Skip to content

Commit

Permalink
chore: Adapt --skip-devworkspace-operator flag for server:update comm…
Browse files Browse the repository at this point in the history
…and (#2723)

Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Jul 5, 2023
1 parent 02e6569 commit 2e3e59e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand All @@ -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]}`)
Expand Down
22 changes: 21 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -319,6 +323,22 @@ export namespace CheCtlContext {
}
}

async function getCatalogSource(name: string, namespace: string): Promise<CatalogSource | undefined> {
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<string | undefined> {
const kubeConfig = new KubeConfig()
kubeConfig.loadFromDefault()
Expand Down
11 changes: 1 addition & 10 deletions src/tasks/installers/dev-workspace/devworkspace-olm-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
return {
title: `Install ${DevWorkspace.PRODUCT_NAME} operator`,
skip: () => this.skip,
task: async (ctx: any, _task: any) => {
const tasks = newListr()

Expand Down
18 changes: 12 additions & 6 deletions src/tasks/installers/eclipse-che/eclipse-che-olm-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2e3e59e

Please sign in to comment.