Skip to content

Commit

Permalink
Fix Che update when backup/restore CRDs don't exist
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <[email protected]>
  • Loading branch information
mmorhun committed May 27, 2021
1 parent 1293076 commit ac0324d
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/tasks/installers/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,26 +386,32 @@ export class OperatorTasks {
task: async (ctx: any, task: any) => {
const existedBackupCRD = await kube.getCrd(this.cheClusterBackupCrd)
const newBackupCRDPath = path.join(ctx.resourcesPath, 'crds', 'org.eclipse.che_checlusterbackups_crd.yaml')
if (existedBackupCRD) {
if (!existedBackupCRD.metadata || !existedBackupCRD.metadata.resourceVersion) {
throw new Error(`Fetched CRD ${this.cheClusterBackupCrd} without resource version`)
if (fs.existsSync(newBackupCRDPath)) {
if (existedBackupCRD) {
if (!existedBackupCRD.metadata || !existedBackupCRD.metadata.resourceVersion) {
throw new Error(`Fetched CRD ${this.cheClusterBackupCrd} without resource version`)
}
await kube.replaceCrdFromFile(newBackupCRDPath, existedBackupCRD.metadata.resourceVersion)
} else {
await kube.createCrdFromFile(newBackupCRDPath)
}
await kube.replaceCrdFromFile(newBackupCRDPath, existedBackupCRD.metadata.resourceVersion)
} else {
await kube.createCrdFromFile(newBackupCRDPath)
}

const existedRestoreCRD = await kube.getCrd(this.cheClusterRestoreCrd)
const newRestoreCRDPath = path.join(ctx.resourcesPath, 'crds', 'org.eclipse.che_checlusterrestores_crd.yaml')
if (existedRestoreCRD) {
if (!existedRestoreCRD.metadata || !existedRestoreCRD.metadata.resourceVersion) {
throw new Error(`Fetched CRD ${this.cheClusterRestoreCrd} without resource version`)
if (fs.existsSync(newRestoreCRDPath)) {
if (existedRestoreCRD) {
if (!existedRestoreCRD.metadata || !existedRestoreCRD.metadata.resourceVersion) {
throw new Error(`Fetched CRD ${this.cheClusterRestoreCrd} without resource version`)
}
await kube.replaceCrdFromFile(newRestoreCRDPath, existedRestoreCRD.metadata.resourceVersion)
task.title = `${task.title}...updated.`
} else {
await kube.createCrdFromFile(newRestoreCRDPath)
task.title = `${task.title}...created new one.`
}
await kube.replaceCrdFromFile(newRestoreCRDPath, existedRestoreCRD.metadata.resourceVersion)
task.title = `${task.title}...updated.`
} else {
await kube.createCrdFromFile(newRestoreCRDPath)
task.title = `${task.title}...created new one.`
task.title = `${task.title}...skipped.`
}
}
},
Expand Down

0 comments on commit ac0324d

Please sign in to comment.