Created
February 1, 2019 12:09
-
-
Save kooba/e30276d3ff92b13079f76bd45ef935ae to your computer and use it in GitHub Desktop.
Development in the Cloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const kubernetes = require('@kubernetes/client-node'); | |
const yaml = require('js-yaml'); | |
const k8sClient = kubernetes.Config.defaultClient(); | |
const BRIGADE_NAMESPACE = 'brigade'; | |
const createEnvironmentConfigMap = async (name, projects) => { | |
const configMap = new kubernetes.V1ConfigMap(); | |
const metadata = new kubernetes.V1ObjectMeta(); | |
metadata.name = `environment-config-${name}`; | |
metadata.namespace = BRIGADE_NAMESPACE; | |
metadata.labels = { | |
type: 'preview-environment-config', | |
environmentName: name, | |
}; | |
configMap.metadata = metadata; | |
configMap.data = { | |
environment: yaml.dump(projects), | |
}; | |
try { | |
await k8sClient.createNamespacedConfigMap(BRIGADE_NAMESPACE, configMap); | |
} catch (error) { | |
if (error.body && error.body.code === 409) { | |
await k8sClient.replaceNamespacedConfigMap( | |
configMap.metadata.name, BRIGADE_NAMESPACE, configMap, | |
); | |
} else { | |
throw error; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment