From ac0324de6264df6eafb2233997f83f7cdd184667 Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Thu, 27 May 2021 14:56:58 +0300 Subject: [PATCH] Fix Che update when backup/restore CRDs don't exist Signed-off-by: Mykola Morhun --- src/tasks/installers/operator.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/tasks/installers/operator.ts b/src/tasks/installers/operator.ts index e9ad0b981..c45110b84 100644 --- a/src/tasks/installers/operator.ts +++ b/src/tasks/installers/operator.ts @@ -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.` } } },