Skip to content

Commit

Permalink
chore: Reorder operator tasks (#2079)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Apr 19, 2022
1 parent 474e2ca commit 6d46101
Showing 1 changed file with 85 additions and 85 deletions.
170 changes: 85 additions & 85 deletions src/tasks/installers/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
Expand All @@ -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]`
Expand All @@ -230,24 +212,42 @@ 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]`
}
}
},
},
{
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) => {
Expand Down Expand Up @@ -321,7 +321,7 @@ export class OperatorTasks {
updateTasks(): Array<Listr.ListrTask> {
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')
Expand All @@ -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')
Expand Down Expand Up @@ -476,32 +476,32 @@ 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}]`
}
},
},
{
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}]`
}
},
},
{
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}]`
Expand Down

0 comments on commit 6d46101

Please sign in to comment.