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: re-deploy Che via OLM installer. #1806

Merged
merged 2 commits into from
Nov 4, 2021
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
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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