From b25b0ea6d8d45167c74a90b98bf297db7a0ca909 Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Thu, 23 Sep 2021 16:13:56 +0300 Subject: [PATCH] Changes after rebasing conflicting files Signed-off-by: Mykola Morhun --- src/api/che.ts | 4 ++-- src/commands/server/restore.ts | 31 +++++++++++-------------------- src/commands/server/update.ts | 2 +- src/tasks/installers/olm.ts | 8 ++++---- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/api/che.ts b/src/api/che.ts index c03b9868b..0e1be775e 100644 --- a/src/api/che.ts +++ b/src/api/che.ts @@ -551,7 +551,7 @@ export class CheHelper { } } - async findCheSubscription(namespace: string): Promise { + async findCheOperatorSubscription(namespace: string): Promise { try { const subscriptions = await this.kube.listOperatorSubscriptions(namespace) const cheSubscriptions = subscriptions.filter(subscription => subscription.spec.name && subscription.spec.name.includes(DEFAULT_CHE_OLM_PACKAGE_NAME)) @@ -563,7 +563,7 @@ export class CheHelper { } // No subscriptions found, check if Che is installed in all namespaces mode if (namespace !== DEFAULT_OPENSHIFT_OPERATORS_NS_NAME) { - return this.findCheSubscription(DEFAULT_OPENSHIFT_OPERATORS_NS_NAME) + return this.findCheOperatorSubscription(DEFAULT_OPENSHIFT_OPERATORS_NS_NAME) } } catch { // Do nothing, just return undefined diff --git a/src/commands/server/restore.ts b/src/commands/server/restore.ts index 4e0bff2a4..4fdca056e 100644 --- a/src/commands/server/restore.ts +++ b/src/commands/server/restore.ts @@ -14,9 +14,10 @@ import { Command, flags } from '@oclif/command' import { boolean, string } from '@oclif/parser/lib/flags' import * as Listr from 'listr' -import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL, CHE_CLUSTER_RESTORE_KIND_PLURAL, DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME, OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME, OLM_STABLE_CHANNEL_NAME, OPERATOR_DEPLOYMENT_NAME, SUBSCRIPTION_NAME } from '../../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL, CHE_CLUSTER_RESTORE_KIND_PLURAL, DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME, OLM_STABLE_CHANNEL_NAME, OPERATOR_DEPLOYMENT_NAME } from '../../constants' import { ChectlContext } from '../../api/context' import { KubeHelper } from '../../api/kube' +import { CheHelper } from '../../api/che' import { cheNamespace } from '../../common-flags' import { requestRestore } from '../../api/backup-restore' import { cli } from 'cli-ux' @@ -113,6 +114,7 @@ export default class Restore extends Command { private getRestoreTasks(flags: any): Listr.ListrTask[] { const kube = new KubeHelper(flags) + const che = new CheHelper(flags) return [ { title: 'Detecting existing operator version...', @@ -147,30 +149,19 @@ export default class Restore extends Command { if (!ctx.isOperatorDeployed) { setDefaultInstaller(flags) if (flags.installer === 'olm') { - if (await kube.operatorSubscriptionExists(SUBSCRIPTION_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME)) { - flags['olm-channel'] = OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME - } else { - flags['olm-channel'] = OLM_STABLE_CHANNEL_NAME - } + flags['olm-channel'] = OLM_STABLE_CHANNEL_NAME + task.title = `${task.title}OLM` + } else { + task.title = `${task.title}Operator` } - task.title = `${task.title}${flags.installer}` return } - if (await kube.operatorSubscriptionExists(SUBSCRIPTION_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME)) { - // OLM in all namespaces mode - const operatorSubscriptionYaml = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME) + const subscription = await che.findCheOperatorSubscription(flags.chenamespace) + if (subscription) { + // OLM flags.installer = 'olm' - flags['olm-channel'] = operatorSubscriptionYaml.spec.channel - task.title = `${task.title}OLM` - return - } - - if (await kube.operatorSubscriptionExists(SUBSCRIPTION_NAME, flags.chenamespace)) { - // OLM in single namespace mode - const operatorSubscriptionYaml = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, flags.chenamespace) - flags.installer = 'olm' - flags['olm-channel'] = operatorSubscriptionYaml.spec.channel + flags['olm-channel'] = subscription.spec.channel task.title = `${task.title}OLM` return } diff --git a/src/commands/server/update.ts b/src/commands/server/update.ts index 50710d5c6..83fdf85ff 100644 --- a/src/commands/server/update.ts +++ b/src/commands/server/update.ts @@ -363,7 +363,7 @@ export default class Update extends Command { */ private async setDefaultInstaller(flags: any): Promise { const cheHelper = new CheHelper(flags) - if (await cheHelper.findCheSubscription(flags.chenamespace)) { + if (await cheHelper.findCheOperatorSubscription(flags.chenamespace)) { flags.installer = 'olm' } else { flags.installer = 'operator' diff --git a/src/tasks/installers/olm.ts b/src/tasks/installers/olm.ts index f5af73070..0047ee4a9 100644 --- a/src/tasks/installers/olm.ts +++ b/src/tasks/installers/olm.ts @@ -152,7 +152,7 @@ export class OLMTasks { { title: 'Create operator subscription', task: async (ctx: any, task: any) => { - let subscription = await che.findCheSubscription(ctx.operatorNamespace) + let subscription = await che.findCheOperatorSubscription(ctx.operatorNamespace) if (subscription) { ctx.subscriptionName = subscription.metadata.name task.title = `${task.title}...It already exists.` @@ -252,7 +252,7 @@ export class OLMTasks { { title: 'Check if operator subscription exists', task: async (ctx: any, task: any) => { - if (!await che.findCheSubscription(ctx.operatorNamespace)) { + if (!await che.findCheOperatorSubscription(ctx.operatorNamespace)) { command.error('Unable to find operator subscription') } task.title = `${task.title}...done.` @@ -269,7 +269,7 @@ export class OLMTasks { title: 'Get operator installation plan', task: async (ctx: any, task: any) => { // We can be sure that the subscription exist, because it was checked in preupdate tasks - const subscription: Subscription = (await che.findCheSubscription(ctx.operatorNamespace))! + const subscription: Subscription = (await che.findCheOperatorSubscription(ctx.operatorNamespace))! if (subscription.status) { if (subscription.status.state === 'AtLatestKnown') { @@ -336,7 +336,7 @@ export class OLMTasks { { title: 'Check if operator is installed', task: async (ctx: any, task: any) => { - const subscription = await che.findCheSubscription(flags.chenamespace || DEFAULT_CHE_NAMESPACE) + const subscription = await che.findCheOperatorSubscription(flags.chenamespace || DEFAULT_CHE_NAMESPACE) if (subscription) { ctx.subscriptionName = subscription.metadata.name ctx.operatorNamespace = subscription.metadata.namespace