Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't fail on scale down if deployment does not exist #2860

Merged
merged 8 commits into from
Feb 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
Signed-off-by: Anatolii Bazko <[email protected]>
tolusha committed Feb 19, 2024
commit 3e2c2c9cbd75633100b6941256eed38414a05619
14 changes: 11 additions & 3 deletions src/tasks/che-tasks.ts
Original file line number Diff line number Diff line change
@@ -76,13 +76,21 @@ 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]))
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.DEVFILE_REGISTRY, EclipseChe.DEVFILE_REGISTRY_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
if (!cheCluster?.spec?.components?.pluginRegistry?.disableInternalRegistry) {
tasks.add(PodTasks.getScaleDeploymentTask(EclipseChe.PLUGIN_REGISTRY, EclipseChe.PLUGIN_REGISTRY_DEPLOYMENT_NAME, 0, flags[CHE_NAMESPACE_FLAG]))
}

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

return tasks
},
}
@@ -94,9 +102,9 @@ export namespace CheTasks {
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()
const cheCluster = await kubeHelper.getCheCluster(flags[CHE_NAMESPACE_FLAG])
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]))
9 changes: 5 additions & 4 deletions src/tasks/pod-tasks.ts
Original file line number Diff line number Diff line change
@@ -59,12 +59,13 @@ export namespace PodTasks {
return {
title: `Scale ${name} ${replicas > 0 ? 'Up' : 'Down'}`,
task: async (_ctx: any, task: any) => {
if (await kubeHelper.isDeploymentExist(deploymentName, namespace)) {
await kubeHelper.scaleDeployment(deploymentName, namespace, replicas)
task.title = `${task.title}...[OK]`
} else {
if (replicas === 0 && !await kubeHelper.isDeploymentExist(deploymentName, namespace)) {
task.title = `${task.title}...[Not found]`
return
}

await kubeHelper.scaleDeployment(deploymentName, namespace, replicas)
task.title = `${task.title}...[OK]`
},
}
}

Unchanged files with check annotations Beta

import * as getos from 'getos'
import {promisify} from 'node:util'
const Analytics = require('analytics-node')

Check warning on line 26 in src/hooks/analytics/segment-adapter.ts

GitHub Actions / unit-tests

Do not use "require"

Check warning on line 26 in src/hooks/analytics/segment-adapter.ts

GitHub Actions / release-test

Do not use "require"
export interface SegmentConfig {
segmentWriteKey: string
if (await CheCtlVersion.isCheCtlUpdateAvailable(ctx[CliContext.CLI_CACHE_DIR])) {
ux.info(`A more recent version of chectl is available. To deploy the latest version of ${EclipseChe.PRODUCT_NAME}, update the chectl tool first.`)
if (await ux.confirm('Do you want to update chectl now? [y/n]')) {
const bin = path.join(__dirname, '..', '..', 'bin', getProjectName())

Check warning on line 72 in src/utils/command-utils.ts

GitHub Actions / unit-tests

Do not use "__dirname"

Check warning on line 72 in src/utils/command-utils.ts

GitHub Actions / release-test

Do not use "__dirname"
await execa(bin, ['update'], {stdout: 'inherit', stderr: 'inherit', timeout: 60_000})
ux.exit(0)
}
import * as commandExists from 'command-exists'
import execa = require('execa')
const pkjson = require('../../package.json')

Check warning on line 25 in src/utils/utls.ts

GitHub Actions / unit-tests

Do not use "require"

Check warning on line 25 in src/utils/utls.ts

GitHub Actions / release-test

Do not use "require"
export function base64Decode(arg: string): string {
return Buffer.from(arg, 'base64').toString('ascii')
// __dirname is
// project_root/src if dev mode,
// installation_root/lib if run from an installed location
return path.join(__dirname, '..', '..', 'templates')

Check warning on line 69 in src/utils/utls.ts

GitHub Actions / unit-tests

Do not use "__dirname"

Check warning on line 69 in src/utils/utls.ts

GitHub Actions / release-test

Do not use "__dirname"
}
export function addTrailingSlash(url: string): string {