Skip to content

Commit

Permalink
feat: Use nightly olm channel. (#845)
Browse files Browse the repository at this point in the history
* Use nightly olm channel.

Signed-off-by: Oleksandr Andriienko <[email protected]>
  • Loading branch information
AndrienkoAleksandr authored Sep 12, 2020
1 parent 05515f4 commit 29ab89b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 30 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. If not set, default is "olm" for OpenShift 4.x platform otherwise "operator".
-b, --domain=domain
Domain of the Kubernetes cluster (e.g. example.k8s-cluster.com or <local-ip>.nip.io)
Expand Down
16 changes: 13 additions & 3 deletions src/api/typings/olm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,20 @@ export interface CatalogSource {
}

export interface CatalogSourceSpec {
address: string
base64data: string
mediatype: string
address?: string
base64data?: string
mediatype?: string
sourceType: string
image: string
updateStrategy: CatalogSourceUpdateStrategy
}

export interface CatalogSourceUpdateStrategy {
registryPoll: CatalogSourceRegistryPoll
}

export interface CatalogSourceRegistryPoll {
interval: string
}

export interface PackageManifest {
Expand Down
11 changes: 5 additions & 6 deletions src/commands/server/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { InstallerTasks } from '../../tasks/installers/installer'
import { ApiTasks } from '../../tasks/platforms/api'
import { CommonPlatformTasks } from '../../tasks/platforms/common-platform-tasks'
import { PlatformTasks } from '../../tasks/platforms/platform'
import { isOpenshiftPlatformFamily, isStableVersion } from '../../util'
import { isOpenshiftPlatformFamily } from '../../util'

export default class Start extends Command {
static description = 'start Eclipse Che server'
Expand Down Expand Up @@ -96,9 +96,8 @@ export default class Start extends Command {
}),
installer: string({
char: 'a',
description: `Installer type.${isStableVersion({}) ? ' If not set, default is "olm" for OpenShift 4.x platform otherwise "operator".' : ''}`,
description: 'Installer type. If not set, default is "olm" for OpenShift 4.x platform otherwise "operator".',
options: ['helm', 'operator', 'olm', 'minishift-addon'],
default: `${isStableVersion({}) ? '' : 'operator'}`,
}),
domain: string({
char: 'b',
Expand Down Expand Up @@ -435,13 +434,13 @@ export default class Start extends Command {
async setDefaultInstaller(flags: any): Promise<void> {
const kubeHelper = new KubeHelper(flags)

const olmIsPreinstalled = await kubeHelper.isPreInstalledOLM()
if ((flags['catalog-source-name'] || flags['catalog-source-yaml']) && olmIsPreinstalled) {
const isOlmPreinstalled = await kubeHelper.isPreInstalledOLM()
if ((flags['catalog-source-name'] || flags['catalog-source-yaml']) && isOlmPreinstalled) {
flags.installer = 'olm'
return
}

if (flags.platform === 'openshift' && await kubeHelper.isOpenShift4() && isStableVersion(flags) && olmIsPreinstalled) {
if (flags.platform === 'openshift' && await kubeHelper.isOpenShift4() && isOlmPreinstalled) {
flags.installer = 'olm'
} else {
flags.installer = 'operator'
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const CHE_CLUSTER_CRD = 'checlusters.org.eclipse.che'
// OLM
export const DEFAULT_CHE_OLM_PACKAGE_NAME = 'eclipse-che'
export const OLM_STABLE_CHANNEL_NAME = 'stable'
export const OLM_NIGHTLY_CHANNEL_NAME = 'nightly'
export const DEFAULT_OPENSHIFT_MARKET_PLACE_NAMESPACE = 'openshift-marketplace'
export const DEFAULT_OLM_KUBERNETES_NAMESPACE = 'olm'
export const CUSTOM_CATALOG_SOURCE_NAME = 'eclipse-che-custom-catalog-source'
Expand All @@ -33,6 +34,7 @@ export const OPERATOR_GROUP_NAME = 'che-operator-group'
export const KUBERNETES_OLM_CATALOG = 'operatorhubio-catalog'
export const OPENSHIFT_OLM_CATALOG = 'community-operators'
export const CVS_PREFIX = 'eclipse-che'
export const NIGHTLY_CATALOG_SOURCE_NAME = 'eclipse-che-preview'

// Documentation links
export const DOCS_LINK_INSTALL_RUNNING_CHE_LOCALLY = 'https://www.eclipse.org/che/docs/che-7/overview/running-che-locally/'
Expand Down
74 changes: 57 additions & 17 deletions src/tasks/installers/olm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Listr = require('listr')

import { KubeHelper } from '../../api/kube'
import { CatalogSource, Subscription } from '../../api/typings/olm'
import { CUSTOM_CATALOG_SOURCE_NAME, CVS_PREFIX, DEFAULT_CHE_IMAGE, DEFAULT_CHE_OLM_PACKAGE_NAME, DEFAULT_OLM_KUBERNETES_NAMESPACE, DEFAULT_OPENSHIFT_MARKET_PLACE_NAMESPACE, KUBERNETES_OLM_CATALOG, OLM_STABLE_CHANNEL_NAME, OPENSHIFT_OLM_CATALOG, OPERATOR_GROUP_NAME, SUBSCRIPTION_NAME } from '../../constants'
import { isKubernetesPlatformFamily } from '../../util'
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 { isKubernetesPlatformFamily, isStableVersion } from '../../util'

import { copyOperatorResources, createEclipseCheCluster, createNamespaceTask } from './common-tasks'

Expand All @@ -25,9 +25,6 @@ export class OLMTasks {
*/
startTasks(flags: any, command: Command): Listr {
const kube = new KubeHelper(flags)
if (this.isNightlyChectlChannel() && !flags['catalog-source-yaml']) {
command.warn('A nightly channel for Eclipse Che is not available on OpenShift OLM catalog, the latest stable release will be deployed instead. To get a nightly release of Eclipse Che use the `operator` installer (--installer=operator).')
}
return new Listr([
this.isOlmPreInstalledTask(command, kube),
copyOperatorResources(flags, command.config.cacheDir),
Expand All @@ -53,10 +50,25 @@ export class OLMTasks {
ctx.approvalStarategy = flags['auto-update'] ? 'Automatic' : 'Manual'

ctx.sourceName = flags['catalog-source-name'] || CUSTOM_CATALOG_SOURCE_NAME
ctx.generalPlatformName = isKubernetesPlatformFamily(flags.platform) ? 'kubernetes' : 'openshift'

task.title = `${task.title}...done.`
}
},
{
enabled: () => !isStableVersion(flags),
title: `Create nightly index CatalogSource in the namespace ${flags.chenamespace}`,
task: async (ctx: any, task: any) => {
if (!await kube.catalogSourceExists(NIGHTLY_CATALOG_SOURCE_NAME, flags.chenamespace)) {
const catalogSourceImage = `quay.io/eclipse/eclipse-che-${ctx.generalPlatformName}-opm-catalog:preview`
const nigthlyCatalogSource = this.constructIndexCatalogSource(flags.chenamespace, catalogSourceImage)
await kube.createCatalogSource(nigthlyCatalogSource)
await kube.waitCatalogSource(flags.chenamespace, NIGHTLY_CATALOG_SOURCE_NAME)
} else {
task.title = `${task.title}...It already exists.`
}
}
},
{
enabled: () => flags['catalog-source-yaml'],
title: 'Create custom catalog source from file',
Expand All @@ -80,11 +92,17 @@ export class OLMTasks {
task.title = `${task.title}...It already exists.`
} else {
let subscription: Subscription
if (!flags['catalog-source-yaml'] && !flags['catalog-source-name']) {
subscription = this.createSubscription(SUBSCRIPTION_NAME, DEFAULT_CHE_OLM_PACKAGE_NAME, flags.chenamespace, ctx.defaultCatalogSourceNamespace, OLM_STABLE_CHANNEL_NAME, ctx.catalogSourceNameStable, ctx.approvalStarategy, flags['starting-csv'])
} else {

// stable Che CatalogSource
if (isStableVersion(flags)) {
subscription = this.constructSubscription(SUBSCRIPTION_NAME, DEFAULT_CHE_OLM_PACKAGE_NAME, flags.chenamespace, ctx.defaultCatalogSourceNamespace, OLM_STABLE_CHANNEL_NAME, ctx.catalogSourceNameStable, ctx.approvalStarategy, flags['starting-csv'])
// custom Che CatalogSource
} else if (flags['catalog-source-yaml'] || flags['catalog-source-name']) {
const catalogSourceNamespace = flags['catalog-source-namespace'] || flags.chenamespace
subscription = this.createSubscription(SUBSCRIPTION_NAME, flags['package-manifest-name'], flags.chenamespace, catalogSourceNamespace, flags['olm-channel'], ctx.sourceName, ctx.approvalStarategy, flags['starting-csv'])
subscription = this.constructSubscription(SUBSCRIPTION_NAME, flags['package-manifest-name'], flags.chenamespace, catalogSourceNamespace, flags['olm-channel'], ctx.sourceName, ctx.approvalStarategy, flags['starting-csv'])
// nightly Che CatalogSource
} else {
subscription = this.constructSubscription(SUBSCRIPTION_NAME, `eclipse-che-preview-${ctx.generalPlatformName}`, flags.chenamespace, flags.chenamespace, OLM_NIGHTLY_CHANNEL_NAME, NIGHTLY_CATALOG_SOURCE_NAME, ctx.approvalStarategy, flags['starting-csv'])
}
await kube.createOperatorSubscription(subscription)
task.title = `${task.title}...created new one.`
Expand Down Expand Up @@ -236,6 +254,15 @@ export class OLMTasks {
}
task.title = `${task.title}...OK`
}
},
{
title: `Delete(OLM) nigthly catalog source ${NIGHTLY_CATALOG_SOURCE_NAME}`,
task: async (_ctx: any, task: any) => {
if (await kube.catalogSourceExists(NIGHTLY_CATALOG_SOURCE_NAME, flags.chenamespace)) {
await kube.deleteCatalogSource(flags.chenamespace, NIGHTLY_CATALOG_SOURCE_NAME)
}
task.title = `${task.title}...OK`
}
}
]
}
Expand All @@ -254,14 +281,7 @@ export class OLMTasks {
}
}

private isNightlyChectlChannel(): boolean {
if (DEFAULT_CHE_IMAGE.endsWith(':nightly')) {
return true
}
return false
}

private createSubscription(name: string, packageName: string, namespace: string, sourceNamespace: string, channel: string, sourceName: string, installPlanApproval: string, startingCSV?: string): Subscription {
private constructSubscription(name: string, packageName: string, namespace: string, sourceNamespace: string, channel: string, sourceName: string, installPlanApproval: string, startingCSV?: string): Subscription {
return {
apiVersion: 'operators.coreos.com/v1alpha1',
kind: 'Subscription',
Expand All @@ -279,4 +299,24 @@ export class OLMTasks {
}
}
}

private constructIndexCatalogSource(namespace: string, catalogSourceImage: string): CatalogSource {
return {
apiVersion: 'operators.coreos.com/v1alpha1',
kind: 'CatalogSource',
metadata: {
name: NIGHTLY_CATALOG_SOURCE_NAME,
namespace,
},
spec: {
image: catalogSourceImage,
sourceType: 'grpc',
updateStrategy: {
registryPoll: {
interval: '15m'
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function base64Decode(arg: string): string {
export function isStableVersion(flags: any): boolean {
const operatorImage = flags['che-operator-image'] || DEFAULT_CHE_OPERATOR_IMAGE
const cheVersion = getImageTag(operatorImage)
return cheVersion !== 'nightly' && cheVersion !== 'latest'
return cheVersion !== 'nightly' && cheVersion !== 'latest' && !flags['catalog-source-yaml'] && !flags['catalog-source-name']
}

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1548,11 +1548,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#aeef0ef21ab482d6f35a686dc4be5d5ce15bda5d"
resolved "git://github.com/eclipse/che-operator#f7a2bed4d2bb52a43740618443cecb48851af6dd"

"eclipse-che@git://github.com/eclipse/che#master":
version "0.0.0"
resolved "git://github.com/eclipse/che#dd4219009724780c151a993efc15fdc8d5be077a"
resolved "git://github.com/eclipse/che#9c5d915d881f8413f9e2ebb713409be2ff4bb339"

editorconfig@^0.15.0:
version "0.15.3"
Expand Down

0 comments on commit 29ab89b

Please sign in to comment.