-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubernetes): plugin command to remove
garden-util
resources (#…
…6278) * chore: remove unused constant * chore: use named constant as a deploy action name * feat(kubernetes): plugin command to remove `garden-util` resources * chore: print namespace in the log message
- Loading branch information
1 parent
1890e84
commit 4f8a2d6
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
core/src/plugins/kubernetes/commands/cleanup-garden-util.ts
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,44 @@ | ||
/* | ||
* Copyright (C) 2018-2024 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import type { KubernetesPluginContext } from "../config.js" | ||
import type { PluginCommand } from "../../../plugin/command.js" | ||
import { utilDeploymentName } from "../container/build/common.js" | ||
import { styles } from "../../../logger/styles.js" | ||
import { deleteResources } from "../kubectl.js" | ||
import type { KubernetesResource } from "../types.js" | ||
|
||
export const cleanupUtilDeployment: PluginCommand = { | ||
name: "cleanup-util-deployment", | ||
description: `Remove ${utilDeploymentName} utility deployment from the current namespace`, | ||
title: `Cleanup ${utilDeploymentName} deployment`, | ||
resolveGraph: true, | ||
|
||
handler: async ({ ctx, log }) => { | ||
const result = {} | ||
const k8sCtx = ctx as KubernetesPluginContext | ||
const provider = k8sCtx.provider | ||
|
||
const namespace = provider.outputs["app-namespace"] | ||
log.info({ msg: styles.highlight(`\nRemoving ${utilDeploymentName} deployment from namespace ${namespace}`) }) | ||
|
||
const targetKinds = ["Service", "Deployment"] | ||
const resources: KubernetesResource[] = targetKinds.map((kind) => { | ||
return { apiVersion: "v1", kind, metadata: { name: utilDeploymentName } } | ||
}) | ||
|
||
for (const resource of resources) { | ||
log.info(`Deleting ${resource.kind}/${resource.metadata.name}`) | ||
await deleteResources({ ctx, log, provider, namespace, resources }) | ||
} | ||
|
||
log.success("\nDone!") | ||
|
||
return { result } | ||
}, | ||
} |
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