diff --git a/src/api/che.ts b/src/api/che.ts index e0ca40118..4a1712a9a 100644 --- a/src/api/che.ts +++ b/src/api/che.ts @@ -24,7 +24,7 @@ import * as rimraf from 'rimraf' import * as unzipper from 'unzipper' import { OpenShiftHelper } from '../api/openshift' -import { CHE_ROOT_CA_SECRET_NAME, DEFAULT_CA_CERT_FILE_NAME, OPERATOR_TEMPLATE_DIR } from '../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_ROOT_CA_SECRET_NAME, DEFAULT_CA_CERT_FILE_NAME, OPERATOR_TEMPLATE_DIR } from '../constants' import { base64Decode, downloadFile } from '../util' import { CheApiClient } from './che-api-client' @@ -214,7 +214,7 @@ export class CheHelper { let adminUsername let adminPassword - const cheCluster = await this.kube.getCheCluster(cheNamespace) + const cheCluster = await this.kube.getCustomResource(cheNamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (!cheCluster || cheCluster.spec.auth.externalIdentityProvider) { return [] } diff --git a/src/api/kube.ts b/src/api/kube.ts index c8df43d7d..8d30ea006 100644 --- a/src/api/kube.ts +++ b/src/api/kube.ts @@ -1620,12 +1620,12 @@ export class KubeHelper { } /** - * Returns `checlusters.org.eclipse.che' in the given namespace. + * Returns custom resource in the given namespace. */ - async getCheCluster(namespace: string): Promise { + async getCustomResource(namespace: string, resourceAPIGroup: string, resourceAPIVersion: string, resourcePlural: string): Promise { const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi) try { - const { body } = await customObjectsApi.listNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters') + const { body } = await customObjectsApi.listNamespacedCustomObject(resourceAPIGroup, resourceAPIVersion, namespace, resourcePlural) if (!(body as any).items) { return } @@ -1634,13 +1634,13 @@ export class KubeHelper { if (crs.length === 0) { return } else if (crs.length !== 1) { - throw new Error(`Too many resources '${CHE_CLUSTER_CRD}' found in the namespace '${namespace}'`) + throw new Error(`Too many resources of type ${resourcePlural}.${resourceAPIGroup} found in the namespace '${namespace}'`) } return crs[0] } catch (e) { if (e.response.statusCode === 404) { - // There is no CR 'checluster` + // There is no CRD return } throw this.wrapK8sClientError(e) @@ -1648,44 +1648,16 @@ export class KubeHelper { } /** - * Returns `che.eclipse.org/v1alpha1' in the given namespace. + * Returns all custom resources */ - async getCheManagerInstance(namespace: string): Promise { + async getAllCustomResource(resourceAPIGroup: string, resourceAPIVersion: string, resourcePlural: string): Promise { const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi) try { - const { body } = await customObjectsApi.listNamespacedCustomObject('che.eclipse.org', 'v1alpha1', namespace, 'chemanagers') - if (!(body as any).items) { - return - } - - const crs = (body as any).items as any[] - if (crs.length === 0) { - return - } else if (crs.length !== 1) { - throw new Error(`Too many resources '${CHE_CLUSTER_CRD}' found in the namespace '${namespace}'`) - } - - return crs[0] - } catch (e) { - if (e.response.statusCode === 404) { - // There is no CR 'checluster` - return - } - throw this.wrapK8sClientError(e) - } - } - - /** - * Returns all `checlusters.org.eclipse.che' resources - */ - async getAllCheClusters(): Promise { - const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi) - try { - const { body } = await customObjectsApi.listClusterCustomObject('org.eclipse.che', 'v1', 'checlusters') + const { body } = await customObjectsApi.listClusterCustomObject(resourceAPIGroup, resourceAPIVersion, resourcePlural) return (body as any).items ? (body as any).items : [] } catch (e) { if (e.response.statusCode === 404) { - // There is no CRD 'checlusters` + // There is no CRD return [] } throw this.wrapK8sClientError(e) @@ -1693,47 +1665,23 @@ export class KubeHelper { } /** - * Deletes `checlusters.org.eclipse.che' resources in the given namespace. - */ - async deleteCheCluster(namespace: string): Promise { - const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi) - try { - const { body } = await customObjectsApi.listNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters') - if (!(body as any).items) { - return - } - - const crs = (body as any).items as any[] - for (const cr of crs) { - await customObjectsApi.deleteNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters', cr.metadata.name) - } - } catch (e) { - if (e.response.statusCode === 404) { - // There is no CRD 'checlusters` - return - } - throw this.wrapK8sClientError(e) - } - } - - /** - * Deletes `che.eclipse.org/v1alpha1' resources in the given namespace. + * Deletes custom resources in the given namespace. */ - async deleteCheManagerInstance(namespace: string): Promise { + async deleteCustomResource(namespace: string, resourceAPIGroup: string, resourceAPIVersion: string, resourcePlural: string): Promise { const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi) try { - const { body } = await customObjectsApi.listNamespacedCustomObject('che.eclipse.org', 'v1alpha1', namespace, 'checlusters') + const { body } = await customObjectsApi.listNamespacedCustomObject(resourceAPIGroup, resourceAPIVersion, namespace, resourcePlural) if (!(body as any).items) { return } const crs = (body as any).items as any[] for (const cr of crs) { - await customObjectsApi.deleteNamespacedCustomObject('che.eclipse.org', 'v1alpha1', namespace, 'checlusters', cr.metadata.name) + await customObjectsApi.deleteNamespacedCustomObject(resourceAPIGroup, resourceAPIVersion, namespace, resourcePlural, cr.metadata.name) } } catch (e) { if (e.response.statusCode === 404) { - // There is no CRD 'checlusters` + // There is no CRD return } throw this.wrapK8sClientError(e) diff --git a/src/api/version.ts b/src/api/version.ts index f0e4e79b0..e2b0c1ee4 100644 --- a/src/api/version.ts +++ b/src/api/version.ts @@ -17,7 +17,7 @@ import Listr = require('listr') import * as path from 'path' import * as semver from 'semver' -import { CHECTL_PROJECT_NAME } from '../constants' +import { CHECTL_PROJECT_NAME, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION } from '../constants' import { CheTasks } from '../tasks/che' import { getClusterClientCommand, getProjectName, getProjectVersion } from '../util' @@ -161,7 +161,7 @@ export namespace VersionHelper { export async function getCheVersion(flags: any): Promise { const kube = new KubeHelper(flags) const cheTasks = new CheTasks(flags) - const cheCluster = await kube.getCheCluster(flags.chenamespace) + const cheCluster = await kube.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (cheCluster && cheCluster.spec.server.cheFlavor !== 'che') { return cheCluster.status.cheVersion } diff --git a/src/commands/server/delete.ts b/src/commands/server/delete.ts index e7d71878b..95de3e289 100644 --- a/src/commands/server/delete.ts +++ b/src/commands/server/delete.ts @@ -17,7 +17,7 @@ import Listr = require('listr') import { ChectlContext } from '../../api/context' import { KubeHelper } from '../../api/kube' import { assumeYes, batch, cheDeployment, cheNamespace, CHE_TELEMETRY, listrRenderer, skipKubeHealthzCheck } from '../../common-flags' -import { DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants' import { CheTasks } from '../../tasks/che' import { DevWorkspaceTasks } from '../../tasks/component-installers/devfile-workspace-operator-installer' import { HelmTasks } from '../../tasks/installers/helm' @@ -80,9 +80,9 @@ export default class Delete extends Command { // Remove devworkspace controller only if there are no more cheClusters after olm/operator tasks tasks.add({ - title: 'Uninstall DevWorkspace Controller', + title: 'Uninstall DevWorkspace Controller and DevWorkspace Che Controller', task: async (_ctx: any, task: any) => { - const checlusters = await kube.getAllCheClusters() + const checlusters = await kube.getAllCustomResource(CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (checlusters.length === 0) { return new Listr(devWorkspaceTasks.getUninstallTasks()) } diff --git a/src/commands/server/status.ts b/src/commands/server/status.ts index 6da700e4a..f5d5c81e7 100644 --- a/src/commands/server/status.ts +++ b/src/commands/server/status.ts @@ -16,7 +16,7 @@ import { ChectlContext } from '../../api/context' import { KubeHelper } from '../../api/kube' import { VersionHelper } from '../../api/version' import { cheNamespace, CHE_TELEMETRY } from '../../common-flags' -import { DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants' import { findWorkingNamespace } from '../../util' export default class Status extends Command { @@ -39,7 +39,7 @@ export default class Status extends Command { let openshiftOauth = 'No' await this.config.runHook(DEFAULT_ANALYTIC_HOOK_NAME, { command: Status.id, flags }) - const cr = await kube.getCheCluster(flags.chenamespace) + const cr = await kube.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (cr && cr.spec && cr.spec.auth && cr.spec.auth.openShiftoAuth && await kube.isOpenShift()) { openshiftOauth = 'Yes' } diff --git a/src/commands/server/update.ts b/src/commands/server/update.ts index ecfdf8d98..8bb943720 100644 --- a/src/commands/server/update.ts +++ b/src/commands/server/update.ts @@ -18,7 +18,7 @@ import * as semver from 'semver' import { ChectlContext } from '../../api/context' import { KubeHelper } from '../../api/kube' import { assumeYes, batch, cheDeployment, cheDeployVersion, cheNamespace, cheOperatorCRPatchYaml, CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_TELEMETRY, DEPLOY_VERSION_KEY, listrRenderer, skipKubeHealthzCheck } from '../../common-flags' -import { DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_CHE_OPERATOR_IMAGE_NAME, MIN_CHE_OPERATOR_INSTALLER_VERSION, SUBSCRIPTION_NAME } from '../../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_CHE_OPERATOR_IMAGE_NAME, MIN_CHE_OPERATOR_INSTALLER_VERSION, SUBSCRIPTION_NAME } from '../../constants' import { checkChectlAndCheVersionCompatibility, downloadTemplates, getPrintHighlightedMessagesTask } from '../../tasks/installers/common-tasks' import { InstallerTasks } from '../../tasks/installers/installer' import { ApiTasks } from '../../tasks/platforms/api' @@ -170,7 +170,7 @@ export default class Update extends Command { */ private async checkComponentImages(flags: any): Promise { const kubeHelper = new KubeHelper(flags) - const cheCluster = await kubeHelper.getCheCluster(flags.chenamespace) + const cheCluster = await kubeHelper.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (cheCluster.spec.server.cheImage || cheCluster.spec.server.cheImageTag || cheCluster.spec.server.devfileRegistryImage @@ -364,7 +364,7 @@ export default class Update extends Command { */ private async setDomainFlag(flags: any): Promise { const kubeHelper = new KubeHelper(flags) - const cheCluster = await kubeHelper.getCheCluster(flags.chenamespace) + const cheCluster = await kubeHelper.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (cheCluster && cheCluster.spec.k8s && cheCluster.spec.k8s.ingressDomain) { flags.domain = cheCluster.spec.k8s.ingressDomain } diff --git a/src/constants.ts b/src/constants.ts index 75fcee13a..c3b1672d7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -30,7 +30,6 @@ export const CHE_TLS_SECRET_NAME = 'che-tls' export const CHE_ROOT_CA_SECRET_NAME = 'self-signed-certificate' export const DEFAULT_CA_CERT_FILE_NAME = 'cheCA.crt' export const CHE_CLUSTER_CR_NAME = 'eclipse-che' -export const CHE_CLUSTER_CRD = 'checlusters.org.eclipse.che' // operator export const OPERATOR_DEPLOYMENT_NAME = 'che-operator' @@ -77,3 +76,8 @@ export const DEFAULT_ANALYTIC_HOOK_NAME = 'analytics' // Timeouts export const DEFAULT_K8S_POD_WAIT_TIMEOUT = 600000 export const DEFAULT_K8S_POD_ERROR_RECHECK_TIMEOUT = 15000 + +// Custom Resources names +export const CHE_CLUSTER_CRD = 'checlusters.org.eclipse.che' +export const CHE_CLUSTER_API_GROUP = 'org.eclipse.che' +export const CHE_CLUSTER_API_VERSION = 'v1' diff --git a/src/tasks/che.ts b/src/tasks/che.ts index 5d1ab39ed..79b36a363 100644 --- a/src/tasks/che.ts +++ b/src/tasks/che.ts @@ -16,7 +16,7 @@ import { CheServerLoginManager } from '../api/che-login-manager' import { KubeHelper } from '../api/kube' import { OpenShiftHelper } from '../api/openshift' import { VersionHelper } from '../api/version' -import { CHE_OPERATOR_SELECTOR, DOC_LINK, DOC_LINK_RELEASE_NOTES, OUTPUT_SEPARATOR } from '../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_OPERATOR_SELECTOR, DOC_LINK, DOC_LINK_RELEASE_NOTES, OUTPUT_SEPARATOR } from '../constants' import { base64Decode } from '../util' import { KubeTasks } from './kube' @@ -456,7 +456,7 @@ export class CheTasks { { title: `Delete consoleLink ${this.cheConsoleLinkName}`, task: async (_ctx: any, task: any) => { - const checlusters = await this.kube.getAllCheClusters() + const checlusters = await this.kube.getAllCustomResource(CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') // Delete the consoleLink only in case if there no more checluster installed if (checlusters.length === 0) { await this.kube.deleteConsoleLink(this.cheConsoleLinkName) @@ -669,7 +669,7 @@ export class CheTasks { const cheUrl = await this.che.cheURL(flags.chenamespace) messages.push(`Users Dashboard : ${cheUrl}`) - const cr = await this.kube.getCheCluster(flags.chenamespace) + const cr = await this.kube.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (ctx.isOpenShift && cr && cr.spec && cr.spec.auth && cr.spec.auth.openShiftoAuth) { if (cr.status && cr.status.openShiftOAuthUserCredentialsSecret) { let user = '' diff --git a/src/tasks/component-installers/devfile-workspace-operator-installer.ts b/src/tasks/component-installers/devfile-workspace-operator-installer.ts index d631b1e75..5b4433fea 100644 --- a/src/tasks/component-installers/devfile-workspace-operator-installer.ts +++ b/src/tasks/component-installers/devfile-workspace-operator-installer.ts @@ -285,15 +285,18 @@ export class DevWorkspaceTasks { { title: `Delete the Custom Resource of type ${this.cheManagerCRDName}`, task: async (_ctx: any, task: any) => { - await this.kubeHelper.deleteCheManagerInstance(this.devworkspaceCheNamespace) - // if chemanager instance still exists then remove finalizers and delete again - const chemanager = await this.kubeHelper.getCheManagerInstance(this.devworkspaceCheNamespace) + await this.kubeHelper.deleteCustomResource(this.devworkspaceCheNamespace, this.cheManagerApiGroupName, this.cheManagerApiVersionName, 'chemanagers') + + // wait 10 seconds + await cli.wait(10000) + // if chemanager instance still exists then remove finalizers and delete again + const chemanager = await this.kubeHelper.getCustomResource(this.devworkspaceCheNamespace, this.cheManagerApiGroupName, this.cheManagerApiVersionName, 'chemanagers') if (chemanager) { try { await this.kubeHelper.patchCustomResource(chemanager.metadata.name, this.devworkspaceCheNamespace, { metadata: { finalizers: null } }, this.cheManagerApiGroupName, this.cheManagerApiVersionName, 'chemanagers') } catch (error) { - if (await this.kubeHelper.getCheManagerInstance(this.devworkspaceCheNamespace)) { + if (await this.kubeHelper.getCustomResource(this.devworkspaceCheNamespace, this.cheManagerApiGroupName, this.cheManagerApiVersionName, 'chemanagers')) { task.title = `${task.title}...OK` return // successfully removed } @@ -304,7 +307,7 @@ export class DevWorkspaceTasks { await cli.wait(2000) } - if (!await this.kubeHelper.getCheManagerInstance(this.devworkspaceCheNamespace)) { + if (!await this.kubeHelper.getCustomResource(this.devworkspaceCheNamespace, this.cheManagerApiGroupName, this.cheManagerApiVersionName, 'chemanagers')) { task.title = `${task.title}...OK` } else { task.title = `${task.title}...Failed` diff --git a/src/tasks/installers/common-tasks.ts b/src/tasks/installers/common-tasks.ts index beb14986a..cab2049cb 100644 --- a/src/tasks/installers/common-tasks.ts +++ b/src/tasks/installers/common-tasks.ts @@ -21,7 +21,7 @@ import { ChectlContext } from '../../api/context' import { CheGithubClient } from '../../api/github-client' import { KubeHelper } from '../../api/kube' import { VersionHelper } from '../../api/version' -import { CHE_CLUSTER_CRD, DOCS_LINK_IMPORT_CA_CERT_INTO_BROWSER, OPERATOR_TEMPLATE_DIR } from '../../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_CRD, DOCS_LINK_IMPORT_CA_CERT_INTO_BROWSER, OPERATOR_TEMPLATE_DIR } from '../../constants' import { getProjectVersion } from '../../util' export function createNamespaceTask(namespaceName: string, labels: {}): Listr.ListrTask { @@ -165,7 +165,7 @@ export function patchingEclipseCheCluster(flags: any, kube: KubeHelper, command: title: `Patching the Custom Resource of type '${CHE_CLUSTER_CRD}' in the namespace '${flags.chenamespace}'`, skip: (ctx: any) => isEmpty(ctx[ChectlContext.CR_PATCH]), task: async (ctx: any, task: any) => { - const cheCluster = await kube.getCheCluster(flags.chenamespace) + const cheCluster = await kube.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (!cheCluster) { command.error(`Eclipse Che cluster CR is not found in the namespace '${flags.chenamespace}'`) } diff --git a/src/tasks/installers/olm.ts b/src/tasks/installers/olm.ts index 66776e947..b482d1d10 100644 --- a/src/tasks/installers/olm.ts +++ b/src/tasks/installers/olm.ts @@ -17,7 +17,7 @@ import * as path from 'path' import { KubeHelper } from '../../api/kube' import { CatalogSource, Subscription } from '../../api/typings/olm' import { VersionHelper } from '../../api/version' -import { CUSTOM_CATALOG_SOURCE_NAME, CVS_PREFIX, DEFAULT_CHE_OLM_PACKAGE_NAME, DEFAULT_OLM_KUBERNETES_NAMESPACE, DEFAULT_OPENSHIFT_MARKET_PLACE_NAMESPACE, KUBERNETES_OLM_CATALOG, NIGHTLY_CATALOG_SOURCE_NAME, OLM_NIGHTLY_CHANNEL_NAME, OLM_STABLE_CHANNEL_NAME, OPENSHIFT_OLM_CATALOG, OPERATOR_GROUP_NAME, SUBSCRIPTION_NAME } from '../../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CUSTOM_CATALOG_SOURCE_NAME, CVS_PREFIX, DEFAULT_CHE_OLM_PACKAGE_NAME, DEFAULT_OLM_KUBERNETES_NAMESPACE, DEFAULT_OPENSHIFT_MARKET_PLACE_NAMESPACE, KUBERNETES_OLM_CATALOG, NIGHTLY_CATALOG_SOURCE_NAME, OLM_NIGHTLY_CHANNEL_NAME, OLM_STABLE_CHANNEL_NAME, OPENSHIFT_OLM_CATALOG, OPERATOR_GROUP_NAME, SUBSCRIPTION_NAME } from '../../constants' import { isKubernetesPlatformFamily } from '../../util' import { createEclipseCheCluster, createNamespaceTask, patchingEclipseCheCluster } from './common-tasks' @@ -198,7 +198,7 @@ export class OLMTasks { { title: 'Prepare Eclipse Che cluster CR', task: async (ctx: any, task: any) => { - const cheCluster = await kube.getCheCluster(flags.chenamespace) + const cheCluster = await kube.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (cheCluster) { task.title = `${task.title}...It already exists..` return diff --git a/src/tasks/installers/operator.ts b/src/tasks/installers/operator.ts index cdeef823e..1ea78a41a 100644 --- a/src/tasks/installers/operator.ts +++ b/src/tasks/installers/operator.ts @@ -17,7 +17,7 @@ import * as path from 'path' import { ChectlContext } from '../../api/context' import { KubeHelper } from '../../api/kube' import { VersionHelper } from '../../api/version' -import { CHE_CLUSTER_CRD, CHE_OPERATOR_SELECTOR, OPERATOR_DEPLOYMENT_NAME, OPERATOR_TEMPLATE_DIR } from '../../constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_CRD, CHE_OPERATOR_SELECTOR, OPERATOR_DEPLOYMENT_NAME, OPERATOR_TEMPLATE_DIR } from '../../constants' import { safeLoadFromYamlFile } from '../../util' import { KubeTasks } from '../kube' @@ -258,7 +258,7 @@ export class OperatorTasks { { title: 'Prepare Eclipse Che cluster CR', task: async (ctx: any, task: any) => { - const cheCluster = await kube.getCheCluster(flags.chenamespace) + const cheCluster = await kube.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (cheCluster) { task.title = `${task.title}...It already exists..` return @@ -445,7 +445,7 @@ export class OperatorTasks { return [{ title: 'Delete oauthClientAuthorizations', task: async (_ctx: any, task: any) => { - const checluster = await kh.getCheCluster(flags.chenamespace) + const checluster = await kh.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (checluster && checluster.spec && checluster.spec.auth && checluster.spec.auth.oAuthClientName) { const oAuthClientAuthorizations = await kh.getOAuthClientAuthorizations(checluster.spec.auth.oAuthClientName) await kh.deleteOAuthClientAuthorizations(oAuthClientAuthorizations) @@ -456,24 +456,24 @@ export class OperatorTasks { { title: `Delete the Custom Resource of type ${CHE_CLUSTER_CRD}`, task: async (_ctx: any, task: any) => { - await kh.deleteCheCluster(flags.chenamespace) + await kh.deleteCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') // wait 20 seconds, default timeout in che operator for (let index = 0; index < 20; index++) { await cli.wait(1000) - if (!await kh.getCheCluster(flags.chenamespace)) { + if (!await kh.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters')) { task.title = `${task.title}...OK` return } } // if checluster still exists then remove finalizers and delete again - const checluster = await kh.getCheCluster(flags.chenamespace) + const checluster = await kh.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (checluster) { try { await kh.patchCustomResource(checluster.metadata.name, flags.chenamespace, { metadata: { finalizers: null } }, 'org.eclipse.che', 'v1', 'checlusters') } catch (error) { - if (await kh.getCheCluster(flags.chenamespace)) { + if (await kh.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters')) { task.title = `${task.title}...OK` return // successfully removed } @@ -484,7 +484,7 @@ export class OperatorTasks { await cli.wait(2000) } - if (!await kh.getCheCluster(flags.chenamespace)) { + if (!await kh.getCustomResource(flags.chenamespace, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters')) { task.title = `${task.title}...OK` } else { task.title = `${task.title}...Failed` @@ -494,7 +494,7 @@ export class OperatorTasks { { title: `Delete CRD ${this.cheClusterCrd}`, task: async (_ctx: any, task: any) => { - const checlusters = await kh.getAllCheClusters() + const checlusters = await kh.getAllCustomResource(CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (checlusters.length > 0) { task.title = `${task.title}...Skipped: another Eclipse Che deployment found.` } else { diff --git a/test/e2e/util.ts b/test/e2e/util.ts index 74ff96554..fc415b7fc 100644 --- a/test/e2e/util.ts +++ b/test/e2e/util.ts @@ -15,7 +15,7 @@ import { CheHelper } from '../../src/api/che' import { CheGithubClient, TagInfo } from '../../src/api/github-client' import { KubeHelper } from '../../src/api/kube' import { OpenShiftHelper } from '../../src/api/openshift' -import { DEFAULT_OLM_SUGGESTED_NAMESPACE } from '../../src/constants' +import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, DEFAULT_OLM_SUGGESTED_NAMESPACE } from '../../src/constants' // Fields which chectl returns for workspace:list commands interface WorkspaceInfo { @@ -181,7 +181,7 @@ export class E2eHelper { let totalTimeMs = 0 while (totalTimeMs < timeoutMs) { - const cheCR = await this.kubeHelper.getCheCluster(NAMESPACE) + const cheCR = await this.kubeHelper.getCustomResource(NAMESPACE, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, 'checlusters') if (cheCR && cheCR.status && cheCR.status.cheVersion === version) { return }