diff --git a/src/api/kube.ts b/src/api/kube.ts index 9796bf835..fef951789 100644 --- a/src/api/kube.ts +++ b/src/api/kube.ts @@ -1193,11 +1193,10 @@ export class KubeHelper { } } - async deleteCrd(name = '') { + async deleteCrd(name: string): Promise { const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1beta1Api) try { - const options = new V1DeleteOptions() - await k8sApiextensionsApi.deleteCustomResourceDefinition(name, undefined, options) + await k8sApiextensionsApi.deleteCustomResourceDefinition(name) } catch (e) { throw this.wrapK8sClientError(e) } @@ -1309,6 +1308,19 @@ export class KubeHelper { } } + /** + * Returns all `checlusters.org.eclipse.che' resources + */ + async getAllCheCluster(): Promise { + const customObjectsApi = KubeHelper.KUBE_CONFIG.makeApiClient(CustomObjectsApi) + try { + const { body } = await customObjectsApi.listClusterCustomObject('org.eclipse.che', 'v1', 'checlusters') + return body.items ? body.items : [] + } catch (e) { + throw this.wrapK8sClientError(e) + } + } + /** * Deletes `checlusters.org.eclipse.che' resources in the given namespace. */ diff --git a/src/tasks/installers/operator.ts b/src/tasks/installers/operator.ts index d3fceb8d7..e38585904 100644 --- a/src/tasks/installers/operator.ts +++ b/src/tasks/installers/operator.ts @@ -228,7 +228,7 @@ export class OperatorTasks { command.error('ERROR: It looks like you don\'t have enough privileges. You need to grant more privileges to current user or use a different user. If you are using minishift you can "oc login -u system:admin"') } task.title = `${task.title}...updated.` - // it is needed to check the legacy cluster object name to be compatible with previous installations + // it is needed to check the legacy cluster object name to be compatible with previous installations } else if (legacyClusterRoleExists) { const statusCode = await kube.replaceClusterRoleFromFile(yamlFilePath, this.operatorClusterRole) if (statusCode === 403) { @@ -266,7 +266,7 @@ export class OperatorTasks { if (clusterRoleBindExists) { await kube.replaceClusterRoleBinding(clusterRoleBindingName, this.operatorServiceAccount, flags.chenamespace, clusterRoleName) task.title = `${task.title}...updated.` - // it is needed to check the legacy cluster object name to be compatible with previous installations + // it is needed to check the legacy cluster object name to be compatible with previous installations } else if (legacyClusterRoleBindExists) { await kube.replaceClusterRoleBinding(this.operatorClusterRoleBinding, this.operatorServiceAccount, flags.chenamespace, this.operatorClusterRole) task.title = `Updating ClusterRoleBinding ${this.operatorClusterRoleBinding}...updated.` @@ -335,10 +335,24 @@ export class OperatorTasks { title: `Delete the Custom Resource of type ${CHE_CLUSTER_CRD}`, task: async (_ctx: any, task: any) => { await kh.deleteCheCluster(flags.chenamespace) - await cli.wait(2000) //wait a couple of secs for the finalizers to be executed + do { + await cli.wait(2000) //wait a couple of secs for the finalizers to be executed + } while (await kh.getCheCluster(flags.chenamespace)) task.title = await `${task.title}...OK` } }, + { + title: `Delete CRD ${this.cheClusterCrd}`, + task: async (_ctx: any, task: any) => { + const checlusters = await kh.getAllCheCluster() + if (checlusters.length > 0) { + task.title = await `${task.title}...Skipped: another Eclipse Che deployment found.` + } else { + await kh.deleteCrd(this.cheClusterCrd) + task.title = await `${task.title}...OK` + } + } + }, { title: `Delete role binding ${this.operatorRoleBinding}`, task: async (_ctx: any, task: any) => { @@ -365,7 +379,7 @@ export class OperatorTasks { if (clusterRoleBindExists) { await kh.deleteClusterRoleBinding(clusterRoleBindingName) task.title = await `${task.title}...OK` - // it is needed to check the legacy cluster object name to be compatible with previous installations + // it is needed to check the legacy cluster object name to be compatible with previous installations } else if (legacyClusterRoleBindExists) { await kh.deleteClusterRoleBinding(this.operatorClusterRoleBinding) task.title = await `Delete cluster role binding ${this.operatorClusterRoleBinding}...OK` @@ -380,7 +394,7 @@ export class OperatorTasks { if (clusterRoleExists) { await kh.deleteClusterRole(clusterRoleName) task.title = await `${task.title}...OK` - // it is needed to check the legacy cluster object name to be compatible with previous installations + // it is needed to check the legacy cluster object name to be compatible with previous installations } else if (legacyClusterRoleExists) { await kh.deleteClusterRole(this.operatorClusterRole) task.title = await `Delete cluster role ${this.operatorClusterRole}...OK`