Skip to content

Commit

Permalink
feat: Support OLM all namespaces next channel. (#1751)
Browse files Browse the repository at this point in the history
* Support OLM all namespaces next channel.

Signed-off-by: Oleksandr Andriienko <[email protected]>
  • Loading branch information
AndrienkoAleksandr authored Oct 19, 2021
1 parent 603df9d commit 41ce6f4
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 105 deletions.
24 changes: 18 additions & 6 deletions src/api/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as os from 'os'
import * as path from 'path'

import { CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_OPERATOR_CR_YAML_KEY, LOG_DIRECTORY_KEY } from '../common-flags'
import { CHECTL_PROJECT_NAME, DEFAULT_CHE_NAMESPACE, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME, OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME } from '../constants'
import { CHECTL_PROJECT_NAME } from '../constants'
import { getProjectName, getProjectVersion, readCRFile } from '../util'

import { CHECTL_DEVELOPMENT_VERSION } from './version'
Expand Down Expand Up @@ -49,11 +49,6 @@ export namespace ChectlContext {
ctx.listrOptions = { renderer: (flags['listr-renderer'] as any), collapse: false } as Listr.ListrOptions
}

ctx.operatorNamespace = flags.chenamespace || DEFAULT_CHE_NAMESPACE
if (flags['olm-channel'] === OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME) {
ctx.operatorNamespace = DEFAULT_OPENSHIFT_OPERATORS_NS_NAME
}

ctx.highlightedMessages = [] as string[]
ctx[START_TIME] = Date.now()

Expand Down Expand Up @@ -89,3 +84,20 @@ export namespace DexContextKeys {
export const DEX_PASSWORD = 'dex-password'
export const DEX_PASSWORD_HASH = 'dex-password-hash'
}

export namespace OLM {
export const CHANNEL = 'olm-channel'
export const STARTING_CSV = 'starting-csv'
export const AUTO_UPDATE = 'auto-update'

// Custom catalog source
export const CATALOG_SOURCE_NAME = 'catalog-source-name'
export const CATALOG_SOURCE_NAMESPACE = 'catalog-source-namespace'
export const CATALOG_SOURCE_YAML = 'catalog-source-yaml'
export const PACKAGE_MANIFEST_NAME = 'package-manifest-name'
}

export enum OLMInstallationUpdate {
MANUAL = 'Manual',
AUTO = 'Automatic'
}
9 changes: 7 additions & 2 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as net from 'net'
import { Writable } from 'stream'
import { CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL, CHE_CLUSTER_KIND_PLURAL, CHE_CLUSTER_RESTORE_KIND_PLURAL, DEFAULT_CHE_TLS_SECRET_NAME, DEFAULT_K8S_POD_ERROR_RECHECK_TIMEOUT, DEFAULT_K8S_POD_WAIT_TIMEOUT, OLM_STABLE_CHANNEL_NAME } from '../constants'
import { base64Encode, getClusterClientCommand, getImageNameAndTag, isKubernetesPlatformFamily, newError, safeLoadFromYamlFile } from '../util'
import { ChectlContext } from './context'
import { ChectlContext, OLM } from './context'
import { V1CheClusterBackup, V1CheClusterRestore } from './types/backup-restore-crds'

import { V1Certificate } from './types/cert-manager'
Expand Down Expand Up @@ -1647,7 +1647,7 @@ export class KubeHelper {
cheClusterCR.spec.server.cheImageTag = tag
}

if ((flags.installer === 'olm' && !flags['catalog-source-yaml']) || (flags['catalog-source-yaml'] && flags['olm-channel'] === OLM_STABLE_CHANNEL_NAME)) {
if ((flags.installer === 'olm' && !flags[OLM.CATALOG_SOURCE_YAML]) || (flags[OLM.CATALOG_SOURCE_YAML] && flags[OLM.CHANNEL] === OLM_STABLE_CHANNEL_NAME)) {
// use default image tag for `olm` to install stable Che, because we don't have next channel for OLM catalog.
cheClusterCR.spec.server.cheImageTag = ''
}
Expand Down Expand Up @@ -2190,9 +2190,14 @@ export class KubeHelper {
(_phase: string, obj: any) => {
const subscription = obj as Subscription
if (subscription.status && subscription.status.conditions) {
if (subscription.status.installedCSV) {
resolve(subscription.status.installplan)
return
}
for (const condition of subscription.status.conditions) {
if (condition.type === 'InstallPlanPending' && condition.status === 'True') {
resolve(subscription.status.installplan)
return
}
}
}
Expand Down
50 changes: 25 additions & 25 deletions src/commands/server/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { boolean, string } from '@oclif/parser/lib/flags'
import { cli } from 'cli-ux'
import * as Listr from 'listr'
import * as semver from 'semver'
import { ChectlContext } from '../../api/context'
import { ChectlContext, OLM } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { batch, cheDeployment, cheDeployVersion, cheNamespace, cheOperatorCRPatchYaml, cheOperatorCRYaml, CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_OPERATOR_CR_YAML_KEY, CHE_TELEMETRY, DEPLOY_VERSION_KEY, k8sPodDownloadImageTimeout, K8SPODDOWNLOADIMAGETIMEOUT_KEY, k8sPodErrorRecheckTimeout, K8SPODERRORRECHECKTIMEOUT_KEY, k8sPodReadyTimeout, K8SPODREADYTIMEOUT_KEY, k8sPodWaitTimeout, K8SPODWAITTIMEOUT_KEY, listrRenderer, logsDirectory, LOG_DIRECTORY_KEY, skipKubeHealthzCheck as skipK8sHealthCheck } from '../../common-flags'
import { DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_CHE_NAMESPACE, DEFAULT_OLM_SUGGESTED_NAMESPACE, DOCS_LINK_INSTALL_RUNNING_CHE_LOCALLY, MIN_CHE_OPERATOR_INSTALLER_VERSION, MIN_HELM_INSTALLER_VERSION, MIN_OLM_INSTALLER_VERSION, OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME } from '../../constants'
Expand Down Expand Up @@ -263,47 +263,47 @@ export default class Deploy extends Command {
this.error(`🛑 The specified installer ${flags.installer} does not support Minishift`)
}

if (flags['olm-channel'] === OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME && isKubernetesPlatformFamily(flags.platform)) {
if (flags[OLM.CHANNEL] === OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME && isKubernetesPlatformFamily(flags.platform)) {
this.error('"stable-all-namespaces" channel is supported only in "openshift" platform')
}

if (flags['catalog-source-name'] && flags['catalog-source-yaml']) {
this.error('should be provided only one argument: "catalog-source-name" or "catalog-source-yaml"')
if (flags[OLM.CATALOG_SOURCE_NAME] && flags[OLM.CATALOG_SOURCE_YAML]) {
this.error(`should be provided only one argument: "${OLM.CATALOG_SOURCE_NAME}" or "${OLM.CATALOG_SOURCE_YAML}"`)
}
if (flags.version) {
if (flags['starting-csv']) {
this.error('"starting-csv" and "version" flags are mutually exclusive. Please specify only one of them.')
if (flags[OLM.STARTING_CSV]) {
this.error(`"${OLM.STARTING_CSV}" and "version" flags are mutually exclusive. Please specify only one of them.`)
}
if (flags['auto-update']) {
this.error('enabled "auto-update" flag cannot be used with version flag. Deploy latest version instead.')
if (flags[OLM.AUTO_UPDATE]) {
this.error(`enabled "${OLM.AUTO_UPDATE}" flag cannot be used with version flag. Deploy latest version instead.`)
}
}

if (!flags['package-manifest-name'] && flags['catalog-source-yaml']) {
this.error('you need to define "package-manifest-name" flag to use "catalog-source-yaml".')
if (!flags[OLM.PACKAGE_MANIFEST_NAME] && flags[OLM.CATALOG_SOURCE_YAML]) {
this.error(`you need to define "${OLM.PACKAGE_MANIFEST_NAME}" flag to use "${OLM.CATALOG_SOURCE_YAML}".`)
}
if (!flags['olm-channel'] && flags['catalog-source-yaml']) {
this.error('you need to define "olm-channel" flag to use "catalog-source-yaml".')
if (!flags[OLM.CHANNEL] && flags[OLM.CATALOG_SOURCE_YAML]) {
this.error(`you need to define "${OLM.CHANNEL}" flag to use "${OLM.CATALOG_SOURCE_YAML}".`)
}
} else {
// Not OLM installer
if (flags['starting-csv']) {
this.error('"starting-csv" flag should be used only with "olm" installer.')
if (flags[OLM.STARTING_CSV]) {
this.error(`"${OLM.STARTING_CSV}" flag should be used only with "olm" installer.`)
}
if (flags['catalog-source-yaml']) {
this.error('"catalog-source-yaml" flag should be used only with "olm" installer.')
if (flags[OLM.CATALOG_SOURCE_YAML]) {
this.error(`"${OLM.CATALOG_SOURCE_YAML}" flag should be used only with "olm" installer.`)
}
if (flags['olm-channel']) {
this.error('"olm-channel" flag should be used only with "olm" installer.')
if (flags[OLM.CHANNEL]) {
this.error(`"${OLM.CHANNEL}" flag should be used only with "olm" installer.`)
}
if (flags['package-manifest-name']) {
this.error('"package-manifest-name" flag should be used only with "olm" installer.')
if (flags[OLM.PACKAGE_MANIFEST_NAME]) {
this.error(`"${OLM.PACKAGE_MANIFEST_NAME}" flag should be used only with "olm" installer.`)
}
if (flags['catalog-source-name']) {
this.error('"catalog-source-name" flag should be used only with "olm" installer.')
if (flags[OLM.CATALOG_SOURCE_NAME]) {
this.error(`"${OLM.CATALOG_SOURCE_NAME}" flag should be used only with "olm" installer.`)
}
if (flags['catalog-source-namespace']) {
this.error('"package-manifest-name" flag should be used only with "olm" installer.')
if (flags[OLM.CATALOG_SOURCE_NAMESPACE]) {
this.error(`"${OLM.CATALOG_SOURCE_NAMESPACE}" flag should be used only with "olm" installer.`)
}
if (flags['cluster-monitoring'] && flags.platform !== 'openshift') {
this.error('"cluster-monitoring" flag should be used only with "olm" installer and "openshift" platform.')
Expand Down Expand Up @@ -452,7 +452,7 @@ export async function setDefaultInstaller(flags: any): Promise<void> {
const kubeHelper = new KubeHelper(flags)

const isOlmPreinstalled = await kubeHelper.isPreInstalledOLM()
if ((flags['catalog-source-name'] || flags['catalog-source-yaml']) && isOlmPreinstalled) {
if ((flags[OLM.CATALOG_SOURCE_NAME] || flags[OLM.CATALOG_SOURCE_YAML]) && isOlmPreinstalled) {
flags.installer = 'olm'
return
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/server/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as Listr from 'listr'

import { CHE_BACKUP_SERVER_CONFIG_KIND_PLURAL, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL, CHE_CLUSTER_RESTORE_KIND_PLURAL, DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME, OPERATOR_DEPLOYMENT_NAME } from '../../constants'
import { batch, CHE_TELEMETRY, listrRenderer } from '../../common-flags'
import { ChectlContext } from '../../api/context'
import { ChectlContext, OLM } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { CheHelper } from '../../api/che'
import { cheNamespace } from '../../common-flags'
Expand Down Expand Up @@ -171,7 +171,7 @@ export default class Restore extends Command {
}

if (flags.installer === 'olm') {
if (!flags['olm-channel']) {
if (!flags[OLM.CHANNEL]) {
throw new Error('Cannot detect OLM channel automatically, provide --olm-channel flag')
}
task.title = `${task.title}OLM`
Expand All @@ -185,7 +185,7 @@ export default class Restore extends Command {
if (subscription) {
// OLM
flags.installer = 'olm'
flags['olm-channel'] = subscription.spec.channel
flags[OLM.CHANNEL] = subscription.spec.channel
task.title = `${task.title}OLM`
return
}
Expand Down
20 changes: 13 additions & 7 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,28 @@ export const CHE_OPERATOR_SELECTOR = 'app=che-operator'
export const DEFAULT_CHE_NAMESPACE = 'eclipse-che'
export const LEGACY_CHE_NAMESPACE = 'che'

// OLM
// OLM common
export const DEFAULT_CHE_OLM_PACKAGE_NAME = 'eclipse-che'
export const DEFAULT_CHE_OPERATOR_SUBSCRIPTION_NAME = 'eclipse-che-subscription'
export const DEVWORKSPACE_OPERATOR_SUBSRIPTION_NAME = 'devworkspace-operator-fast-redhat-operators-openshift-marketplace'
export const OPERATOR_GROUP_NAME = 'che-operator-group'
export const CVS_PREFIX = 'eclipse-che'
export const DEVWORKSPACE_CVS_PREFIX = 'devworkspace-operator'
// OLM channels
export const OLM_STABLE_CHANNEL_NAME = 'stable'
export const OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME = 'tech-preview-stable-all-namespaces'
export const OLM_NEXT_CHANNEL_NAME = 'next'
export const OLM_NEXT_ALL_NAMESPACES_CHANNEL_NAME = 'next-all-namespaces'
// OLM namespaces
export const DEFAULT_OPENSHIFT_MARKET_PLACE_NAMESPACE = 'openshift-marketplace'
export const DEFAULT_OLM_KUBERNETES_NAMESPACE = 'olm'
export const DEFAULT_OPENSHIFT_OPERATORS_NS_NAME = 'openshift-operators'
// OLM catalogs
export const CUSTOM_CATALOG_SOURCE_NAME = 'eclipse-che-custom-catalog-source'
export const DEFAULT_CHE_OPERATOR_SUBSCRIPTION_NAME = 'eclipse-che-subscription'
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 NEXT_CATALOG_SOURCE_NAME = 'eclipse-che-preview'
export const DEFAULT_OLM_SUGGESTED_NAMESPACE = 'eclipse-che'
export const DEFAULT_OPENSHIFT_OPERATORS_NS_NAME = 'openshift-operators'
export const KUBERNETES_OLM_CATALOG = 'operatorhubio-catalog'
export const OPENSHIFT_OLM_CATALOG = 'community-operators'

// Documentation links
export const DOC_LINK = 'https://www.eclipse.org/che/docs/'
Expand Down
Loading

0 comments on commit 41ce6f4

Please sign in to comment.