Skip to content

Commit

Permalink
fix: add applyArgs to kubectl apply function (#6385)
Browse files Browse the repository at this point in the history
* fix: add applyArgs to kubectl apply function

Signed-off-by: Manuel Ruck <[email protected]>

* test: add applyArgs test for kubernetes deploy

Signed-off-by: Manuel Ruck <[email protected]>

* test: ensure that custom applyArgs are passed in and applied

---------

Signed-off-by: Manuel Ruck <[email protected]>
Co-authored-by: Manuel Ruck <[email protected]>
Co-authored-by: Vladimir Vagaytsev <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent 955e605 commit f140ab2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/src/plugins/kubernetes/kubernetes-type/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
KubernetesExecTestActionConfig,
} from "./kubernetes-exec.js"
import { dedent } from "../../../util/string.js"
import type { ApplyParams } from "../kubectl.js"

export interface KubernetesTypeCommonDeploySpec {
files: string[]
Expand All @@ -40,6 +41,7 @@ export interface KubernetesTypeCommonDeploySpec {
manifests: KubernetesResource[]
namespace?: string
portForwards?: PortForwardSpec[]
applyArgs?: ApplyParams["applyArgs"]
}

export interface KubernetesDeployActionSpec extends KubernetesTypeCommonDeploySpec {
Expand Down
12 changes: 10 additions & 2 deletions core/src/plugins/kubernetes/kubernetes-type/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export const kubernetesDeploy: DeployActionHandler<"deploy", KubernetesDeployAct

if (namespaceManifests.length > 0) {
// Don't prune namespaces
await apply({ log, ctx, api, provider, manifests: namespaceManifests })
await apply({ log, ctx, api, provider, manifests: namespaceManifests, applyArgs: spec.applyArgs })
await waitForResources({
namespace,
ctx,
Expand Down Expand Up @@ -410,7 +410,15 @@ export const kubernetesDeploy: DeployActionHandler<"deploy", KubernetesDeployAct

// TODO: Similarly to `container` deployments, check if immutable fields have changed (and delete before
// redeploying, unless in a production environment).
await apply({ log, ctx, api, provider: k8sCtx.provider, manifests: preparedManifests, pruneLabels })
await apply({
log,
ctx,
api,
provider: k8sCtx.provider,
manifests: preparedManifests,
pruneLabels,
applyArgs: spec.applyArgs,
})
await waitForResources({
namespace,
ctx,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Deploy
name: apply-args
type: kubernetes

spec:
applyArgs:
- --unknown-apply-flag
files:
- manifests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
items:
- apiVersion: v1
data:
foo.json: test
kind: ConfigMap
metadata:
name: foo
- apiVersion: v1
data:
bar.json: test
kind: ConfigMap
metadata:
name: bar
- apiVersion: v1
data:
baz.json: test
kind: ConfigMap
metadata:
name: baz
kind: ConfigMapList
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import cloneDeep from "fast-copy"
import tmp from "tmp-promise"

import type { TestGarden } from "../../../../../helpers.js"
import { expectError } from "../../../../../helpers.js"
import { getKubernetesTestGarden } from "./common.js"
import { DeployTask } from "../../../../../../src/tasks/deploy.js"
import {
Expand Down Expand Up @@ -490,6 +491,13 @@ describe("kubernetes-type handlers", () => {
// test successful deploy
await kubernetesDeploy(configMapList.deployParams)
})

it("should apply the custom applyArgs to the deployment", async () => {
// This example has a bad custom argument - it is `--unknown-apply-flag`.
const { deployParams } = await prepareActionDeployParams("apply-args", {})

await expectError(() => kubernetesDeploy(deployParams), { contains: "error: unknown flag: --unknown-apply-flag" })
})
})

describe("deleteKubernetesDeploy", () => {
Expand Down

0 comments on commit f140ab2

Please sign in to comment.