diff --git a/src/tasks/installers/operator.ts b/src/tasks/installers/operator.ts index 19ae69437..326aa1f4a 100644 --- a/src/tasks/installers/operator.ts +++ b/src/tasks/installers/operator.ts @@ -174,35 +174,17 @@ export class OperatorTasks { }, this.getCreateOrUpdateRolesAndBindingsTasks(false), { - title: `Create CRD ${CHE_CLUSTER_CRD}`, - task: async (ctx: any, task: any) => { - const existedCRD = await this.kh.getCrd(CHE_CLUSTER_CRD) - if (existedCRD) { - task.title = `${task.title}...[Exists]]` - } else { - const newCRDPath = await this.getCRDPath() - await this.kh.createCrdFromFile(newCRDPath) - task.title = `${task.title}...[OK: created]` - } - }, - }, - { - title: 'Waiting 5 seconds for the new Kubernetes resources to get flushed', - task: async (_ctx: any, task: any) => { - await cli.wait(5000) - task.title = `${task.title}...[OK]` - }, - }, - { - title: `Create Webhook Service ${OperatorTasks.WEBHOOK_SERVICE}`, + title: `Create Certificate ${OperatorTasks.CERTIFICATE}`, + enabled: ctx => !ctx[ChectlContext.IS_OPENSHIFT], task: async (ctx: any, task: any) => { - const exists = await this.kh.isServiceExists(OperatorTasks.WEBHOOK_SERVICE, this.flags.chenamespace) + const exists = await this.kh.isCertificateExists(OperatorTasks.CERTIFICATE, this.flags.chenamespace) if (exists) { task.title = `${task.title}...[Exists]]` } else { - const yamlFilePath = this.getResourcePath('webhook-service.yaml') + const yamlFilePath = this.getResourcePath('serving-cert.yaml') if (fs.existsSync(yamlFilePath)) { - await this.kh.createServiceFromFile(yamlFilePath, this.flags.chenamespace) + const certificate = yaml.load(fs.readFileSync(yamlFilePath).toString()) as V1Certificate + await this.kh.createCertificate(certificate, this.flags.chenamespace) task.title = `${task.title}...[OK: created]` } else { task.title = `${task.title}...[Skipped: Not found]` @@ -211,17 +193,17 @@ export class OperatorTasks { }, }, { - title: `Create Certificate ${OperatorTasks.CERTIFICATE}`, + title: `Create Issuer ${OperatorTasks.ISSUER}`, enabled: ctx => !ctx[ChectlContext.IS_OPENSHIFT], task: async (ctx: any, task: any) => { - const exists = await this.kh.isCertificateExists(OperatorTasks.CERTIFICATE, this.flags.chenamespace) + const exists = await this.kh.isIssuerExists(OperatorTasks.ISSUER, this.flags.chenamespace) if (exists) { task.title = `${task.title}...[Exists]]` } else { - const yamlFilePath = this.getResourcePath('serving-cert.yaml') + const yamlFilePath = this.getResourcePath('selfsigned-issuer.yaml') if (fs.existsSync(yamlFilePath)) { - const certificate = yaml.load(fs.readFileSync(yamlFilePath).toString()) as V1Certificate - await this.kh.createCertificate(certificate, this.flags.chenamespace) + const issuer = yaml.load(fs.readFileSync(yamlFilePath).toString()) + await this.kh.createIssuer(issuer, this.flags.chenamespace) task.title = `${task.title}...[OK: created]` } else { task.title = `${task.title}...[Skipped: Not found]` @@ -230,17 +212,15 @@ export class OperatorTasks { }, }, { - title: `Create Issuer ${OperatorTasks.ISSUER}`, - enabled: ctx => !ctx[ChectlContext.IS_OPENSHIFT], + title: `Create Webhook Service ${OperatorTasks.WEBHOOK_SERVICE}`, task: async (ctx: any, task: any) => { - const exists = await this.kh.isIssuerExists(OperatorTasks.ISSUER, this.flags.chenamespace) + const exists = await this.kh.isServiceExists(OperatorTasks.WEBHOOK_SERVICE, this.flags.chenamespace) if (exists) { task.title = `${task.title}...[Exists]]` } else { - const yamlFilePath = this.getResourcePath('selfsigned-issuer.yaml') + const yamlFilePath = this.getResourcePath('webhook-service.yaml') if (fs.existsSync(yamlFilePath)) { - const issuer = yaml.load(fs.readFileSync(yamlFilePath).toString()) - await this.kh.createIssuer(issuer, this.flags.chenamespace) + await this.kh.createServiceFromFile(yamlFilePath, this.flags.chenamespace) task.title = `${task.title}...[OK: created]` } else { task.title = `${task.title}...[Skipped: Not found]` @@ -248,6 +228,26 @@ export class OperatorTasks { } }, }, + { + title: `Create CRD ${CHE_CLUSTER_CRD}`, + task: async (ctx: any, task: any) => { + const existedCRD = await this.kh.getCrd(CHE_CLUSTER_CRD) + if (existedCRD) { + task.title = `${task.title}...[Exists]]` + } else { + const newCRDPath = await this.getCRDPath() + await this.kh.createCrdFromFile(newCRDPath) + task.title = `${task.title}...[OK: created]` + } + }, + }, + { + title: 'Waiting 5 seconds for the new Kubernetes resources to get flushed', + task: async (_ctx: any, task: any) => { + await cli.wait(5000) + task.title = `${task.title}...[OK]` + }, + }, { title: `Create deployment ${OPERATOR_DEPLOYMENT_NAME} in namespace ${this.flags.chenamespace}`, task: async (ctx: any, task: any) => { @@ -321,7 +321,7 @@ export class OperatorTasks { updateTasks(): Array { return [ { - title: `Updating ServiceAccount ${OperatorTasks.SERVICE_ACCOUNT}`, + title: `Update ServiceAccount ${OperatorTasks.SERVICE_ACCOUNT}`, task: async (ctx: any, task: any) => { const exist = await this.kh.isServiceAccountExist(OperatorTasks.SERVICE_ACCOUNT, this.flags.chenamespace) const yamlFilePath = this.getResourcePath('service_account.yaml') @@ -336,95 +336,95 @@ export class OperatorTasks { }, this.getCreateOrUpdateRolesAndBindingsTasks(true), { - title: `Updating Eclipse Che cluster CRD ${CHE_CLUSTER_CRD}`, + title: `Update Certificate ${OperatorTasks.CERTIFICATE}`, + enabled: ctx => !ctx[ChectlContext.IS_OPENSHIFT], task: async (ctx: any, task: any) => { - const existedCRD = await this.kh.getCrd(CHE_CLUSTER_CRD) - const newCRDPath = await this.getCRDPath() - - if (existedCRD) { - if (!existedCRD.metadata || !existedCRD.metadata.resourceVersion) { - throw new Error(`Fetched CRD ${CHE_CLUSTER_CRD} without resource version`) - } + const yamlFilePath = this.getResourcePath('serving-cert.yaml') + if (!fs.existsSync(yamlFilePath)) { + task.title = `${task.title}...[Skipped: Not found]` + return + } - await this.kh.replaceCrdFromFile(newCRDPath) + const certificate = yaml.load(fs.readFileSync(yamlFilePath).toString()) as V1Certificate + const exist = await this.kh.isCertificateExists(OperatorTasks.CERTIFICATE, this.flags.chenamespace) + if (exist) { + await this.kh.replaceCertificate(OperatorTasks.CERTIFICATE, certificate, this.flags.chenamespace) task.title = `${task.title}...[OK: updated]` } else { - await this.kh.createCrdFromFile(newCRDPath) + await this.kh.createCertificate(certificate, this.flags.chenamespace) task.title = `${task.title}...[OK: created]` } }, }, { - title: 'Waiting 5 seconds for the new Kubernetes resources to get flushed', - task: async (_ctx: any, task: any) => { - await cli.wait(5000) - task.title = `${task.title}...[OK]` - }, - }, - { - title: `Update Service ${OperatorTasks.WEBHOOK_SERVICE}`, + title: `Update Issuer ${OperatorTasks.ISSUER}`, + enabled: ctx => !ctx[ChectlContext.IS_OPENSHIFT], task: async (ctx: any, task: any) => { - const yamlFilePath = this.getResourcePath('webhook-service.yaml') + const yamlFilePath = this.getResourcePath('selfsigned-issuer.yaml') if (!fs.existsSync(yamlFilePath)) { task.title = `${task.title}...[Skipped: Not found]` return } - const service = yaml.load(fs.readFileSync(yamlFilePath).toString()) as V1Service - const exist = await this.kh.isServiceExists(OperatorTasks.WEBHOOK_SERVICE, this.flags.chenamespace) + const issuer = yaml.load(fs.readFileSync(yamlFilePath).toString()) + const exist = await this.kh.isIssuerExists(OperatorTasks.ISSUER, this.flags.chenamespace) if (exist) { - await this.kh.replaceService(OperatorTasks.WEBHOOK_SERVICE, service, this.flags.chenamespace) + await this.kh.replaceIssuer(OperatorTasks.ISSUER, issuer, this.flags.chenamespace) task.title = `${task.title}...[OK: updated]` } else { - await this.kh.createService(service, this.flags.chenamespace) + await this.kh.createIssuer(issuer, this.flags.chenamespace) task.title = `${task.title}...[OK: created]` } }, }, { - title: `Update Certificate ${OperatorTasks.CERTIFICATE}`, - enabled: ctx => !ctx[ChectlContext.IS_OPENSHIFT], + title: `Update Service ${OperatorTasks.WEBHOOK_SERVICE}`, task: async (ctx: any, task: any) => { - const yamlFilePath = this.getResourcePath('serving-cert.yaml') + const yamlFilePath = this.getResourcePath('webhook-service.yaml') if (!fs.existsSync(yamlFilePath)) { task.title = `${task.title}...[Skipped: Not found]` return } - const certificate = yaml.load(fs.readFileSync(yamlFilePath).toString()) as V1Certificate - const exist = await this.kh.isCertificateExists(OperatorTasks.CERTIFICATE, this.flags.chenamespace) + const service = yaml.load(fs.readFileSync(yamlFilePath).toString()) as V1Service + const exist = await this.kh.isServiceExists(OperatorTasks.WEBHOOK_SERVICE, this.flags.chenamespace) if (exist) { - await this.kh.replaceCertificate(OperatorTasks.CERTIFICATE, certificate, this.flags.chenamespace) + await this.kh.replaceService(OperatorTasks.WEBHOOK_SERVICE, service, this.flags.chenamespace) task.title = `${task.title}...[OK: updated]` } else { - await this.kh.createCertificate(certificate, this.flags.chenamespace) + await this.kh.createService(service, this.flags.chenamespace) task.title = `${task.title}...[OK: created]` } }, }, { - title: `Update Issuer ${OperatorTasks.ISSUER}`, - enabled: ctx => !ctx[ChectlContext.IS_OPENSHIFT], + title: `Update Eclipse Che cluster CRD ${CHE_CLUSTER_CRD}`, task: async (ctx: any, task: any) => { - const yamlFilePath = this.getResourcePath('selfsigned-issuer.yaml') - if (!fs.existsSync(yamlFilePath)) { - task.title = `${task.title}...[Skipped: Not found]` - return - } + const existedCRD = await this.kh.getCrd(CHE_CLUSTER_CRD) + const newCRDPath = await this.getCRDPath() - const issuer = yaml.load(fs.readFileSync(yamlFilePath).toString()) - const exist = await this.kh.isIssuerExists(OperatorTasks.ISSUER, this.flags.chenamespace) - if (exist) { - await this.kh.replaceIssuer(OperatorTasks.ISSUER, issuer, this.flags.chenamespace) + if (existedCRD) { + if (!existedCRD.metadata || !existedCRD.metadata.resourceVersion) { + throw new Error(`Fetched CRD ${CHE_CLUSTER_CRD} without resource version`) + } + + await this.kh.replaceCrdFromFile(newCRDPath) task.title = `${task.title}...[OK: updated]` } else { - await this.kh.createIssuer(issuer, this.flags.chenamespace) + await this.kh.createCrdFromFile(newCRDPath) task.title = `${task.title}...[OK: created]` } }, }, { - title: `Updating deployment ${OPERATOR_DEPLOYMENT_NAME}`, + title: 'Waiting 5 seconds for the new Kubernetes resources to get flushed', + task: async (_ctx: any, task: any) => { + await cli.wait(5000) + task.title = `${task.title}...[OK]` + }, + }, + { + title: `Update deployment ${OPERATOR_DEPLOYMENT_NAME}`, task: async (ctx: any, task: any) => { const exist = await this.kh.isDeploymentExist(OPERATOR_DEPLOYMENT_NAME, this.flags.chenamespace) const deploymentPath = this.getResourcePath('operator.yaml') @@ -476,10 +476,10 @@ export class OperatorTasks { }, }, { - title: `Delete Webhook Service ${OperatorTasks.WEBHOOK_SERVICE}`, + title: `Delete Issuer ${OperatorTasks.ISSUER}`, task: async (_ctx: any, task: any) => { try { - await kh.deleteService(OperatorTasks.WEBHOOK_SERVICE, this.flags.chenamespace) + await kh.deleteIssuer(OperatorTasks.ISSUER, this.flags.chenamespace) task.title = `${task.title}...[Ok]` } catch (e: any) { task.title = `${task.title}...[Failed: ${e.message}]` @@ -487,10 +487,10 @@ export class OperatorTasks { }, }, { - title: `Delete Issuer ${OperatorTasks.ISSUER}`, + title: `Delete Certificate ${OperatorTasks.CERTIFICATE}`, task: async (_ctx: any, task: any) => { try { - await kh.deleteIssuer(OperatorTasks.ISSUER, this.flags.chenamespace) + await kh.deleteCertificate(OperatorTasks.CERTIFICATE, this.flags.chenamespace) task.title = `${task.title}...[Ok]` } catch (e: any) { task.title = `${task.title}...[Failed: ${e.message}]` @@ -498,10 +498,10 @@ export class OperatorTasks { }, }, { - title: `Delete Certificate ${OperatorTasks.CERTIFICATE}`, + title: `Delete Webhook Service ${OperatorTasks.WEBHOOK_SERVICE}`, task: async (_ctx: any, task: any) => { try { - await kh.deleteCertificate(OperatorTasks.CERTIFICATE, this.flags.chenamespace) + await kh.deleteService(OperatorTasks.WEBHOOK_SERVICE, this.flags.chenamespace) task.title = `${task.title}...[Ok]` } catch (e: any) { task.title = `${task.title}...[Failed: ${e.message}]`