Skip to content

Commit

Permalink
fix: use operator namespace to get checluster CR from a csv (#1733)
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 50a899d commit f8acd58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2051,13 +2051,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
11 changes: 7 additions & 4 deletions src/tasks/installers/olm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class OLMTasks {
}

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

task.title = `${task.title}...Done.`
Expand Down Expand Up @@ -474,10 +474,13 @@ export class OLMTasks {
}
}

private async getCRFromCSV(kube: KubeHelper, cheNamespace: string, subscriptionName: string): Promise<any> {
const subscription: Subscription = await kube.getOperatorSubscription(subscriptionName, cheNamespace)
private async getCRFromCSV(kube: KubeHelper, namespace: string, subscriptionName: string): Promise<any> {
const subscription = await kube.getOperatorSubscription(subscriptionName, namespace)
if (!subscription) {
throw new Error(`Subscription '${subscriptionName}' 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 f8acd58

Please sign in to comment.