Skip to content

Commit

Permalink
chore: Adapt chectl to 22932
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha committed May 23, 2024
1 parent 5459950 commit 206bc7d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 45 deletions.
61 changes: 23 additions & 38 deletions src/tasks/che-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019-2021 Red Hat, Inc.
* Copyright (c) 2019-2024 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -11,7 +11,7 @@
*/

import * as Listr from 'listr'
import { KubeClient } from '../api/kube-client'
import {KubeClient} from '../api/kube-client'
import {PodTasks} from './pod-tasks'
import {CheCtlContext, CliContext, EclipseCheContext} from '../context'
import {CHE_NAMESPACE_FLAG, DEBUG_FLAG, DEBUG_PORT_FLAG} from '../flags'
Expand All @@ -21,7 +21,7 @@ import * as os from 'node:os'
import * as fs from 'fs-extra'
import {Che} from '../utils/che'
import {newListr, sleep} from '../utils/utls'
import { ux } from '@oclif/core'
import {ux} from '@oclif/core'

export namespace CheTasks {
export function getWaitCheDeployedTasks(): Listr.ListrTask<any> {
Expand All @@ -35,11 +35,11 @@ export namespace CheTasks {

const cheCluster = await kubeHelper.getCheCluster(flags[CHE_NAMESPACE_FLAG])
if (cheCluster) {
if (!cheCluster.spec?.components?.devfileRegistry?.disableInternalRegistry) {
if (await Che.isDevfileRegistryDeploymentConfigured()) {
tasks.add(PodTasks.getPodStartTasks(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}

if (!cheCluster.spec?.components?.pluginRegistry?.disableInternalRegistry) {
if (await Che.isPluginRegistryDeploymentConfigured()) {
tasks.add(PodTasks.getPodStartTasks(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}

Expand All @@ -59,21 +59,13 @@ export namespace CheTasks {
title: 'Wait all pods deleted',
task: async (_ctx: any, _task: any) => {
const flags = CheCtlContext.getFlags()
const kubeHelper = KubeClient.getInstance()
const cheCluster = await kubeHelper.getCheCluster(flags[CHE_NAMESPACE_FLAG])

const tasks = newListr()
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.GATEWAY, EclipseChe.GATEWAY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.DASHBOARD, EclipseChe.DASHBOARD_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.CHE_SERVER, EclipseChe.CHE_SERVER_SELECTOR, flags[CHE_NAMESPACE_FLAG]))

if (!cheCluster?.spec?.components?.devfileRegistry?.disableInternalRegistry) {
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}

if (!cheCluster?.spec?.components?.pluginRegistry?.disableInternalRegistry) {
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))

return tasks
},
Expand All @@ -85,18 +77,15 @@ export namespace CheTasks {
title: `Scale ${EclipseChe.PRODUCT_NAME} down`,
task: async (_ctx: any, _task: any) => {
const flags = CheCtlContext.getFlags()
const kubeHelper = KubeClient.getInstance()
const cheCluster = await kubeHelper.getCheCluster(flags[CHE_NAMESPACE_FLAG])

const tasks = newListr()
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.GATEWAY, EclipseChe.GATEWAY_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.DASHBOARD, EclipseChe.DASHBOARD_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.CHE_SERVER, EclipseChe.CHE_SERVER_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
if (!cheCluster?.spec?.components?.pluginRegistry?.disableInternalRegistry) {
if (await Che.isPluginRegistryDeploymentConfigured()) {
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
}

if (!cheCluster?.spec?.components?.devfileRegistry?.disableInternalRegistry) {
if (await Che.isDevfileRegistryDeploymentConfigured()) {

Check failure on line 88 in src/tasks/che-tasks.ts

View workflow job for this annotation

GitHub Actions / release-test

Expected blank line before this statement

Check failure on line 88 in src/tasks/che-tasks.ts

View workflow job for this annotation

GitHub Actions / unit-tests

Expected blank line before this statement
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
}

Expand All @@ -110,30 +99,26 @@ export namespace CheTasks {
title: `Scale ${EclipseChe.PRODUCT_NAME} up`,
task: async (_ctx: any, _task: any) => {
const flags = CheCtlContext.getFlags()
const kubeHelper = KubeClient.getInstance()
const cheCluster = await kubeHelper.getCheCluster(flags[CHE_NAMESPACE_FLAG])

const tasks = newListr()
if (cheCluster) {
if (!cheCluster.spec?.components?.devfileRegistry?.disableInternalRegistry) {
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}
if (await Che.isDevfileRegistryDeploymentConfigured()) {
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}

if (!cheCluster.spec?.components?.pluginRegistry?.disableInternalRegistry) {
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}
if (await Che.isPluginRegistryDeploymentConfigured()) {
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}

tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.DASHBOARD, EclipseChe.DASHBOARD_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.DASHBOARD, EclipseChe.DASHBOARD_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.DASHBOARD, EclipseChe.DASHBOARD_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.DASHBOARD, EclipseChe.DASHBOARD_SELECTOR, flags[CHE_NAMESPACE_FLAG]))

tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.GATEWAY, EclipseChe.GATEWAY_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.GATEWAY, EclipseChe.GATEWAY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.GATEWAY, EclipseChe.GATEWAY_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.GATEWAY, EclipseChe.GATEWAY_SELECTOR, flags[CHE_NAMESPACE_FLAG]))

tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.CHE_SERVER, EclipseChe.CHE_SERVER_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.CHE_SERVER, EclipseChe.CHE_SERVER_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
}
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.CHE_SERVER, EclipseChe.CHE_SERVER_DEPLOYMENT_NAME, 1, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodStartTasks(EclipseChe.CHE_SERVER, EclipseChe.CHE_SERVER_SELECTOR, flags[CHE_NAMESPACE_FLAG]))

return tasks
},
Expand Down
5 changes: 2 additions & 3 deletions src/tasks/pod-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019-2021 Red Hat, Inc.
* Copyright (c) 2019-2024 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -16,7 +16,6 @@ import {KubeClient} from '../api/kube-client'
import {KubeHelperContext} from '../context'
import {EclipseChe} from './installers/eclipse-che/eclipse-che'
import {newListr} from '../utils/utls'
import {Che} from '../utils/che'

export namespace PodTasks {
interface FailState {
Expand Down Expand Up @@ -83,7 +82,7 @@ export namespace PodTasks {
const tasks = newListr([])
tasks.add(getSchedulingTask(selector, namespace))
tasks.add(getDownloadingTask(selector, namespace))
if (name === EclipseChe.PLUGIN_REGISTRY && await Che.isEmbeddedOpenVSXRegistryConfigured(namespace)) {
if (name === EclipseChe.PLUGIN_REGISTRY) {
// if embedded plugin registry is configured, use longer timeout for pod readiness
tasks.add(getStartingTask(selector, namespace, ctx[KubeHelperContext.POD_READY_TIMEOUT_EMBEDDED_PLUGIN_REGISTRY]))
} else {
Expand Down
29 changes: 25 additions & 4 deletions src/utils/che.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019-2022 Red Hat, Inc.
* Copyright (c) 2019-2024 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -135,10 +135,31 @@ export namespace Che {
throw new Error(`Route ${EclipseChe.CHE_FLAVOR} not found`)
}

export async function isEmbeddedOpenVSXRegistryConfigured(namespace: string): Promise<boolean> {
export async function isDevfileRegistryDeploymentConfigured(): Promise<boolean> {
const kubeClient = KubeClient.getInstance()
const cheCluster = await kubeClient.getCheCluster(namespace)
const ctx = CheCtlContext.get()

const cheCluster = await kubeClient.getCheCluster(ctx[EclipseCheContext.NAMESPACE])

return !cheCluster?.spec?.components?.devfileRegistry?.disableInternalRegistry
}

export async function isPluginRegistryDeploymentConfigured(): Promise<boolean> {
const kubeClient = KubeClient.getInstance()
const ctx = CheCtlContext.get()

const cheCluster = await kubeClient.getCheCluster(ctx[EclipseCheContext.NAMESPACE])

if (cheCluster?.spec?.components?.pluginRegistry?.disableInternalRegistry) {
return false
}

const isOpenVSXURLConfiguredInCheCluster = cheCluster?.spec?.components?.pluginRegistry?.openVSXURL
if (isOpenVSXURLConfiguredInCheCluster) {
return false
}

return !cheCluster?.spec?.components?.pluginRegistry?.openVSXURL
const operatorDeployment = await kubeClient.getDeployment(EclipseChe.OPERATOR_DEPLOYMENT_NAME, ctx[EclipseCheContext.OPERATOR_NAMESPACE])
return !operatorDeployment?.spec?.template.spec?.containers[0].env?.find(env => env.name === 'CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL')?.value
}
}

0 comments on commit 206bc7d

Please sign in to comment.