Skip to content

Commit

Permalink
fix: re-deploy Che via OLM installer. (#1806) (#1812)
Browse files Browse the repository at this point in the history
* fix: Fix re-deploy Che via OLM installer.

Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr committed Nov 8, 2021
1 parent 0a65484 commit 3ef37a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -104,11 +104,29 @@ export class DevWorkspaceTasks {
]
}

async isDevWorkspaceInstalledViaOLM(): Promise<boolean> {
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<Listr.ListrTask> {
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) => {
Expand Down Expand Up @@ -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`
},
Expand All @@ -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`
},
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 3ef37a0

Please sign in to comment.