diff --git a/src/tasks/platform-tasks.ts b/src/tasks/platform-tasks.ts deleted file mode 100644 index 0601c8915..000000000 --- a/src/tasks/platform-tasks.ts +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2019-2022 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/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ - -import * as Listr from 'listr' -import {CheCtlContext, OIDCContext} from '../context' -import {KubeClient} from '../api/kube-client' -import {PLATFORM_FLAG, SKIP_OIDC_PROVIDER_FLAG} from '../flags' -import {EclipseChe} from './installers/eclipse-che/eclipse-che' - -export namespace PlatformTasks { - export function getEnsureOIDCProviderInstalledTask(): Listr.ListrTask { - const flags = CheCtlContext.getFlags() - return { - title: 'Check if OIDC Provider installed', - enabled: () => !flags[SKIP_OIDC_PROVIDER_FLAG], - skip: () => { - if (flags[PLATFORM_FLAG] === 'minikube') { - return 'Dex will be automatically installed as OIDC Identity Provider' - } - }, - task: async (_ctx: any, task: any) => { - const kubeHelper = KubeClient.getInstance() - const apiServerPods = await kubeHelper.getPodListByLabel('kube-system', 'component=kube-apiserver') - for (const pod of apiServerPods) { - if (!pod.spec) { - continue - } - - for (const container of pod.spec.containers) { - if (container.command && container.command.some(value => value.includes(OIDCContext.ISSUER_URL)) && container.command.some(value => value.includes(OIDCContext.CLIENT_ID))) { - task.title = `${task.title}...[OK]` - return - } - - if (container.args && container.args.some(value => value.includes(OIDCContext.ISSUER_URL)) && container.args.some(value => value.includes(OIDCContext.CLIENT_ID))) { - task.title = `${task.title}...[OK]` - return - } - } - } - - task.title = `${task.title}...[Not Found]` - throw new Error(`API server is not configured with OIDC Identity Provider, see details ${EclipseChe.DOC_LINK_CONFIGURE_API_SERVER}. To bypass OIDC Provider check, use \'--skip-oidc-provider-check\' flag`) - }, - } - } -} diff --git a/src/tasks/platforms/platform-tasks.ts b/src/tasks/platforms/platform-tasks.ts index ded322fe9..f7b7e964a 100644 --- a/src/tasks/platforms/platform-tasks.ts +++ b/src/tasks/platforms/platform-tasks.ts @@ -18,14 +18,53 @@ import { K8sTasks } from './k8s' import { MicroK8sTasks } from './microk8s' import { MinikubeTasks } from './minikube' import { OpenshiftTasks } from './openshift' -import {CheCtlContext} from '../../context' -import {PLATFORM_FLAG} from '../../flags' +import {EclipseChe} from '../installers/eclipse-che/eclipse-che' +import {KubeClient} from '../../api/kube-client' +import {CheCtlContext, OIDCContext} from '../../context' +import {PLATFORM_FLAG, SKIP_OIDC_PROVIDER_FLAG} from '../../flags' import {newListr} from '../../utils/utls' /** * Platform specific tasks. */ export namespace PlatformTasks { + export function getEnsureOIDCProviderInstalledTask(): Listr.ListrTask { + const flags = CheCtlContext.getFlags() + return { + title: 'Check if OIDC Provider installed', + enabled: () => !flags[SKIP_OIDC_PROVIDER_FLAG], + skip: () => { + if (flags[PLATFORM_FLAG] === 'minikube') { + return 'Dex will be automatically installed as OIDC Identity Provider' + } + }, + task: async (_ctx: any, task: any) => { + const kubeHelper = KubeClient.getInstance() + const apiServerPods = await kubeHelper.getPodListByLabel('kube-system', 'component=kube-apiserver') + for (const pod of apiServerPods) { + if (!pod.spec) { + continue + } + + for (const container of pod.spec.containers) { + if (container.command && container.command.some(value => value.includes(OIDCContext.ISSUER_URL)) && container.command.some(value => value.includes(OIDCContext.CLIENT_ID))) { + task.title = `${task.title}...[OK]` + return + } + + if (container.args && container.args.some(value => value.includes(OIDCContext.ISSUER_URL)) && container.args.some(value => value.includes(OIDCContext.CLIENT_ID))) { + task.title = `${task.title}...[OK]` + return + } + } + } + + task.title = `${task.title}...[Not Found]` + throw new Error(`API server is not configured with OIDC Identity Provider, see details ${EclipseChe.DOC_LINK_CONFIGURE_API_SERVER}. To bypass OIDC Provider check, use \'--skip-oidc-provider-check\' flag`) + }, + } + } + export function getPreflightCheckTasks(): Listr.ListrTask { const flags = CheCtlContext.getFlags()