Skip to content

Commit

Permalink
fix: use operator namespace to find subscription
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Oct 4, 2021
1 parent 7e8cc32 commit 8ec3ad0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2008,13 +2008,15 @@ export class KubeHelper {
}
}

async getOperatorSubscription(name: string, namespace: string): Promise<Subscription> {
async getOperatorSubscription(name: string, namespace: string): Promise<Subscription | undefined> {
const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi)
try {
const { body } = await customObjectsApi.getNamespacedCustomObject('operators.coreos.com', 'v1alpha1', namespace, 'subscriptions', name)
return body as Subscription
} catch (e) {
throw this.wrapK8sClientError(e)
if (e.response.statusCode !== 404) {
throw this.wrapK8sClientError(e)
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { cli } from 'cli-ux'
import * as Listr from 'listr'
import { merge } from 'lodash'
import * as semver from 'semver'

import { ChectlContext } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { assumeYes, batch, cheDeployment, cheDeployVersion, cheNamespace, cheOperatorCRPatchYaml, CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_TELEMETRY, DEPLOY_VERSION_KEY, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
Expand Down Expand Up @@ -378,8 +377,11 @@ export default class Update extends Command {
private async setDefaultInstaller(flags: any): Promise<void> {
const kubeHelper = new KubeHelper(flags)
try {
await kubeHelper.getOperatorSubscription(SUBSCRIPTION_NAME, flags.chenamespace)
flags.installer = 'olm'
if (await kubeHelper.getOperatorSubscription(SUBSCRIPTION_NAME, flags.chenamespace)) {
flags.installer = 'olm'
} else {
flags.installer = 'operator'
}
} catch {
flags.installer = 'operator'
}
Expand Down
17 changes: 12 additions & 5 deletions src/tasks/installers/olm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class OLMTasks {
}

if (!ctx.customCR) {
ctx.defaultCR = await this.getCRFromCSV(kube, flags.chenamespace)
ctx.defaultCR = await this.getCRFromCSV(kube, ctx.operatorNamespace)
}

task.title = `${task.title}...Done.`
Expand Down Expand Up @@ -255,7 +255,10 @@ export class OLMTasks {
{
title: 'Get operator installation plan',
task: async (ctx: any, task: any) => {
const subscription: Subscription = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, ctx.operatorNamespace)
const subscription = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, ctx.operatorNamespace)
if (!subscription) {
throw new Error(`Subscription '${SUBSCRIPTION_NAME}' not found in namespace '${ctx.operatorNamespace}'.`)
}

if (subscription.status) {
if (subscription.status.state === 'AtLatestKnown') {
Expand Down Expand Up @@ -440,10 +443,14 @@ export class OLMTasks {
}
}

private async getCRFromCSV(kube: KubeHelper, cheNamespace: string): Promise<any> {
const subscription: Subscription = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, cheNamespace)
private async getCRFromCSV(kube: KubeHelper, namespace: string): Promise<any> {
const subscription = await kube.getOperatorSubscription(SUBSCRIPTION_NAME, namespace)
if (!subscription) {
throw new Error(`Subscription '${SUBSCRIPTION_NAME}' not found in namespace '${namespace}'.`)
}

const currentCSV = subscription.status!.currentCSV
const csv = await kube.getCSV(currentCSV, cheNamespace)
const csv = await kube.getCSV(currentCSV, namespace)
if (csv && csv.metadata.annotations) {
const CRRaw = csv.metadata.annotations!['alm-examples']
return (yaml.load(CRRaw) as Array<any>).find(cr => cr.kind === 'CheCluster')
Expand Down

0 comments on commit 8ec3ad0

Please sign in to comment.