Skip to content

Commit

Permalink
chore: Refactor delete tasks (#2328)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>

Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Oct 18, 2022
1 parent 6f33848 commit 41d1964
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 252 deletions.
8 changes: 3 additions & 5 deletions prepare-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ function prepareCheOperatorTemplates() {
fs.copySync(
path.join(src, 'org.eclipse.che.ValidatingWebhookConfiguration.yaml'),
path.join(templates, 'org.eclipse.che.ValidatingWebhookConfiguration.yaml'))
if (fs.existsSync(path.join(src, 'org.eclipse.che.MutatingWebhookConfiguration.yaml'))) {
fs.copySync(
path.join(src, 'org.eclipse.che.MutatingWebhookConfiguration.yaml'),
path.join(templates, 'org.eclipse.che.MutatingWebhookConfiguration.yaml'))
}
fs.copySync(
path.join(src, 'org.eclipse.che.MutatingWebhookConfiguration.yaml'),
path.join(templates, 'org.eclipse.che.MutatingWebhookConfiguration.yaml'))
fs.copySync(
path.join(src, 'che-operator-leader-election.Role.yaml'),
path.join(templates, 'leader-election-role.yaml'))
Expand Down
41 changes: 6 additions & 35 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,8 @@ export class KubeHelper {
async getClusterCustomObject(group: string, version: string, plural: string, name: any): Promise<any> {
const k8sCoreApi = this.kubeConfig.makeApiClient(CustomObjectsApi)
try {
return await k8sCoreApi.getClusterCustomObject(group, version, plural, name)
const { body } = await k8sCoreApi.getClusterCustomObject(group, version, plural, name)
return body
} catch (e: any) {
if (e.response.statusCode !== 404) {
throw this.wrapK8sClientError(e)
Expand All @@ -723,8 +724,11 @@ export class KubeHelper {
const k8sCoreApi = this.kubeConfig.makeApiClient(CustomObjectsApi)
try {
await k8sCoreApi.deleteClusterCustomObject(group, version, plural, name)
cli.debug(`Deleted ${plural}.${version}.${group} ${name} resource`)
} catch (e: any) {
throw this.wrapK8sClientError(e)
if (e.response.statusCode !== 404) {
throw this.wrapK8sClientError(e)
}
}
}

Expand Down Expand Up @@ -1438,39 +1442,6 @@ export class KubeHelper {
}
}

async listOAuthClientBySelector(selector: string): Promise<any[]> {
const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi)
try {
const { body } = await customObjectsApi.listClusterCustomObject('oauth.openshift.io', 'v1', 'oauthclients', undefined, undefined, undefined, selector)
return (body as any).items
} catch (e: any) {
throw this.wrapK8sClientError(e)
}
}

async deleteOAuthClient(name: string): Promise<void> {
const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi)
try {
await customObjectsApi.deleteClusterCustomObject('oauth.openshift.io', 'v1', 'oauthclients', name)
} catch (e: any) {
if (e.response && e.response.statusCode === 404) {
return
}
throw this.wrapK8sClientError(e)
}
}

async deleteConsoleLink(name: string): Promise<void> {
const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi)
try {
await customObjectsApi.deleteClusterCustomObject('console.openshift.io', 'v1', 'consolelinks', name)
} catch (e: any) {
if (e.response.statusCode !== 404) {
throw this.wrapK8sClientError(e)
}
}
}

readCatalogSourceFromFile(filePath: string): CatalogSource {
const catalogSource = this.safeLoadFromYamlFile(filePath) as CatalogSource
if (!catalogSource.metadata || !catalogSource.metadata.name) {
Expand Down
14 changes: 5 additions & 9 deletions src/commands/server/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ export default class Delete extends Command {

tasks.add({
title: 'Uninstall Eclipse Che Operator',
task: async (_ctx: any, _task: any) => {
task: async (ctx: any, _task: any) => {
const operatorTasks = new OperatorInstaller(flags)
const cheTasks = new CheTasks(flags)

const tasks = new Listrq([], ctx.listrOptions)
tasks.add({
title: 'Delete Custom Resources',
task: () => new Listr(operatorTasks.getDeleteCRsTasks()),
title: 'Delete operator resources',
task: () => new Listr(operatorTasks.getDeleteTasks()),
})
if (ctx[ChectlContext.IS_OPENSHIFT]) {
let olmInstaller: Installer
Expand All @@ -137,15 +137,11 @@ export default class Delete extends Command {
task: () => new Listr(olmInstaller.getDeleteTasks()),
})
}
tasks.add({
title: 'Delete operator resources',
task: () => new Listr(operatorTasks.getDeleteTasks()),
})
tasks.add({
title: 'Wait until all pods are deleted',
task: () => new Listr(cheTasks.getWaitPodsDeletedTasks()),
})
if (flags['delete-namespace'] || flags['delete-all']) {
if (flags['delete-namespace']) {
tasks.add(cheTasks.getDeleteNamespaceTasks(flags))
}

Expand All @@ -155,7 +151,7 @@ export default class Delete extends Command {

if (flags.batch || await this.isDeletionConfirmed(flags)) {
try {
await tasks.run()
await tasks.run(ctx)
cli.log(getCommandSuccessMessage())
} catch (err: any) {
this.error(wrapCommandError(err))
Expand Down
4 changes: 2 additions & 2 deletions src/commands/server/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class Stop extends Command {
async run() {
const { flags } = this.parse(Stop)
flags.chenamespace = flags.chenamespace || await findWorkingNamespace(flags) || DEFAULT_CHE_NAMESPACE
await ChectlContext.init(flags, this)
const ctx = await ChectlContext.initAndGet(flags, this)

const Listr = require('listr')
const cheTasks = new CheTasks(flags)
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class Stop extends Command {
tasks.add(cheTasks.getSaleCheDownTasks())
tasks.add(cheTasks.getWaitPodsDeletedTasks())
try {
await tasks.run()
await tasks.run(ctx)
cli.log(getCommandSuccessMessage())
} catch (err: any) {
this.error(wrapCommandError(err))
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

export const DSC_PROJECT_NAME = 'dsc'
export const CHECTL_PROJECT_NAME = 'chectl'
export const CHE_FLAVOR = 'che'
export const CHE_OPERATOR_TEMPLATE_DIR = 'che-operator'
export const DEVWORKSPACE_OPERATOR_TEMPLATE_DIR = 'devworkspace-operator'

Expand Down
Loading

0 comments on commit 41d1964

Please sign in to comment.