Skip to content

Commit

Permalink
Use CRDs of v1beta1 version on Openshift 3.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <[email protected]>
  • Loading branch information
mmorhun committed Jun 3, 2021
1 parent b1a1ca3 commit 2d89f13
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/tasks/installers/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ export class OperatorTasks {
return
}

const backupCrdPath = path.join(ctx.resourcesPath, 'crds', 'org.eclipse.che_checlusterbackups_crd.yaml')
const [backupCrdFileName, restoreCrdFileName] = await this.getBackupRestoreCrdFilesNames(kube)
const backupCrdPath = path.join(ctx.resourcesPath, 'crds', backupCrdFileName)
if (!backupCrdExist && fs.existsSync(backupCrdPath)) {
await kube.createCrdFromFile(backupCrdPath)
}

const restoreCrdPath = path.join(ctx.resourcesPath, 'crds', 'org.eclipse.che_checlusterrestores_crd.yaml')
const restoreCrdPath = path.join(ctx.resourcesPath, 'crds', restoreCrdFileName)
if (!restoreCrdExist && fs.existsSync(restoreCrdPath)) {
await kube.createCrdFromFile(restoreCrdPath)
}
Expand Down Expand Up @@ -382,8 +383,9 @@ export class OperatorTasks {
{
title: 'Updating backup and restore CRDs',
task: async (ctx: any, task: any) => {
const [backupCrdFileName, restoreCrdFileName] = await this.getBackupRestoreCrdFilesNames(kube)
const existedBackupCRD = await kube.getCrd(this.cheClusterBackupCrd)
const newBackupCRDPath = path.join(ctx.resourcesPath, 'crds', 'org.eclipse.che_checlusterbackups_crd.yaml')
const newBackupCRDPath = path.join(ctx.resourcesPath, 'crds', backupCrdFileName)
if (fs.existsSync(newBackupCRDPath)) {
if (existedBackupCRD) {
if (!existedBackupCRD.metadata || !existedBackupCRD.metadata.resourceVersion) {
Expand All @@ -396,7 +398,7 @@ export class OperatorTasks {
}

const existedRestoreCRD = await kube.getCrd(this.cheClusterRestoreCrd)
const newRestoreCRDPath = path.join(ctx.resourcesPath, 'crds', 'org.eclipse.che_checlusterrestores_crd.yaml')
const newRestoreCRDPath = path.join(ctx.resourcesPath, 'crds', restoreCrdFileName)
if (fs.existsSync(newRestoreCRDPath)) {
if (existedRestoreCRD) {
if (!existedRestoreCRD.metadata || !existedRestoreCRD.metadata.resourceVersion) {
Expand Down Expand Up @@ -652,6 +654,21 @@ export class OperatorTasks {
return path.join(ctx.resourcesPath, 'crds', 'org_v1_che_crd.yaml')
}

// Delete this method and use default v1 CRDs when Openshift 3.x support dropped
private async getBackupRestoreCrdFilesNames(kube: KubeHelper): Promise<[string, string]> {
let backupCrdFileName: string
let restoreCrdFileName: string
if (! await kube.IsAPIExtensionSupported('v1')) {
// Needed for Openshift 3.x
backupCrdFileName = 'org.eclipse.che_checlusterbackups_crd-v1beta1.yaml'
restoreCrdFileName = 'org.eclipse.che_checlusterrestores_crd-v1beta1.yaml'
} else {
backupCrdFileName = 'org.eclipse.che_checlusterbackups_crd.yaml'
restoreCrdFileName = 'org.eclipse.che_checlusterrestores_crd.yaml'
}
return [backupCrdFileName, restoreCrdFileName]
}

/**
* Reads and patch 'che-operator' deployment:
* - sets operator image
Expand Down

0 comments on commit 2d89f13

Please sign in to comment.