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

fix: add applyArgs to kubectl apply function #6385

Merged
merged 3 commits into from
Sep 4, 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
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