From d6e8cf3816a620ffd0fa691fc70d0736c0606e7f Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Tue, 21 Sep 2021 17:38:56 +0300 Subject: [PATCH] Fixes for all namespaces mode Signed-off-by: Mykola Morhun --- src/commands/server/restore.ts | 5 ++++- src/constants.ts | 5 ++--- src/tasks/installers/olm.ts | 30 +++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/commands/server/restore.ts b/src/commands/server/restore.ts index 3d207da05..edb31da13 100644 --- a/src/commands/server/restore.ts +++ b/src/commands/server/restore.ts @@ -182,10 +182,13 @@ export default class Restore extends Command { const backupCrName = 'backup-before-update-to-' + currentOperatorVersion.replace(/\./g, '-') const kube = new KubeHelper(flags) - const backupCr = await kube.getCustomResource(flags.chenamespace, backupCrName, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL) + const backupCr: V1CheClusterBackup = await kube.getCustomResource(flags.chenamespace, backupCrName, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL) if (!backupCr) { throw new Error(`Cannot find backup: ${backupCrName}`) } + if (!backupCr.status || backupCr.status.state !== 'Succeeded') { + throw new Error(`Backup with name '${backupCrName}' is not successful`) + } flags['backup-cr'] = backupCrName task.title = `${task.title} ${backupCrName} found` }, diff --git a/src/constants.ts b/src/constants.ts index 234af564e..12da62493 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -44,13 +44,12 @@ export const LEGACY_CHE_NAMESPACE = 'che' // OLM export const DEFAULT_CHE_OLM_PACKAGE_NAME = 'eclipse-che' export const OLM_STABLE_CHANNEL_NAME = 'stable' -export const OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME = 'stable-all-namespaces' +export const OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME = 'tech-preview-stable-all-namespaces' export const OLM_NEXT_CHANNEL_NAME = 'next' export const DEFAULT_OPENSHIFT_MARKET_PLACE_NAMESPACE = 'openshift-marketplace' export const DEFAULT_OLM_KUBERNETES_NAMESPACE = 'olm' export const CUSTOM_CATALOG_SOURCE_NAME = 'eclipse-che-custom-catalog-source' -// export const SUBSCRIPTION_NAME = 'eclipse-che-subscription' -export const SUBSCRIPTION_NAME = 'eclipse-che-preview-openshift' +export const SUBSCRIPTION_NAME = 'eclipse-che-subscription' export const OPERATOR_GROUP_NAME = 'che-operator-group' export const KUBERNETES_OLM_CATALOG = 'operatorhubio-catalog' export const OPENSHIFT_OLM_CATALOG = 'community-operators' diff --git a/src/tasks/installers/olm.ts b/src/tasks/installers/olm.ts index 9916c7b66..9cda5465a 100644 --- a/src/tasks/installers/olm.ts +++ b/src/tasks/installers/olm.ts @@ -93,7 +93,13 @@ export class OLMTasks { // Convert version flag to channel (see subscription object), starting CSV and approval starategy flags.version = VersionHelper.removeVPrefix(flags.version, true) // Need to point to specific CSV - ctx.startingCSV = `eclipse-che.v${flags.version}` + if (flags['starting-csv']) { + ctx.startingCSV = flags['starting-csv'] + } else if (flags['olm-channel'] === OLM_STABLE_CHANNEL_NAME) { + ctx.startingCSV = `eclipse-che.v${flags.version}` + } else if (flags['olm-channel'] === OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME) { + ctx.startingCSV = `eclipse-che-preview-openshift.v${flags.version}-all-namespaces` + } // else use latest in the channel // Set approval starategy to manual to prevent autoupdate to the latest version right before installation ctx.approvalStarategy = 'Manual' } else { @@ -152,11 +158,11 @@ export class OLMTasks { // custom Che CatalogSource const catalogSourceNamespace = flags['catalog-source-namespace'] || ctx.operatorNamespace subscription = this.constructSubscription(SUBSCRIPTION_NAME, flags['package-manifest-name'], ctx.operatorNamespace, catalogSourceNamespace, flags['olm-channel'], ctx.sourceName, ctx.approvalStarategy, ctx.startingCSV) - } else if (VersionHelper.isDeployingStableVersion(flags) || flags['olm-channel'] === OLM_STABLE_CHANNEL_NAME) { + } else if (flags['olm-channel'] === OLM_STABLE_CHANNEL_NAME || (VersionHelper.isDeployingStableVersion(flags) && !flags['olm-channel'])) { // stable Che CatalogSource subscription = this.constructSubscription(SUBSCRIPTION_NAME, DEFAULT_CHE_OLM_PACKAGE_NAME, ctx.operatorNamespace, ctx.defaultCatalogSourceNamespace, OLM_STABLE_CHANNEL_NAME, ctx.catalogSourceNameStable, ctx.approvalStarategy, ctx.startingCSV) } else if (flags['olm-channel'] === OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME) { - // stable Che CatalogSource + // stable all namespaces Che CatalogSource subscription = this.constructSubscription(SUBSCRIPTION_NAME, DEFAULT_CHE_OLM_PACKAGE_NAME, ctx.operatorNamespace, ctx.defaultCatalogSourceNamespace, OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME, ctx.catalogSourceNameStable, ctx.approvalStarategy, ctx.startingCSV) } else { // next Che CatalogSource @@ -338,19 +344,33 @@ export class OLMTasks { task.title = `${task.title}...OK` }, }, + { + title: `Delete(OLM) Eclipse Che cluster service versions for all namespaces mode`, + enabled: ctx => ctx.isPreInstalledOLM && flags.chenamespace !== ctx.operatorNamespace, + task: async (ctx: any, task: any) => { + const csvs = await kube.getClusterServiceVersions(ctx.operatorNamespace) + const csvsToDelete = csvs.items.filter(csv => csv.metadata.name!.startsWith(CVS_PREFIX)) + for (const csv of csvsToDelete) { + await kube.deleteClusterServiceVersion(ctx.operatorNamespace, csv.metadata.name!) + } + task.title = `${task.title}...OK` + }, + }, { title: 'Delete(OLM) Eclipse Che cluster service versions', enabled: ctx => ctx.isPreInstalledOLM, task: async (_ctx: any, task: any) => { const csvs = await kube.getClusterServiceVersions(flags.chenamespace) const csvsToDelete = csvs.items.filter(csv => csv.metadata.name!.startsWith(CVS_PREFIX)) - csvsToDelete.forEach(csv => kube.deleteClusterServiceVersion(flags.chenamespace, csv.metadata.name!)) + for (const csv of csvsToDelete) { + await kube.deleteClusterServiceVersion(flags.chenamespace, csv.metadata.name!) + } task.title = `${task.title}...OK` }, }, { title: `Delete(OLM) operator group ${OPERATOR_GROUP_NAME}`, - enabled: ctx => ctx.isPreInstalledOLM, + enabled: ctx => ctx.isPreInstalledOLM && ctx.operatorNamespace !== DEFAULT_OPENSHIFT_OPERATORS_NS_NAME, task: async (ctx: any, task: any) => { await kube.deleteOperatorGroup(OPERATOR_GROUP_NAME, ctx.operatorNamespace) task.title = `${task.title}...OK`