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
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .github/workflows/minikube-chectl-commands-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Start minikube cluster
uses: che-incubator/setup-minikube-action@next
with:
minikube-version: v1.23.2
minikube-version: v1.29.0
- name: Install NodeJS
uses: actions/setup-node@v3
with:
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Start minikube cluster
uses: che-incubator/setup-minikube-action@next
with:
minikube-version: v1.23.2
minikube-version: v1.29.0
- name: Install chectl from the stable channel
run: bash <(curl -sL https://www.eclipse.org/che/chectl/) --channel=stable
- name: Install NodeJS
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/minikube-chectl-release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Start minikube cluster
uses: che-incubator/setup-minikube-action@next
with:
minikube-version: v1.23.2
minikube-version: v1.29.0
- name: Install NodeJS
uses: actions/setup-node@v3
with:
Expand Down
31 changes: 24 additions & 7 deletions src/tasks/che-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,22 @@ 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.CHE_SERVER, EclipseChe.CHE_SERVER_SELECTOR, flags[CHE_NAMESPACE_FLAG]))
tasks.add(PodTasks.getPodDeletedTask(EclipseChe.DASHBOARD, EclipseChe.DASHBOARD_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]))
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]))
}

return tasks
},
}
Expand All @@ -76,13 +85,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
},
}
Expand All @@ -94,9 +111,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]))
Expand Down
72 changes: 36 additions & 36 deletions src/tasks/pod-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/

import { ux } from '@oclif/core'
import {ux} from '@oclif/core'
import * as Listr from 'listr'
import {KubeClient} from '../api/kube-client'
import {KubeHelperContext} from '../context'
Expand Down Expand Up @@ -265,8 +265,8 @@ export namespace PodTasks {
}

/**
* Checks if there is any reason for a given pod state and returns message if so.
*/
* Checks if there is any reason for a given pod state and returns message if so.
*/
async function getContainerFailState(namespace: string, selector: string, state: string): Promise<FailState | undefined> {
const kubeHelper = KubeClient.getInstance()
const waitingState = await kubeHelper.getPodWaitingState(namespace, selector, state)
Expand All @@ -278,38 +278,38 @@ export namespace PodTasks {
/**
* Returns extended timeout error message explaining a failure.
*/
async function getTimeOutErrorMessage(namespace: string, selector: string): Promise<string> {
const kubeHelper = KubeClient.getInstance()
const pods = await kubeHelper.getPodListByLabel(namespace, selector)
if (!pods.length) {
throw new Error(`Timeout: there are no pods in the namespace: ${namespace}, selector: ${selector}. Check ${EclipseChe.PRODUCT_NAME} logs for details. Consider increasing error recheck timeout with --k8spoderrorrechecktimeout flag.`)
}

let errorMessage = 'Timeout:'
for (const pod of pods) {
errorMessage += `\nPod: ${pod.metadata!.name}`
if (pod.status) {
if (pod.status.containerStatuses) {
errorMessage += `\n\t\tstatus: ${JSON.stringify(pod.status.containerStatuses, undefined, ' ')}`
}

if (pod.status.conditions) {
errorMessage += `\n\t\tconditions: ${JSON.stringify(pod.status.conditions, undefined, ' ')}`
}
} else {
errorMessage += ', status not found.'
}
}

return errorMessage
}

async function getCheClusterFailState(namespace: string): Promise<FailState | undefined> {
const kubeHelper = KubeClient.getInstance()
const cheCluster = await kubeHelper.getCheCluster(namespace)
if (cheCluster?.status?.reason && cheCluster?.status?.message) {
return cheCluster.status
}
}
async function getTimeOutErrorMessage(namespace: string, selector: string): Promise<string> {
const kubeHelper = KubeClient.getInstance()
const pods = await kubeHelper.getPodListByLabel(namespace, selector)
if (!pods.length) {
throw new Error(`Timeout: there are no pods in the namespace: ${namespace}, selector: ${selector}. Check ${EclipseChe.PRODUCT_NAME} logs for details. Consider increasing error recheck timeout with --k8spoderrorrechecktimeout flag.`)
}

let errorMessage = 'Timeout:'
for (const pod of pods) {
errorMessage += `\nPod: ${pod.metadata!.name}`
if (pod.status) {
if (pod.status.containerStatuses) {
errorMessage += `\n\t\tstatus: ${JSON.stringify(pod.status.containerStatuses, undefined, ' ')}`
}

if (pod.status.conditions) {
errorMessage += `\n\t\tconditions: ${JSON.stringify(pod.status.conditions, undefined, ' ')}`
}
} else {
errorMessage += ', status not found.'
}
}

return errorMessage
}

async function getCheClusterFailState(namespace: string): Promise<FailState | undefined> {
const kubeHelper = KubeClient.getInstance()
const cheCluster = await kubeHelper.getCheCluster(namespace)
if (cheCluster?.status?.reason && cheCluster?.status?.message) {
return cheCluster.status
}
}
}

4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3673,7 +3673,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#8f3eafb9f91be8cdc0bc5c6df76e36900f5b000e"
resolved "https://github.com/devfile/devworkspace-operator#54561af09cf51e78e5e1295fb9f78b542138a0b9"

dezalgo@^1.0.0:
version "1.0.4"
Expand Down Expand Up @@ -3734,7 +3734,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#1ae01423c15e14cb9aff32c65bc2c71686a99ca5"
resolved "https://github.com/eclipse-che/che-operator#76b21ea63282e75c664913f0ed47f708870fdcc2"

editorconfig@^0.15.0:
version "0.15.3"
Expand Down
Loading