From 2e3e59e918986a24ef0cdfd55c0839139585210c Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 5 Jul 2023 16:06:38 +0200 Subject: [PATCH] chore: Adapt --skip-devworkspace-operator flag for server:update command (#2723) Signed-off-by: Anatolii Bazko --- src/commands/server/update.ts | 4 ++-- src/context.ts | 22 ++++++++++++++++++- .../devworkspace-olm-installer.ts | 11 +--------- .../eclipse-che/eclipse-che-olm-installer.ts | 18 ++++++++++----- yarn.lock | 4 ++-- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/commands/server/update.ts b/src/commands/server/update.ts index c4b73e079..7e0341e37 100644 --- a/src/commands/server/update.ts +++ b/src/commands/server/update.ts @@ -192,7 +192,7 @@ export default class Update extends Command { cli.info(`Current channel : ${subscription.spec.channel}`) cli.info(`Current catalog source : ${subscription.spec.source}`) cli.info(`Current catalog source namespace: ${subscription.spec.sourceNamespace}`) - if (catalogSource && !Che.isRedHatCatalogSources(catalogSource.metadata.name)) { + if (!Che.isRedHatCatalogSources(catalogSource?.metadata.name) && catalogSource?.spec.image) { cli.info(`Current catalog source image : ${catalogSource.spec.image}`) } cli.info(`Current package name : ${subscription.spec.name}`) @@ -208,7 +208,7 @@ export default class Update extends Command { cli.info(`New channel : ${ctx[EclipseCheContext.CHANNEL]}`) cli.info(`New catalog source : ${ctx[EclipseCheContext.CATALOG_SOURCE_NAME]}`) cli.info(`New catalog source namespace : ${ctx[EclipseCheContext.CATALOG_SOURCE_NAMESPACE]}`) - if (!Che.isRedHatCatalogSources(ctx[EclipseCheContext.CATALOG_SOURCE_NAME])) { + if (!Che.isRedHatCatalogSources(ctx[EclipseCheContext.CATALOG_SOURCE_NAME]) && ctx[EclipseCheContext.CATALOG_SOURCE_IMAGE]) { cli.info(`New catalog source image : ${ctx[EclipseCheContext.CATALOG_SOURCE_IMAGE]}`) } cli.info(`New package name : ${ctx[EclipseCheContext.PACKAGE_NAME]}`) diff --git a/src/context.ts b/src/context.ts index d689967d5..62cf28a1f 100644 --- a/src/context.ts +++ b/src/context.ts @@ -50,6 +50,7 @@ import {EclipseChe} from './tasks/installers/eclipse-che/eclipse-che' import * as fs from 'fs-extra' import * as execa from 'execa' import {CheCluster} from './api/types/che-cluster' +import {CatalogSource} from './api/types/olm' export namespace InfrastructureContext { export const IS_OPENSHIFT = 'infrastructure-is-openshift' @@ -224,7 +225,10 @@ export namespace CheCtlContext { ctx[EclipseCheContext.CATALOG_SOURCE_IMAGE] = `quay.io/devspaces/iib:${iibImageTag}-v${ctx[InfrastructureContext.OPENSHIFT_VERSION]}-${ctx[InfrastructureContext.OPENSHIFT_ARCH]}` } - } // RedHat catalog source is used for the stable channel + } else { + const catalogSource = await getCatalogSource(ctx[EclipseCheContext.CATALOG_SOURCE_NAME], ctx[EclipseCheContext.CATALOG_SOURCE_NAMESPACE]) + ctx[EclipseCheContext.CATALOG_SOURCE_IMAGE] = catalogSource?.spec.image + } } if (flags[CATALOG_SOURCE_YAML_FLAG]) { @@ -319,6 +323,22 @@ export namespace CheCtlContext { } } + async function getCatalogSource(name: string, namespace: string): Promise { + const kubeConfig = new KubeConfig() + kubeConfig.loadFromDefault() + + const customObjectsApi = kubeConfig.makeApiClient(CustomObjectsApi) + try { + const response = await customObjectsApi.getNamespacedCustomObject('operators.coreos.com', 'v1alpha1', namespace, 'catalogsources', name) + return response.body as CatalogSource + } catch (e: any) { + if (e.response && e.response.statusCode === 404) { + return + } + throw e + } + } + async function findCheClusterNamespace(): Promise { const kubeConfig = new KubeConfig() kubeConfig.loadFromDefault() diff --git a/src/tasks/installers/dev-workspace/devworkspace-olm-installer.ts b/src/tasks/installers/dev-workspace/devworkspace-olm-installer.ts index 46855b6fb..df5682faa 100644 --- a/src/tasks/installers/dev-workspace/devworkspace-olm-installer.ts +++ b/src/tasks/installers/dev-workspace/devworkspace-olm-installer.ts @@ -10,28 +10,19 @@ * Red Hat, Inc. - initial API and implementation */ -import {CheCtlContext, DevWorkspaceContext, EclipseCheContext, InfrastructureContext} from '../../../context' +import {DevWorkspaceContext, EclipseCheContext, InfrastructureContext} from '../../../context' import Listr = require('listr') import {Installer} from '../installer' import {DevWorkspacesTasks} from './dev-workspace-tasks' import {DevWorkspace} from './dev-workspace' import {OlmTasks} from '../../olm-tasks' -import {SKIP_DEV_WORKSPACE_FLAG} from '../../../flags' import {CommonTasks} from '../../common-tasks' import {isCheFlavor, newListr} from '../../../utils/utls' export class DevWorkspaceOlmInstaller implements Installer { - protected skip: boolean - - constructor() { - const flags = CheCtlContext.getFlags() - this.skip = flags[SKIP_DEV_WORKSPACE_FLAG] - } - getDeployTasks(): Listr.ListrTask { return { title: `Install ${DevWorkspace.PRODUCT_NAME} operator`, - skip: () => this.skip, task: async (ctx: any, _task: any) => { const tasks = newListr() diff --git a/src/tasks/installers/eclipse-che/eclipse-che-olm-installer.ts b/src/tasks/installers/eclipse-che/eclipse-che-olm-installer.ts index e46cdc25a..942e70d27 100644 --- a/src/tasks/installers/eclipse-che/eclipse-che-olm-installer.ts +++ b/src/tasks/installers/eclipse-che/eclipse-che-olm-installer.ts @@ -19,7 +19,7 @@ import {EclipseCheTasks} from './eclipse-che-tasks' import {EclipseChe} from './eclipse-che' import {CheClusterTasks} from '../../che-cluster-tasks' import {OlmTasks} from '../../olm-tasks' -import {DELETE_ALL_FLAG, STARTING_CSV_FLAG} from '../../../flags' +import {DELETE_ALL_FLAG, SKIP_DEV_WORKSPACE_FLAG, STARTING_CSV_FLAG} from '../../../flags' import {isCheFlavor, newListr} from '../../../utils/utls' import {DevWorkspaceInstallerFactory} from '../dev-workspace/dev-workspace-installer-factory' import {CommonTasks} from '../../common-tasks' @@ -52,12 +52,16 @@ export class EclipseCheOlmInstaller implements Installer { title: `Update ${EclipseChe.PRODUCT_NAME} operator`, task: async (ctx: any, _task: any) => { const tasks = newListr() + const flags = CheCtlContext.getFlags() if (ctx[EclipseCheContext.CREATE_CATALOG_SOURCE_AND_SUBSCRIPTION]) { - tasks.add(await OlmTasks.getDeleteSubscriptionAndCatalogSourceTask( - DevWorkspace.PACKAGE, - DevWorkspace.CSV_PREFIX, - ctx[EclipseCheContext.OPERATOR_NAMESPACE])) + if (!flags[SKIP_DEV_WORKSPACE_FLAG]) { + tasks.add(await OlmTasks.getDeleteSubscriptionAndCatalogSourceTask( + DevWorkspace.PACKAGE, + DevWorkspace.CSV_PREFIX, + ctx[EclipseCheContext.OPERATOR_NAMESPACE])) + } + tasks.add(await OlmTasks.getDeleteSubscriptionAndCatalogSourceTask( EclipseChe.PACKAGE, EclipseChe.CSV_PREFIX, @@ -114,7 +118,9 @@ export class EclipseCheOlmInstaller implements Installer { ctx[EclipseCheContext.CATALOG_SOURCE_IMAGE])) } - tasks.add(DevWorkspaceInstallerFactory.getInstaller().getDeployTasks()) + if (!flags[SKIP_DEV_WORKSPACE_FLAG]) { + tasks.add(DevWorkspaceInstallerFactory.getInstaller().getDeployTasks()) + } tasks.add(OlmTasks.getCreateSubscriptionTask( EclipseChe.SUBSCRIPTION, diff --git a/yarn.lock b/yarn.lock index 518038c71..066dbf71f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2463,7 +2463,7 @@ detect-newline@^3.0.0: "devworkspace-operator@https://github.com/devfile/devworkspace-operator#main": version "0.0.0" - resolved "https://github.com/devfile/devworkspace-operator#8d54b6304319cc3382d1c0a52d7571b03584c844" + resolved "https://github.com/devfile/devworkspace-operator#860cadb1443ad7baca22f8212e80d19335983d32" diff-sequences@^29.4.2: version "29.4.2" @@ -2506,7 +2506,7 @@ ecc-jsbn@~0.1.1: "eclipse-che-operator@https://github.com/eclipse-che/che-operator#main": version "0.0.0" - resolved "https://github.com/eclipse-che/che-operator#411821f612b6aeb2796e52d16b201b06b83e096f" + resolved "https://github.com/eclipse-che/che-operator#4db565cb8eb46c910fc6608d2309442c1db7e367" editorconfig@^0.15.0: version "0.15.3"