Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
validateKubernetesResources(singleOperatorName) {
// 1) Delete/Create Namespace. NOTE: for some reason, we need to do this using the Kubectl Command Line;
// as I was not able to wait on the deleted namespace using the Kubernetes JS client.
execSync("kubectl delete namespace metacontroller-dev || echo 'Namespace does not exist'", { stdio: 'inherit' });
execSync("kubectl create namespace metacontroller-dev", { stdio: 'inherit' });
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi_apiExtensions = kc.makeApiClient(k8s.Apiextensions_v1beta1Api);
const k8sApi_customObjects = kc.makeApiClient(k8s.Custom_objectsApi);
const d = new k8s.V1DeleteOptions();
d.propagationPolicy = 'Foreground';
d.gracePeriodSeconds = 0;
let nextPromise = Promise.resolve();
args.operators.forEach(operatorDefinition => {
if (singleOperatorName !== true && operatorDefinition.key !== singleOperatorName) {
console.log(`\n\nOPERATOR ${operatorDefinition.key}\n - skipping`);
return;
}
const crd = YAML.parse(loadCustomResourceDefinition(operatorDefinition));
crd.metadata.name += ".dev";
crd.spec.group += ".dev";
nextPromise = nextPromise
.then(() => console.log(`\n\nOPERATOR ${operatorDefinition.key}`))
async fetch() {
const apiClient = kubeConfig.makeApiClient(k8s.Custom_objectsApi);
const { body } = await apiClient.listClusterCustomObject(
'ui.kyma-project.io',
'v1alpha1',
'backendmodules',
);
const items = body.items.map(item => item.metadata.name);
this.modules = items;
this.fetched = true;
}
constructor(private kubeConfig: k8s.KubeConfig) {
console.info('Initializing Kubernetes configuration');
this.kubeConfig.loadFromDefault();
const context =
this.kubeConfig.getContextObject(this.kubeConfig.getCurrentContext());
if (context && context.namespace) {
this.namespace = context.namespace;
}
this.coreAPI = this.kubeConfig.makeApiClient(k8s.Core_v1Api);
this.customObjectsAPI =
this.kubeConfig.makeApiClient(k8s.Custom_objectsApi);
}