Skip to content

Commit

Permalink
Fixes for all namespaces mode
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <[email protected]>
  • Loading branch information
mmorhun committed Sep 21, 2021
1 parent 95c33c2 commit d6e8cf3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/commands/server/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ export default class Restore extends Command {
const backupCrName = 'backup-before-update-to-' + currentOperatorVersion.replace(/\./g, '-')

const kube = new KubeHelper(flags)
const backupCr = await kube.getCustomResource(flags.chenamespace, backupCrName, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL)
const backupCr: V1CheClusterBackup = await kube.getCustomResource(flags.chenamespace, backupCrName, CHE_CLUSTER_API_GROUP, CHE_CLUSTER_API_VERSION, CHE_CLUSTER_BACKUP_KIND_PLURAL)
if (!backupCr) {
throw new Error(`Cannot find backup: ${backupCrName}`)
}
if (!backupCr.status || backupCr.status.state !== 'Succeeded') {
throw new Error(`Backup with name '${backupCrName}' is not successful`)
}
flags['backup-cr'] = backupCrName
task.title = `${task.title} ${backupCrName} found`
},
Expand Down
5 changes: 2 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ export const LEGACY_CHE_NAMESPACE = 'che'
// OLM
export const DEFAULT_CHE_OLM_PACKAGE_NAME = 'eclipse-che'
export const OLM_STABLE_CHANNEL_NAME = 'stable'
export const OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME = 'stable-all-namespaces'
export const OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME = 'tech-preview-stable-all-namespaces'
export const OLM_NEXT_CHANNEL_NAME = 'next'
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'
// export const SUBSCRIPTION_NAME = 'eclipse-che-subscription'
export const SUBSCRIPTION_NAME = 'eclipse-che-preview-openshift'
export const 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'
Expand Down
30 changes: 25 additions & 5 deletions src/tasks/installers/olm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ export class OLMTasks {
// Convert version flag to channel (see subscription object), starting CSV and approval starategy
flags.version = VersionHelper.removeVPrefix(flags.version, true)
// Need to point to specific CSV
ctx.startingCSV = `eclipse-che.v${flags.version}`
if (flags['starting-csv']) {
ctx.startingCSV = flags['starting-csv']
} else if (flags['olm-channel'] === OLM_STABLE_CHANNEL_NAME) {
ctx.startingCSV = `eclipse-che.v${flags.version}`
} else if (flags['olm-channel'] === OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME) {
ctx.startingCSV = `eclipse-che-preview-openshift.v${flags.version}-all-namespaces`
} // else use latest in the channel
// Set approval starategy to manual to prevent autoupdate to the latest version right before installation
ctx.approvalStarategy = 'Manual'
} else {
Expand Down Expand Up @@ -152,11 +158,11 @@ export class OLMTasks {
// custom Che CatalogSource
const catalogSourceNamespace = flags['catalog-source-namespace'] || ctx.operatorNamespace
subscription = this.constructSubscription(SUBSCRIPTION_NAME, flags['package-manifest-name'], ctx.operatorNamespace, catalogSourceNamespace, flags['olm-channel'], ctx.sourceName, ctx.approvalStarategy, ctx.startingCSV)
} else if (VersionHelper.isDeployingStableVersion(flags) || flags['olm-channel'] === OLM_STABLE_CHANNEL_NAME) {
} else if (flags['olm-channel'] === OLM_STABLE_CHANNEL_NAME || (VersionHelper.isDeployingStableVersion(flags) && !flags['olm-channel'])) {
// stable Che CatalogSource
subscription = this.constructSubscription(SUBSCRIPTION_NAME, DEFAULT_CHE_OLM_PACKAGE_NAME, ctx.operatorNamespace, ctx.defaultCatalogSourceNamespace, OLM_STABLE_CHANNEL_NAME, ctx.catalogSourceNameStable, ctx.approvalStarategy, ctx.startingCSV)
} else if (flags['olm-channel'] === OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME) {
// stable Che CatalogSource
// stable all namespaces Che CatalogSource
subscription = this.constructSubscription(SUBSCRIPTION_NAME, DEFAULT_CHE_OLM_PACKAGE_NAME, ctx.operatorNamespace, ctx.defaultCatalogSourceNamespace, OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME, ctx.catalogSourceNameStable, ctx.approvalStarategy, ctx.startingCSV)
} else {
// next Che CatalogSource
Expand Down Expand Up @@ -338,19 +344,33 @@ export class OLMTasks {
task.title = `${task.title}...OK`
},
},
{
title: `Delete(OLM) Eclipse Che cluster service versions for all namespaces mode`,
enabled: ctx => ctx.isPreInstalledOLM && flags.chenamespace !== ctx.operatorNamespace,
task: async (ctx: any, task: any) => {
const csvs = await kube.getClusterServiceVersions(ctx.operatorNamespace)
const csvsToDelete = csvs.items.filter(csv => csv.metadata.name!.startsWith(CVS_PREFIX))
for (const csv of csvsToDelete) {
await kube.deleteClusterServiceVersion(ctx.operatorNamespace, csv.metadata.name!)
}
task.title = `${task.title}...OK`
},
},
{
title: 'Delete(OLM) Eclipse Che cluster service versions',
enabled: ctx => ctx.isPreInstalledOLM,
task: async (_ctx: any, task: any) => {
const csvs = await kube.getClusterServiceVersions(flags.chenamespace)
const csvsToDelete = csvs.items.filter(csv => csv.metadata.name!.startsWith(CVS_PREFIX))
csvsToDelete.forEach(csv => kube.deleteClusterServiceVersion(flags.chenamespace, csv.metadata.name!))
for (const csv of csvsToDelete) {
await kube.deleteClusterServiceVersion(flags.chenamespace, csv.metadata.name!)
}
task.title = `${task.title}...OK`
},
},
{
title: `Delete(OLM) operator group ${OPERATOR_GROUP_NAME}`,
enabled: ctx => ctx.isPreInstalledOLM,
enabled: ctx => ctx.isPreInstalledOLM && ctx.operatorNamespace !== DEFAULT_OPENSHIFT_OPERATORS_NS_NAME,
task: async (ctx: any, task: any) => {
await kube.deleteOperatorGroup(OPERATOR_GROUP_NAME, ctx.operatorNamespace)
task.title = `${task.title}...OK`
Expand Down

0 comments on commit d6e8cf3

Please sign in to comment.