Skip to content

Commit

Permalink
fix: ensure namespace is removed before returning when deleting env
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Jul 10, 2018
1 parent 3e3d13f commit f381d33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/plugins/kubernetes/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
createNamespace,
getAppNamespace,
getMetadataNamespace,
getAllAppNamespaces,
getAllGardenNamespaces,
} from "./namespace"
import {
KUBECTL_DEFAULT_TIMEOUT,
Expand Down Expand Up @@ -141,12 +141,12 @@ export async function getServiceStatus(params: GetServiceStatusParams<ContainerM
return await checkDeploymentStatus(params)
}

export async function destroyEnvironment({ ctx, provider, env }: DestroyEnvironmentParams) {
export async function destroyEnvironment({ ctx, provider }: DestroyEnvironmentParams) {
const { context } = provider.config
const namespace = await getAppNamespace(ctx, provider)
const entry = ctx.log.info({
section: "kubernetes",
msg: `Deleting namespace ${namespace}`,
msg: `Deleting namespace ${namespace} (this can take awhile)`,
entryStyle: EntryStyle.activity,
})

Expand All @@ -156,7 +156,7 @@ export async function destroyEnvironment({ ctx, provider, env }: DestroyEnvironm
await coreApi(context).deleteNamespace(namespace, <any>{})
} catch (err) {
entry.setError(err.message)
const availableNamespaces = await getAllAppNamespaces(context)
const availableNamespaces = await getAllGardenNamespaces(context)
throw new NotFoundError(err, { namespace, availableNamespaces })
}

Expand All @@ -165,10 +165,8 @@ export async function destroyEnvironment({ ctx, provider, env }: DestroyEnvironm
while (true) {
await sleep(2000)

const status = await getEnvironmentStatus({ ctx, provider, env })

if (!status.configured) {
entry.setSuccess("Finished")
const nsNames = await getAllGardenNamespaces(context)
if (!nsNames.includes(namespace)) {
break
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kubernetes/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function getMetadataNamespace(ctx: PluginContext, provider: KubernetesPro
return `garden-metadata--${ctx.projectName}--${env.namespace}`
}

export async function getAllAppNamespaces(context: string): Promise<string[]> {
export async function getAllGardenNamespaces(context: string): Promise<string[]> {
const allNamespaces = await coreApi(context).listNamespace()
return allNamespaces.body.items
.map(n => n.metadata.name)
Expand Down
5 changes: 5 additions & 0 deletions static/bin/garden-debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node --inspect

const cli = require("../../build/cli/cli")

cli.run()

0 comments on commit f381d33

Please sign in to comment.