Skip to content
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(kubernetes): plugin command to remove garden-util resources #6278

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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