Skip to content

Commit

Permalink
Changes after rebasing conflicting files
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun committed Sep 23, 2021
1 parent 452b509 commit b25b0ea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/api/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export class CheHelper {
}
}

async findCheSubscription(namespace: string): Promise<Subscription | undefined> {
async findCheOperatorSubscription(namespace: string): Promise<Subscription | undefined> {
try {
const subscriptions = await this.kube.listOperatorSubscriptions(namespace)
const cheSubscriptions = subscriptions.filter(subscription => subscription.spec.name && subscription.spec.name.includes(DEFAULT_CHE_OLM_PACKAGE_NAME))
Expand All @@ -563,7 +563,7 @@ export class CheHelper {
}
// No subscriptions found, check if Che is installed in all namespaces mode
if (namespace !== DEFAULT_OPENSHIFT_OPERATORS_NS_NAME) {
return this.findCheSubscription(DEFAULT_OPENSHIFT_OPERATORS_NS_NAME)
return this.findCheOperatorSubscription(DEFAULT_OPENSHIFT_OPERATORS_NS_NAME)
}
} catch {
// Do nothing, just return undefined
Expand Down
31 changes: 11 additions & 20 deletions src/commands/server/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { Command, flags } from '@oclif/command'
import { boolean, string } from '@oclif/parser/lib/flags'
import * as Listr from 'listr'

import { 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, OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME, OLM_STABLE_CHANNEL_NAME, OPERATOR_DEPLOYMENT_NAME, SUBSCRIPTION_NAME } from '../../constants'
import { 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, OLM_STABLE_CHANNEL_NAME, OPERATOR_DEPLOYMENT_NAME } from '../../constants'
import { ChectlContext } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { CheHelper } from '../../api/che'
import { cheNamespace } from '../../common-flags'
import { requestRestore } from '../../api/backup-restore'
import { cli } from 'cli-ux'
Expand Down Expand Up @@ -113,6 +114,7 @@ export default class Restore extends Command {

private getRestoreTasks(flags: any): Listr.ListrTask[] {
const kube = new KubeHelper(flags)
const che = new CheHelper(flags)
return [
{
title: 'Detecting existing operator version...',
Expand Down Expand Up @@ -147,30 +149,19 @@ export default class Restore extends Command {
if (!ctx.isOperatorDeployed) {
setDefaultInstaller(flags)
if (flags.installer === 'olm') {
if (await kube.operatorSubscriptionExists(SUBSCRIPTION_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME)) {
flags['olm-channel'] = OLM_STABLE_ALL_NAMESPACES_CHANNEL_NAME
} else {
flags['olm-channel'] = OLM_STABLE_CHANNEL_NAME
}
flags['olm-channel'] = OLM_STABLE_CHANNEL_NAME
task.title = `${task.title}OLM`
} else {
task.title = `${task.title}Operator`
}
task.title = `${task.title}${flags.installer}`
return
}

if (await kube.operatorSubscriptionExists(SUBSCRIPTION_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME)) {
// OLM in all namespaces mode
const operatorSubscriptionYaml = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, DEFAULT_OPENSHIFT_OPERATORS_NS_NAME)
const subscription = await che.findCheOperatorSubscription(flags.chenamespace)
if (subscription) {
// OLM
flags.installer = 'olm'
flags['olm-channel'] = operatorSubscriptionYaml.spec.channel
task.title = `${task.title}OLM`
return
}

if (await kube.operatorSubscriptionExists(SUBSCRIPTION_NAME, flags.chenamespace)) {
// OLM in single namespace mode
const operatorSubscriptionYaml = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, flags.chenamespace)
flags.installer = 'olm'
flags['olm-channel'] = operatorSubscriptionYaml.spec.channel
flags['olm-channel'] = subscription.spec.channel
task.title = `${task.title}OLM`
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export default class Update extends Command {
*/
private async setDefaultInstaller(flags: any): Promise<void> {
const cheHelper = new CheHelper(flags)
if (await cheHelper.findCheSubscription(flags.chenamespace)) {
if (await cheHelper.findCheOperatorSubscription(flags.chenamespace)) {
flags.installer = 'olm'
} else {
flags.installer = 'operator'
Expand Down
8 changes: 4 additions & 4 deletions src/tasks/installers/olm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class OLMTasks {
{
title: 'Create operator subscription',
task: async (ctx: any, task: any) => {
let subscription = await che.findCheSubscription(ctx.operatorNamespace)
let subscription = await che.findCheOperatorSubscription(ctx.operatorNamespace)
if (subscription) {
ctx.subscriptionName = subscription.metadata.name
task.title = `${task.title}...It already exists.`
Expand Down Expand Up @@ -252,7 +252,7 @@ export class OLMTasks {
{
title: 'Check if operator subscription exists',
task: async (ctx: any, task: any) => {
if (!await che.findCheSubscription(ctx.operatorNamespace)) {
if (!await che.findCheOperatorSubscription(ctx.operatorNamespace)) {
command.error('Unable to find operator subscription')
}
task.title = `${task.title}...done.`
Expand All @@ -269,7 +269,7 @@ export class OLMTasks {
title: 'Get operator installation plan',
task: async (ctx: any, task: any) => {
// We can be sure that the subscription exist, because it was checked in preupdate tasks
const subscription: Subscription = (await che.findCheSubscription(ctx.operatorNamespace))!
const subscription: Subscription = (await che.findCheOperatorSubscription(ctx.operatorNamespace))!

if (subscription.status) {
if (subscription.status.state === 'AtLatestKnown') {
Expand Down Expand Up @@ -336,7 +336,7 @@ export class OLMTasks {
{
title: 'Check if operator is installed',
task: async (ctx: any, task: any) => {
const subscription = await che.findCheSubscription(flags.chenamespace || DEFAULT_CHE_NAMESPACE)
const subscription = await che.findCheOperatorSubscription(flags.chenamespace || DEFAULT_CHE_NAMESPACE)
if (subscription) {
ctx.subscriptionName = subscription.metadata.name
ctx.operatorNamespace = subscription.metadata.namespace
Expand Down

0 comments on commit b25b0ea

Please sign in to comment.