-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add workspace:delete command #586
+213
−22
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import { Command, flags } from '@oclif/command' | ||
import * as Listrq from 'listr' | ||
import * as notifier from 'node-notifier' | ||
|
||
import { CheHelper } from '../../api/che' | ||
import { KubeHelper } from '../../api/kube' | ||
import { accessToken, cheNamespace, listrRenderer } from '../../common-flags' | ||
import { CheTasks } from '../../tasks/che' | ||
import { ApiTasks } from '../../tasks/platforms/api' | ||
|
||
export default class Delete extends Command { | ||
static description = 'delete workspace' | ||
|
||
static flags = { | ||
help: flags.help({ char: 'h' }), | ||
chenamespace: cheNamespace, | ||
workspace: flags.string({ | ||
char: 'w', | ||
description: 'The workspace id to delete', | ||
required: true | ||
}), | ||
'access-token': accessToken, | ||
'listr-renderer': listrRenderer | ||
} | ||
|
||
async run() { | ||
const { flags } = this.parse(Delete) | ||
const ctx: any = {} | ||
ctx.workspaces = [] | ||
|
||
const apiTasks = new ApiTasks() | ||
const cheTasks = new CheTasks(flags) | ||
const cheHelper = new CheHelper(flags) | ||
const kubeHelper = new KubeHelper(flags) | ||
const tasks = new Listrq(undefined, { renderer: flags['listr-renderer'] as any }) | ||
|
||
tasks.add(apiTasks.testApiTasks(flags, this)) | ||
tasks.add(cheTasks.verifyCheNamespaceExistsTask(flags, this)) | ||
tasks.add(cheTasks.retrieveEclipseCheUrl(flags)) | ||
tasks.add(cheTasks.checkEclipseCheStatus()) | ||
tasks.add({ | ||
title: `Get workspace with id '${flags.workspace}'`, | ||
task: async (ctx, task) => { | ||
const workspace = await cheHelper.getWorkspace(ctx.cheURL, flags.workspace, flags['access-token']) | ||
ctx.infrastructureNamespace = workspace.attributes.infrastructureNamespace | ||
task.title = `${task.title}... done` | ||
} | ||
}) | ||
tasks.add({ | ||
title: `Delete workspace with id '${flags.workspace}'`, | ||
task: async (ctx, task) => { | ||
await cheHelper.deleteWorkspace(ctx.cheURL, flags.workspace, flags['access-token']) | ||
task.title = `${task.title}... done` | ||
} | ||
}) | ||
tasks.add({ | ||
title: 'Verify if namespace exists', | ||
skip: ctx => ctx.infrastructureNamespace === flags.chenamespace, | ||
task: async (ctx, task) => { | ||
task.title = `${task.title} '${ctx.infrastructureNamespace}'` | ||
ctx.infrastructureNamespaceExists = await kubeHelper.namespaceExist(ctx.infrastructureNamespace) | ||
if (ctx.infrastructureNamespaceExists) { | ||
task.title = `${task.title}... found` | ||
} else { | ||
task.title = `${task.title}... not found` | ||
} | ||
} | ||
}) | ||
tasks.add({ | ||
title: 'Delete namespace', | ||
skip: ctx => !ctx.infrastructureNamespaceExists, | ||
task: async (ctx, task) => { | ||
task.title = `${task.title} '${ctx.infrastructureNamespace}'` | ||
await kubeHelper.deleteNamespace(ctx.infrastructureNamespace) | ||
task.title = `${task.title}... done` | ||
} | ||
}) | ||
|
||
try { | ||
await tasks.run(ctx) | ||
} catch (error) { | ||
this.error(error) | ||
} | ||
|
||
notifier.notify({ | ||
title: 'chectl', | ||
message: 'Command workspace:delete has completed successfully.' | ||
}) | ||
|
||
this.exit(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello. @tolusha workspace can be configured to start workspace with the same namespace with Che...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. that's why I check
if it is the same namespace then I won't delete it