From f8acd58c2fb265bed3c8a1e3fc7a20ab04a46551 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Mon, 4 Oct 2021 14:55:20 +0300 Subject: [PATCH] fix: use operator namespace to get checluster CR from a csv (#1733) Signed-off-by: Anatolii Bazko --- src/api/kube.ts | 6 ++++-- src/tasks/installers/olm.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/api/kube.ts b/src/api/kube.ts index 730de3c7c..b89e10610 100644 --- a/src/api/kube.ts +++ b/src/api/kube.ts @@ -2051,13 +2051,15 @@ export class KubeHelper { } } - async getOperatorSubscription(name: string, namespace: string): Promise { + async getOperatorSubscription(name: string, namespace: string): Promise { 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) + } } } diff --git a/src/tasks/installers/olm.ts b/src/tasks/installers/olm.ts index 6fe58ecd9..929f612d6 100644 --- a/src/tasks/installers/olm.ts +++ b/src/tasks/installers/olm.ts @@ -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.` @@ -474,10 +474,13 @@ export class OLMTasks { } } - private async getCRFromCSV(kube: KubeHelper, cheNamespace: string, subscriptionName: string): Promise { - const subscription: Subscription = await kube.getOperatorSubscription(subscriptionName, cheNamespace) + private async getCRFromCSV(kube: KubeHelper, namespace: string, subscriptionName: string): Promise { + 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).find(cr => cr.kind === 'CheCluster')