Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use operator namespace to get checluster CR from a csv #1733

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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