From 3ef37a02995b28a7e71c585580c9d7437308083e Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Mon, 8 Nov 2021 10:40:36 +0200 Subject: [PATCH] fix: re-deploy Che via OLM installer. (#1806) (#1812) * fix: Fix re-deploy Che via OLM installer. Signed-off-by: Oleksandr Andriienko --- src/constants.ts | 1 - .../devfile-workspace-operator-installer.ts | 39 +++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 23680f026..67388f45b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -44,7 +44,6 @@ export const LEGACY_CHE_NAMESPACE = 'che' // OLM common export const DEFAULT_CHE_OLM_PACKAGE_NAME = 'eclipse-che' export const DEFAULT_CHE_OPERATOR_SUBSCRIPTION_NAME = 'eclipse-che-subscription' -export const DEVWORKSPACE_OPERATOR_SUBSRIPTION_NAME = 'devworkspace-operator-fast-redhat-operators-openshift-marketplace' export const OPERATOR_GROUP_NAME = 'che-operator-group' export const CVS_PREFIX = 'eclipse-che' export const DEVWORKSPACE_CVS_PREFIX = 'devworkspace-operator' diff --git a/src/tasks/component-installers/devfile-workspace-operator-installer.ts b/src/tasks/component-installers/devfile-workspace-operator-installer.ts index cf48b4a0c..1784ed817 100644 --- a/src/tasks/component-installers/devfile-workspace-operator-installer.ts +++ b/src/tasks/component-installers/devfile-workspace-operator-installer.ts @@ -15,7 +15,7 @@ import * as Listr from 'listr' import { CheHelper } from '../../api/che' import { KubeHelper } from '../../api/kube' import { OpenShiftHelper } from '../../api/openshift' -import { DEFAULT_DEV_WORKSPACE_CONTROLLER_NAMESPACE } from '../../constants' +import { DEFAULT_DEV_WORKSPACE_CONTROLLER_NAMESPACE, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME, DEVWORKSPACE_CVS_PREFIX } from '../../constants' import { CertManagerTasks } from '../component-installers/cert-manager' /** @@ -104,11 +104,29 @@ export class DevWorkspaceTasks { ] } + async isDevWorkspaceInstalledViaOLM(): Promise { + const IsPreInstalledOLM = await this.kubeHelper.isPreInstalledOLM() + if (!IsPreInstalledOLM) { + return false + } + const csvAll = await this.kubeHelper.getClusterServiceVersions(DEFAULT_OPENSHIFT_OPERATORS_NS_NAME) + const devWorkspaceCSVs = csvAll.items.filter(csv => csv.metadata.name!.startsWith(DEVWORKSPACE_CVS_PREFIX)) + return devWorkspaceCSVs.length > 0 + } + /** * Returns list of tasks which uninstall dev-workspace. */ getUninstallTasks(): ReadonlyArray { return [ + { + title: 'Check DevWorkspace OLM installation', + task: async (ctx: any, task: any) => { + ctx.isDevWorkspaceInstalledViaOLM = Boolean(await this.isDevWorkspaceInstalledViaOLM()) + + task.title = await `${task.title} ...${ctx.isDevWorkspaceInstalledViaOLM ? 'Installed' : 'Not installed'}` + }, + }, { title: 'Delete all DevWorkspace Controller deployments', task: async (_ctx: any, task: any) => { @@ -149,10 +167,12 @@ export class DevWorkspaceTasks { }, { title: 'Delete DevWorkspace Controller ClusterRoleBindings', - task: async (_ctx: any, task: any) => { + task: async (ctx: any, task: any) => { await this.kubeHelper.deleteClusterRoleBinding(this.devWorkspaceRoleBinding) await this.kubeHelper.deleteClusterRoleBinding(this.devworkspaceProxyClusterRoleBinding) - await this.kubeHelper.deleteClusterRoleBinding(this.devWorkspaceWebhookServerClusterRolebinding) + if (!ctx.isDevWorkspaceInstalledViaOLM) { + await this.kubeHelper.deleteClusterRoleBinding(this.devWorkspaceWebhookServerClusterRolebinding) + } task.title = await `${task.title}...OK` }, @@ -175,12 +195,15 @@ export class DevWorkspaceTasks { }, { title: 'Delete DevWorkspace Controller cluster roles', - task: async (_ctx: any, task: any) => { - await this.kubeHelper.deleteClusterRole(this.devWorkspaceEditWorkspaceClusterRole) - await this.kubeHelper.deleteClusterRole(this.devWorkspaceViewWorkspaceClusterRole) + task: async (ctx: any, task: any) => { + if (!ctx.isDevWorkspaceInstalledViaOLM) { + await this.kubeHelper.deleteClusterRole(this.devWorkspaceEditWorkspaceClusterRole) + await this.kubeHelper.deleteClusterRole(this.devWorkspaceViewWorkspaceClusterRole) + await this.kubeHelper.deleteClusterRole(this.devWorkspaceClusterRoleWebhook) + } + await this.kubeHelper.deleteClusterRole(this.devworkspaceProxyClusterRole) await this.kubeHelper.deleteClusterRole(this.devworkspaceClusterRole) - await this.kubeHelper.deleteClusterRole(this.devWorkspaceClusterRoleWebhook) task.title = await `${task.title}...OK` }, @@ -205,6 +228,7 @@ export class DevWorkspaceTasks { }, { title: 'Delete DevWorkspace Controller webhooks configurations', + enabled: ctx => !ctx.isDevWorkspaceInstalledViaOLM, task: async (_ctx: any, task: any) => { await this.kubeHelper.deleteMutatingWebhookConfiguration(this.webhooksName) await this.kubeHelper.deleteValidatingWebhookConfiguration(this.webhooksName) @@ -214,6 +238,7 @@ export class DevWorkspaceTasks { }, { title: 'Delete DevWorkspace Controller CRDs', + enabled: ctx => !ctx.isDevWorkspaceInstalledViaOLM, task: async (_ctx: any, task: any) => { await this.kubeHelper.deleteCrd(this.devWorkspacesCrdName) await this.kubeHelper.deleteCrd(this.devWorkspaceTemplatesCrdName)