From 2758465e6663b3924313ab75061a7149700faf06 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Fri, 8 May 2020 13:47:10 +0300 Subject: [PATCH 1/2] Use olm installer by default for OpenShift 4 Signed-off-by: Anatoliy Bazko --- README.md | 2 +- src/api/kube.ts | 10 +++++----- src/api/version.ts | 9 +++++++-- src/commands/server/start.ts | 7 +++++-- src/commands/server/update.ts | 9 ++++----- src/util.ts | 20 ++++++++++++++++++++ yarn.lock | 4 ++-- 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f457554fc..f7a59b174 100644 --- a/README.md +++ b/README.md @@ -304,7 +304,7 @@ USAGE OPTIONS -a, --installer=helm|operator|olm|minishift-addon - [default: operator] Installer type + Installer type -b, --domain=domain Domain of the Kubernetes cluster (e.g. example.k8s-cluster.com or .nip.io) diff --git a/src/api/kube.ts b/src/api/kube.ts index e8526ce03..349df19ee 100644 --- a/src/api/kube.ts +++ b/src/api/kube.ts @@ -1714,19 +1714,19 @@ export class KubeHelper { throw new Error('ERR_LIST_INGRESSES') } - async apiVersionExist(expectedVersion: string): Promise { + async isOpenShift4(): Promise { const k8sCoreApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApisApi) - // if matching APi Version try { const res = await k8sCoreApi.getAPIVersions() if (res && res.body && res.body.groups) { - return res.body.groups.some(version => version.name === expectedVersion) + return res.body.groups.some(group => group.name === 'route.openshift.io') + && res.body.groups.some(group => group.name === 'config.openshift.io') } else { return false } - } catch { - return false + } catch (e) { + throw this.wrapK8sClientError(e) } } diff --git a/src/api/version.ts b/src/api/version.ts index 2b67489b1..46ed9ac90 100644 --- a/src/api/version.ts +++ b/src/api/version.ts @@ -11,6 +11,8 @@ import execa = require('execa') import Listr = require('listr') +import { KubeHelper } from './kube' + export namespace VersionHelper { export const MINIMAL_OPENSHIFT_VERSION = '3.11' export const MINIMAL_K8S_VERSION = '1.9' @@ -20,11 +22,14 @@ export namespace VersionHelper { return { title: 'Check OpenShift version', task: async (_ctx: any, task: any) => { + const kubeHelper = new KubeHelper(flags) const actualVersion = await getOpenShiftVersion() if (actualVersion) { - task.title = `${task.title}: Found ${actualVersion}.` + task.title = `${task.title}: ${actualVersion}.` + } else if (await kubeHelper.isOpenShift4()) { + task.title = `${task.title}: 4.x` } else { - task.title = `${task.title}: Unknown.` + task.title = `${task.title}: Unknown` } if (!flags['skip-version-check'] && actualVersion) { diff --git a/src/commands/server/start.ts b/src/commands/server/start.ts index 6611ad512..832f9fb7f 100644 --- a/src/commands/server/start.ts +++ b/src/commands/server/start.ts @@ -24,7 +24,7 @@ import { getRetrieveKeycloakCredentialsTask, retrieveCheCaCertificateTask } from import { InstallerTasks } from '../../tasks/installers/installer' import { ApiTasks } from '../../tasks/platforms/api' import { PlatformTasks } from '../../tasks/platforms/platform' -import { isOpenshiftPlatformFamily } from '../../util' +import { isOpenshiftPlatformFamily, setDefaultInstaller } from '../../util' export default class Start extends Command { static description = 'start Eclipse Che server' @@ -98,7 +98,6 @@ export default class Start extends Command { char: 'a', description: 'Installer type', options: ['helm', 'operator', 'olm', 'minishift-addon'], - default: 'operator' }), domain: string({ char: 'b', @@ -192,6 +191,10 @@ export default class Start extends Command { async setPlaformDefaults(flags: any): Promise { flags.tls = await this.checkTlsMode(flags) + if (!flags.installer) { + await setDefaultInstaller(flags) + } + if (!flags.templates) { // use local templates folder if present const templates = 'templates' diff --git a/src/commands/server/update.ts b/src/commands/server/update.ts index 4453283fa..5bae999af 100644 --- a/src/commands/server/update.ts +++ b/src/commands/server/update.ts @@ -23,7 +23,7 @@ import { CheTasks } from '../../tasks/che' import { InstallerTasks } from '../../tasks/installers/installer' import { ApiTasks } from '../../tasks/platforms/api' import { PlatformTasks } from '../../tasks/platforms/platform' -import { isKubernetesPlatformFamily } from '../../util' +import { isKubernetesPlatformFamily, setDefaultInstaller } from '../../util' export default class Update extends Command { static description = 'update Eclipse Che server' @@ -33,7 +33,6 @@ export default class Update extends Command { char: 'a', description: 'Installer type', options: ['helm', 'operator', 'minishift-addon', 'olm'], - default: '' }), platform: string({ char: 'p', @@ -73,10 +72,10 @@ export default class Update extends Command { return path.join(__dirname, '../../../templates') } - checkIfInstallerSupportUpdating(flags: any) { + async checkIfInstallerSupportUpdating(flags: any) { // matrix checks if (!flags.installer) { - this.error('🛑 --installer parameter must be specified.') + await setDefaultInstaller(flags) } if (flags.installer === 'operator' || flags.installer === 'olm') { @@ -106,7 +105,7 @@ export default class Update extends Command { // Platform Checks let platformCheckTasks = new Listr(platformTasks.preflightCheckTasks(flags, this), listrOptions) - this.checkIfInstallerSupportUpdating(flags) + await this.checkIfInstallerSupportUpdating(flags) // Checks if Eclipse Che is already deployed let preInstallTasks = new Listr(undefined, listrOptions) diff --git a/src/util.ts b/src/util.ts index 3b7e8fa46..b643e85ff 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,8 +8,12 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ +import { cli } from 'cli-ux' import * as commandExists from 'command-exists' +import { KubeHelper } from './api/kube' +import { DEFAULT_CHE_OPERATOR_IMAGE } from './constants' + export const KUBERNETES_CLI = 'kubectl' export const OPENSHIFT_CLI = 'oc' @@ -64,3 +68,19 @@ export function generatePassword(passwodLength: number, charactersSet = '') { export function base64Decode(arg: string): string { return Buffer.from(arg, 'base64').toString('ascii') } + +/** + * Sets default installer which is `olm` for OpenShift 4 with stable version of chectl + * and `operator` for other cases. + */ +export async function setDefaultInstaller(flags: any): Promise { + const cheVersion = DEFAULT_CHE_OPERATOR_IMAGE.split(':')[1] + const kubeHelper = new KubeHelper(flags) + if (flags.platform === 'openshift' && await kubeHelper.isOpenShift4() && cheVersion !== 'nightly' && cheVersion !== 'latest') { + flags.installer = 'olm' + cli.info('OLM installer is used for OpenShift v4.x') + } else { + flags.installer = 'operator' + cli.info('Operator installer is used by default') + } +} diff --git a/yarn.lock b/yarn.lock index 42e060eef..21678351e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1521,11 +1521,11 @@ ecc-jsbn@~0.1.1: "eclipse-che-operator@git://github.com/eclipse/che-operator#master": version "0.0.0" - resolved "git://github.com/eclipse/che-operator#daa8b582393a43b349a1678ad978e55e1241e94e" + resolved "git://github.com/eclipse/che-operator#0c671d8a117a333ee36756e5d3a4a75171d64b14" "eclipse-che@git://github.com/eclipse/che#master": version "0.0.0" - resolved "git://github.com/eclipse/che#f3900600af44fae05270b729b6a0a83cc924ad4d" + resolved "git://github.com/eclipse/che#0fd09abd02140545c49b28bce186512afeb04336" editorconfig@^0.15.0: version "0.15.3" From 17dbce2fc5e6430c58e0ab6573054319ae06d0b2 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 13 May 2020 09:41:34 +0300 Subject: [PATCH 2/2] update yarn.lock Signed-off-by: Anatoliy Bazko --- yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index 21678351e..42e060eef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1521,11 +1521,11 @@ ecc-jsbn@~0.1.1: "eclipse-che-operator@git://github.com/eclipse/che-operator#master": version "0.0.0" - resolved "git://github.com/eclipse/che-operator#0c671d8a117a333ee36756e5d3a4a75171d64b14" + resolved "git://github.com/eclipse/che-operator#daa8b582393a43b349a1678ad978e55e1241e94e" "eclipse-che@git://github.com/eclipse/che#master": version "0.0.0" - resolved "git://github.com/eclipse/che#0fd09abd02140545c49b28bce186512afeb04336" + resolved "git://github.com/eclipse/che#f3900600af44fae05270b729b6a0a83cc924ad4d" editorconfig@^0.15.0: version "0.15.3"