Skip to content

Commit

Permalink
feat(kubernetes): plugin command to remove garden-util resources (#…
Browse files Browse the repository at this point in the history
…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
vvagaytsev authored Jul 10, 2024
1 parent 1890e84 commit 4f8a2d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
44 changes: 44 additions & 0 deletions core/src/plugins/kubernetes/commands/cleanup-garden-util.ts
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 }
},
}
3 changes: 1 addition & 2 deletions core/src/plugins/kubernetes/container/build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { LogLevel } from "../../../../logger/logger.js"
import type { ActionRuntime } from "../../../../plugin/base.js"

export const inClusterBuilderServiceAccount = "garden-in-cluster-builder"
export const sharedBuildSyncDeploymentName = "garden-build-sync"
export const utilContainerName = "util"
export const utilRsyncPort = 8730
export const utilDeploymentName = "garden-util"
Expand Down Expand Up @@ -455,7 +454,7 @@ export async function ensureUtilDeployment({
namespace,
ctx,
provider,
actionName: "garden-util",
actionName: utilDeploymentName,
resources: [deployment, service],
log: buildUtilLog,
timeoutSec: 600,
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/kubernetes/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { helmPodRunDefinition, helmPodTestDefinition } from "./helm/helm-pod.js"
import { kubernetesPodRunDefinition, kubernetesPodTestDefinition } from "./kubernetes-type/kubernetes-pod.js"
import { kubernetesExecRunDefinition, kubernetesExecTestDefinition } from "./kubernetes-type/kubernetes-exec.js"
import { makeDocsLinkPlain, makeDocsLinkStyled } from "../../docs/common.js"
import { cleanupUtilDeployment } from "./commands/cleanup-garden-util.js"

export const CONTAINER_BUILD_CONCURRENCY_LIMIT_REMOTE_KUBERNETES = 5
export const CONTAINER_STATUS_CONCURRENCY_LIMIT_REMOTE_KUBERNETES = 20
Expand Down Expand Up @@ -154,6 +155,7 @@ export const gardenPlugin = () => {
outputsSchema,
commands: [
cleanupClusterRegistry,
cleanupUtilDeployment,
clusterInit,
uninstallGardenServices,
pullImage,
Expand Down

0 comments on commit 4f8a2d6

Please sign in to comment.