Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use olm installer by default for OpenShift 4 #693

Merged
merged 2 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}
}