Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't remove CRD if another deployments found #828

Merged
merged 4 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,11 +1193,10 @@ export class KubeHelper {
}
}

async deleteCrd(name = '') {
async deleteCrd(name: string): Promise<void> {
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)
}
Expand Down Expand Up @@ -1309,6 +1308,19 @@ export class KubeHelper {
}
}

/**
* Returns all `checlusters.org.eclipse.che' resources
*/
async getAllCheCluster(): Promise<any[]> {
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.
*/
Expand Down
24 changes: 19 additions & 5 deletions src/tasks/installers/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.`
Expand Down Expand Up @@ -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) => {
Expand All @@ -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`
Expand All @@ -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`
Expand Down