Skip to content

Commit

Permalink
chore: Update CRD before deletion in 2 steps (#2930)
Browse files Browse the repository at this point in the history
* chore: Update CRD before deletion in 2 steps

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha authored Sep 10, 2024
1 parent 82dfd2c commit ed3a4c8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/api/kube-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ export class KubeClient {
const k8sApi = this.kubeConfig.makeApiClient(ApiextensionsV1Api)
try {
const response = await k8sApi.readCustomResourceDefinition(crd.metadata!.name!)

crd.metadata!.resourceVersion = (response.body as any).metadata.resourceVersion
await k8sApi.replaceCustomResourceDefinition(crd.metadata!.name!, crd)
} catch (e: any) {
Expand Down Expand Up @@ -1096,11 +1097,12 @@ export class KubeClient {
return
}

crd = await this.getCustomResourceDefinition(crdName)
// 1. Disable conversion webhook
crd.spec.conversion = null
await this.replaceCustomResourceDefinition(crd)

// 2. Patch CRD to unblock potential invalid resource
// 2. Patch CRD to unblock potential invalid resource error
crd = await this.getCustomResourceDefinition(crdName)
for (let i = 0; i < crd.spec.versions.length; i++) {
if (crd.spec.versions[i].schema?.openAPIV3Schema?.properties?.spec) {
crd.spec.versions[i].schema.openAPIV3Schema.properties.spec = {type: 'object', properties: {}}
Expand Down

0 comments on commit ed3a4c8

Please sign in to comment.