Skip to content

Commit

Permalink
Use olm installer by default for OpenShift 4
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed May 13, 2020
1 parent dc8bbbe commit 2758465
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <local-ip>.nip.io)
Expand Down
10 changes: 5 additions & 5 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1714,19 +1714,19 @@ export class KubeHelper {
throw new Error('ERR_LIST_INGRESSES')
}

async apiVersionExist(expectedVersion: string): Promise<boolean> {
async isOpenShift4(): Promise<boolean> {
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)
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/api/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/commands/server/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -192,6 +191,10 @@ export default class Start extends Command {
async setPlaformDefaults(flags: any): Promise<void> {
flags.tls = await this.checkTlsMode(flags)

if (!flags.installer) {
await setDefaultInstaller(flags)
}

if (!flags.templates) {
// use local templates folder if present
const templates = 'templates'
Expand Down
9 changes: 4 additions & 5 deletions src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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',
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<void> {
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')
}
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2758465

Please sign in to comment.