Last active
February 1, 2019 12:08
-
-
Save kooba/c0a2fef8bcdef6ec40cf3dba579ec135 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 k8sClient = kubernetes.Config.defaultClient(); | |
const createNamespace = async (namespaceName) => { | |
const existingNamespace = await k8sClient.listNamespace( | |
true, '', `metadata.name=${namespaceName}`, | |
); | |
if (existingNamespace.body.items.length) { | |
console.log(`Namespace "${namespaceName}" already exists`); | |
return; | |
} | |
const namespace = new kubernetes.V1Namespace(); | |
namespace.metadata = new kubernetes.V1ObjectMeta(); | |
namespace.metadata.name = namespaceName; | |
await k8sClient.createNamespace(namespace); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment