From 96a24ce648558a96451c040bc1b832b17e096f27 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Mon, 19 Feb 2024 10:34:08 +0100 Subject: [PATCH] feat: Use registry.devfile.io by default in Eclipse Che Signed-off-by: Anatolii Bazko --- src/tasks/pod-tasks.ts | 80 ++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/tasks/pod-tasks.ts b/src/tasks/pod-tasks.ts index 3062db990..97b3bd76c 100644 --- a/src/tasks/pod-tasks.ts +++ b/src/tasks/pod-tasks.ts @@ -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' @@ -59,8 +59,12 @@ export namespace PodTasks { return { title: `Scale ${name} ${replicas > 0 ? 'Up' : 'Down'}`, task: async (_ctx: any, task: any) => { - await kubeHelper.scaleDeployment(deploymentName, namespace, replicas) - task.title = `${task.title}...[OK]` + if (await kubeHelper.isDeploymentExist(deploymentName, namespace)) { + await kubeHelper.scaleDeployment(deploymentName, namespace, replicas) + task.title = `${task.title}...[OK]` + } else { + task.title = `${task.title}...[Not found]` + } }, } } @@ -265,8 +269,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 { const kubeHelper = KubeClient.getInstance() const waitingState = await kubeHelper.getPodWaitingState(namespace, selector, state) @@ -278,38 +282,38 @@ export namespace PodTasks { /** * Returns extended timeout error message explaining a failure. */ - async function getTimeOutErrorMessage(namespace: string, selector: string): Promise { - 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 { - 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 { + 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 { + const kubeHelper = KubeClient.getInstance() + const cheCluster = await kubeHelper.getCheCluster(namespace) + if (cheCluster?.status?.reason && cheCluster?.status?.message) { + return cheCluster.status + } + } }