Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const k8s = require('@kubernetes/client-node');
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
const yamlString = k8s.dumpYaml({
metadata: {
name: 'test'
}
});
const yamlNamespace = k8s.loadYaml(yamlString);
k8sApi.createNamespace(yamlNamespace).then(
(response) => {
console.log('Created namespace');
console.log(response);
k8sApi.readNamespace(yamlNamespace.metadata.name).then(
(response) => {
console.log(response);
k8sApi.deleteNamespace(
yamlNamespace.metadata.name, {} /* delete options */);
});
},
(err) => {
console.log('Error!: ' + err);
}
);
async function createNamespacedConfigMap(name, namespace, manifest) {
const k8sApi = getCoreV1Api();
try {
logger.info(`Creating configMap with name ${name} in namespace ${namespace} with manifest:`);
logger.debug(manifest);
const configMap = loadYaml(manifest);
return k8sApi.createNamespacedConfigMap(namespace, configMap);
} catch (error) {
logger.error(`Error creating configMap with name ${name} in namespace ${namespace}`, error.response.body);
throw error;
}
}
function getConfigMap() {
return loadYaml(getManifest());
}