Skip to content

Commit

Permalink
feat: allow custom args in kubectl apply for kubernetes deployments (
Browse files Browse the repository at this point in the history
…#6107)

* feat: add applyArgs for kubernetes deployments

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

* docs(k8s): re-generate docs

---------

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 Jun 3, 2024
1 parent 17f5e0c commit 85ab8e2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/plugins/kubernetes/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface ApplyParams {
pruneLabels?: { [label: string]: string }
validate?: boolean
retryOpts?: RetryOpts
applyArgs?: string[]
}

export const KUBECTL_DEFAULT_TIMEOUT = 300
Expand All @@ -77,6 +78,7 @@ export async function apply({
namespace,
pruneLabels,
validate = true,
applyArgs,
}: ApplyParams) {
// Hash the raw input and add as an annotation on each manifest (this is helpful beyond kubectl's own annotation,
// because kubectl applies some normalization/transformation that is sometimes difficult to reason about).
Expand Down Expand Up @@ -122,6 +124,7 @@ export async function apply({
dryRun && args.push("--dry-run")
args.push("--output=json", "-f", "-")
!validate && args.push("--validate=false")
applyArgs && args.push(...applyArgs)

let result: string
try {
Expand Down
4 changes: 4 additions & 0 deletions core/src/plugins/kubernetes/kubernetes-type/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ export const kubernetesPatchResourcesSchema = () =>
`
)

export const kubernetesApplyArgsSchema = () =>
joi.array().items(joi.string()).description("Additional arguments to pass to `kubectl apply`.")

export const kubernetesCommonDeploySpecKeys = () => ({
files: kubernetesFilesSchema(),
kustomize: kustomizeSpecSchema(),
Expand All @@ -122,6 +125,7 @@ export const kubernetesCommonDeploySpecKeys = () => ({
namespace: namespaceNameSchema(),
portForwards: portForwardsSchema(),
timeout: k8sDeploymentTimeoutSchema(),
applyArgs: kubernetesApplyArgsSchema(),
// TODO-0.14: flip this to true and change default behavior to
// wait for the jobs
waitForJobs: joi
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/action-types/Deploy/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,16 @@ The maximum duration (in seconds) to wait for resources to deploy and become hea
| -------- | ------- | -------- |
| `number` | `300` | No |

### `spec.applyArgs[]`

[spec](#spec) > applyArgs

Additional arguments to pass to `kubectl apply`.

| Type | Required |
| --------------- | -------- |
| `array[string]` | No |

### `spec.waitForJobs`

[spec](#spec) > waitForJobs
Expand Down
11 changes: 11 additions & 0 deletions docs/reference/module-types/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ portForwards:
# The maximum duration (in seconds) to wait for resources to deploy and become healthy.
timeout: 300

# Additional arguments to pass to `kubectl apply`.
applyArgs:

# Wait until the jobs have been completed. Garden will wait for as long as `timeout`.
waitForJobs: false

Expand Down Expand Up @@ -1122,6 +1125,14 @@ The maximum duration (in seconds) to wait for resources to deploy and become hea
| -------- | ------- | -------- |
| `number` | `300` | No |

### `applyArgs[]`

Additional arguments to pass to `kubectl apply`.

| Type | Required |
| --------------- | -------- |
| `array[string]` | No |

### `waitForJobs`

Wait until the jobs have been completed. Garden will wait for as long as `timeout`.
Expand Down

0 comments on commit 85ab8e2

Please sign in to comment.