Skip to content

Commit

Permalink
fix: Wait until pod is actual deleted for server:delete and server:st…
Browse files Browse the repository at this point in the history
…op commands (#730)

* Wait until pod is actual deleted for server:delete and server:stop commands

Signed-off-by: Anatoliy Bazko <[email protected]>
  • Loading branch information
tolusha authored May 26, 2020
1 parent 53b4f98 commit 86e0f65
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 46 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ OPTIONS
-n, --chenamespace=chenamespace [default: che] Kubernetes namespace where Eclipse Che server is supposed to
be deployed
--deployment-name=deployment-name [default: che] Eclipse Che deployment name
--listr-renderer=default|silent|verbose [default: default] Listr renderer
--skip-deletion-check Skip user confirmation on deletion check
Expand Down
6 changes: 3 additions & 3 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,13 @@ export class KubeHelper {
async waitUntilPodIsDeleted(selector: string, namespace = '', intervalMs = 500, timeoutMs = this.podReadyTimeout) {
const iterations = timeoutMs / intervalMs
for (let index = 0; index < iterations; index++) {
let readyStatus = await this.getPodReadyConditionStatus(selector, namespace)
if (readyStatus === 'False') {
const pods = await this.listNamespacedPod(namespace, undefined, selector)
if (!pods.items.length) {
return
}
await cli.wait(intervalMs)
}
throw new Error(`ERR_TIMEOUT: Timeout set to pod ready timeout ${this.podReadyTimeout}`)
throw new Error('ERR_TIMEOUT: Waiting until pod is deleted took too long.')
}

async deletePod(name: string, namespace = '') {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/server/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { cli } from 'cli-ux'
import * as Listrq from 'listr'

import { KubeHelper } from '../../api/kube'
import { cheNamespace, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { cheDeployment, cheNamespace, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { CheTasks } from '../../tasks/che'
import { HelmTasks } from '../../tasks/installers/helm'
import { MinishiftAddonTasks } from '../../tasks/installers/minishift-addon'
Expand All @@ -28,6 +28,7 @@ export default class Delete extends Command {
static flags = {
help: flags.help({ char: 'h' }),
chenamespace: cheNamespace,
'deployment-name': cheDeployment,
'listr-renderer': listrRenderer,
'skip-deletion-check': boolean({
description: 'Skip user confirmation on deletion check',
Expand All @@ -53,11 +54,13 @@ export default class Delete extends Command {
)

tasks.add(apiTasks.testApiTasks(flags, this))
tasks.add(cheTasks.checkIfCheIsInstalledTasks(flags, this))
tasks.add(operatorTasks.deleteTasks(flags))
tasks.add(olmTasks.deleteTasks(flags))
tasks.add(cheTasks.deleteTasks(flags))
tasks.add(helmTasks.deleteTasks(flags))
tasks.add(minishiftAddonTasks.deleteTasks(flags))
tasks.add(cheTasks.waitPodsDeletedTasks())

const cluster = KubeHelper.KUBE_CONFIG.getCurrentCluster()
if (!cluster) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/server/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class Stop extends Command {
{ renderer: flags['listr-renderer'] as any }
)
tasks.add(cheTasks.scaleCheDownTasks(this))
tasks.add(cheTasks.waitPodsDeletedTasks())

try {
await tasks.run()
Expand Down
90 changes: 49 additions & 41 deletions src/tasks/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class CheTasks {
task: async (ctx: any, task: any) => {
if (ctx.isAuthEnabled && !this.cheAccessToken) {
command.error('E_AUTH_REQUIRED - Eclipse Che authentication is enabled and an access token need to be provided (flag --access-token). ' +
`For instructions to retrieve a valid access token refer to ${DOCS_LINK_AUTH_TO_CHE_SERVER_VIA_OPENID}`)
`For instructions to retrieve a valid access token refer to ${DOCS_LINK_AUTH_TO_CHE_SERVER_VIA_OPENID}`)
}
try {
const cheURL = await this.che.cheURL(this.cheNamespace)
Expand All @@ -281,14 +281,6 @@ export class CheTasks {
}
}
},
{
title: 'Wait until Eclipse Che pod is deleted',
enabled: (ctx: any) => !ctx.isCheStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.cheSelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Scale \"keycloak\" deployment to zero',
enabled: (ctx: any) => ctx.isKeycloakDeployed && !ctx.isKeycloakStopped,
Expand All @@ -301,14 +293,6 @@ export class CheTasks {
}
}
},
{
title: 'Wait until Keycloak pod is deleted',
enabled: (ctx: any) => ctx.isKeycloakDeployed && !ctx.isKeycloakStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.keycloakSelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Scale \"postgres\" deployment to zero',
enabled: (ctx: any) => ctx.isPostgresDeployed && !ctx.isPostgresStopped,
Expand All @@ -321,14 +305,6 @@ export class CheTasks {
}
}
},
{
title: 'Wait until Postgres pod is deleted',
enabled: (ctx: any) => ctx.isPostgresDeployed && !ctx.isPostgresStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.postgresSelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Scale \"devfile registry\" deployment to zero',
enabled: (ctx: any) => ctx.isDevfileRegistryDeployed && !ctx.isDevfileRegistryStopped,
Expand All @@ -341,14 +317,6 @@ export class CheTasks {
}
}
},
{
title: 'Wait until Devfile registry pod is deleted',
enabled: (ctx: any) => ctx.isDevfileRegistryDeployed && !ctx.isDevfileRegistryStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.devfileRegistrySelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Scale \"plugin registry\" deployment to zero',
enabled: (ctx: any) => ctx.isPluginRegistryDeployed && !ctx.isPluginRegistryStopped,
Expand All @@ -360,14 +328,6 @@ export class CheTasks {
command.error(`E_SCALE_DEPLOY_FAIL - Failed to scale plugin-registry deployment. ${error.message}`)
}
}
},
{
title: 'Wait until Plugin registry pod is deleted',
enabled: (ctx: any) => ctx.isPluginRegistryDeployed && !ctx.isPluginRegistryStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.pluginRegistrySelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
}]
}

Expand Down Expand Up @@ -462,6 +422,54 @@ export class CheTasks {
}]
}

/**
* Returns tasks which wait until pods are deleted.
*/
waitPodsDeletedTasks(): ReadonlyArray<Listr.ListrTask> {
return [
{
title: 'Wait until Eclipse Che pod is deleted',
enabled: (ctx: any) => !ctx.isCheStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.cheSelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Wait until Keycloak pod is deleted',
enabled: (ctx: any) => ctx.isKeycloakDeployed && !ctx.isKeycloakStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.keycloakSelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Wait until Postgres pod is deleted',
enabled: (ctx: any) => ctx.isPostgresDeployed && !ctx.isPostgresStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.postgresSelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Wait until Devfile registry pod is deleted',
enabled: (ctx: any) => ctx.isDevfileRegistryDeployed && !ctx.isDevfileRegistryStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.devfileRegistrySelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
},
{
title: 'Wait until Plugin registry pod is deleted',
enabled: (ctx: any) => ctx.isPluginRegistryDeployed && !ctx.isPluginRegistryStopped,
task: async (_ctx: any, task: any) => {
await this.kube.waitUntilPodIsDeleted(this.pluginRegistrySelector, this.cheNamespace)
task.title = `${task.title}...done.`
}
}
]
}

verifyCheNamespaceExistsTask(flags: any, command: Command): ReadonlyArray<Listr.ListrTask> {
return [{
title: `Verify if namespace '${flags.chenamespace}' exists`,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ ecc-jsbn@~0.1.1:

"eclipse-che@git://github.com/eclipse/che#master":
version "0.0.0"
resolved "git://github.com/eclipse/che#0043e9dd7ce3a058ba046eb7f5dc8a4a9aa3ae9b"
resolved "git://github.com/eclipse/che#a46766cec2c7365d03d499d6bdbc7a663658bbe3"

editorconfig@^0.15.0:
version "0.15.3"
Expand Down

0 comments on commit 86e0f65

Please sign in to comment.