Support wait_for_jobs flag for helm release upgrade/install (#1140) (#1214)

* Support wait_for_jobs flag for helm release upgrade/install

* Update plugins/modules/helm.py



* Apply suggestion from @abikouo

* fix(helm): correct wait_for_jobs implementation and add changelog

- Fix double-append of --wait-for-jobs flag
- Fix version check to run before appending the flag
- Fetch helm_version before use to avoid undefined variable
- Fix YAML indentation for version_added in docs
- Add changelog fragment



* test: add integration tests for wait_for_jobs

- Test that --wait-for-jobs is appended when wait=true and wait_for_jobs=true
- Test that wait_for_jobs fails with appropriate message on helm < 3.5.0
- Test that wait_for_jobs is ignored when wait is not set
- Add test-chart-job helm chart containing a simple Job resource



* fix: harden test Job pod spec

Disable service account token automounting and add memory limit to
the test Job container.



* fix: add resource requests and pin image version in test Job

Add CPU, memory, and ephemeral-storage requests. Pin busybox image
to version 1.37.



* style: apply linter formatting to helm argument_spec



* Update sanity ignore file

* fix: quote Helm template expression to pass yamllint sanity



* Fix linters errors

---------





(cherry picked from commit e475d06403)

Co-authored-by: Daniel Simko <danosimko1@gmail.com>
Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
Co-authored-by: Yuriy Novostavskiy <yuriy@novostavskiy.kyiv.ua>
Co-authored-by: aubin bikouo <abikouo@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
patchback[bot]
2026-08-11 12:11:51 -04:00
committed by GitHub
co-authored by Daniel Simko Bikouo Aubin Yuriy Novostavskiy aubin bikouo Claude Opus 4.6
parent 569bae6593
commit 7b17313ace
14 changed files with 178 additions and 39 deletions
@@ -0,0 +1,5 @@
---
minor_changes:
- "helm - Add ``wait_for_jobs`` option to wait for all Jobs to complete before
marking a Helm release as successful. Requires Helm >= 3.5.0
(https://github.com/ansible-collections/kubernetes.core/pull/1140)."
+76 -39
View File
@@ -187,6 +187,15 @@ options:
It will wait for as long as I(wait_timeout). This feature requires helm>=3.7.0. Added in version 2.3.0.
default: False
type: bool
wait_for_jobs:
description:
- When I(release_state) is set to C(present), and I(wait) is set to C(True), wait until all jobs are in a
completed state before marking the release as successful.
- Ignored when used without O(wait).
- Requires Helm >= 3.5.0
version_added: 6.6.0
default: False
type: bool
wait_timeout:
description:
- Timeout when wait option is enabled (helm2 is a number of seconds, helm3 is a duration).
@@ -397,6 +406,7 @@ EXAMPLES = r"""
release_namespace: default
force: True
wait: True
wait_for_jobs: True
replace: True
update_repo_cache: True
disable_hook: True
@@ -613,6 +623,7 @@ def deploy(
release_values,
chart_name,
wait,
wait_for_jobs,
wait_timeout,
disable_hook,
force,
@@ -668,6 +679,16 @@ def deploy(
if wait:
deploy_command += " --wait"
if wait_for_jobs:
helm_version = module.get_helm_version()
if LooseVersion(helm_version) < LooseVersion("3.5.0"):
module.fail_json(
msg="wait_for_jobs requires helm >= 3.5.0, current version is {0}".format(
helm_version
)
)
else:
deploy_command += " --wait-for-jobs"
if wait_timeout is not None:
deploy_command += " --timeout " + wait_timeout
@@ -966,45 +987,58 @@ def default_check(release_status, chart_info, values=None, values_files=None):
def argument_spec():
arg_spec = copy.deepcopy(HELM_AUTH_ARG_SPEC)
arg_spec.update(
dict(
chart_ref=dict(type="path"),
chart_repo_url=dict(type="str"),
chart_version=dict(type="str"),
dependency_update=dict(type="bool", default=False, aliases=["dep_up"]),
release_name=dict(type="str", required=True, aliases=["name"]),
release_namespace=dict(type="str", required=True, aliases=["namespace"]),
release_state=dict(
default="present", choices=["present", "absent"], aliases=["state"]
),
release_values=dict(type="dict", default={}, aliases=["values"]),
values_files=dict(type="list", default=[], elements="str"),
update_repo_cache=dict(type="bool", default=False),
disable_hook=dict(type="bool", default=False),
force=dict(type="bool", default=False),
purge=dict(type="bool", default=True),
wait=dict(type="bool", default=False),
wait_timeout=dict(type="str"),
timeout=dict(type="str"),
atomic=dict(type="bool", default=False),
cleanup_on_fail=dict(type="bool", default=False),
server_side=dict(type="str", choices=["auto", "true", "false"]),
force_conflicts=dict(type="bool", default=False),
create_namespace=dict(type="bool", default=False),
post_renderer=dict(type="str"),
replace=dict(type="bool", default=False),
skip_crds=dict(type="bool", default=False),
history_max=dict(type="int"),
set_values=dict(type="list", elements="dict"),
reuse_values=dict(type="bool"),
reset_values=dict(type="bool", default=True),
reset_then_reuse_values=dict(type="bool", default=False),
insecure_skip_tls_verify=dict(
type="bool", default=False, aliases=["skip_tls_certs_check"]
),
plain_http=dict(type="bool", default=False),
take_ownership=dict(type="bool", default=False),
skip_schema_validation=dict(type="bool", default=False),
)
{
"chart_ref": {"type": "path"},
"chart_repo_url": {"type": "str"},
"chart_version": {"type": "str"},
"dependency_update": {
"type": "bool",
"default": False,
"aliases": ["dep_up"],
},
"release_name": {"type": "str", "required": True, "aliases": ["name"]},
"release_namespace": {
"type": "str",
"required": True,
"aliases": ["namespace"],
},
"release_state": {
"default": "present",
"choices": ["present", "absent"],
"aliases": ["state"],
},
"release_values": {"type": "dict", "default": {}, "aliases": ["values"]},
"values_files": {"type": "list", "default": [], "elements": "str"},
"update_repo_cache": {"type": "bool", "default": False},
"disable_hook": {"type": "bool", "default": False},
"force": {"type": "bool", "default": False},
"purge": {"type": "bool", "default": True},
"wait": {"type": "bool", "default": False},
"wait_for_jobs": {"type": "bool", "default": False},
"wait_timeout": {"type": "str"},
"timeout": {"type": "str"},
"atomic": {"type": "bool", "default": False},
"server_side": {"type": "str", "choices": ["auto", "true", "false"]},
"force_conflicts": {"type": "bool", "default": False},
"create_namespace": {"type": "bool", "default": False},
"post_renderer": {"type": "str"},
"replace": {"type": "bool", "default": False},
"skip_crds": {"type": "bool", "default": False},
"history_max": {"type": "int"},
"set_values": {"type": "list", "elements": "dict"},
"reuse_values": {"type": "bool"},
"reset_values": {"type": "bool", "default": True},
"reset_then_reuse_values": {"type": "bool", "default": False},
"insecure_skip_tls_verify": {
"type": "bool",
"default": False,
"aliases": ["skip_tls_certs_check"],
},
"plain_http": {"type": "bool", "default": False},
"take_ownership": {"type": "bool", "default": False},
"skip_schema_validation": {"type": "bool", "default": False},
"cleanup_on_fail": {"type": "bool", "default": False},
}
)
return arg_spec
@@ -1050,6 +1084,7 @@ def main():
force = module.params.get("force")
purge = module.params.get("purge")
wait = module.params.get("wait")
wait_for_jobs = module.params.get("wait_for_jobs")
wait_timeout = module.params.get("wait_timeout")
atomic = module.params.get("atomic")
cleanup_on_fail = module.params.get("cleanup_on_fail")
@@ -1178,6 +1213,7 @@ def main():
release_values,
chart_ref,
wait,
wait_for_jobs,
wait_timeout,
disable_hook,
False,
@@ -1265,6 +1301,7 @@ def main():
release_values,
chart_ref,
wait,
wait_for_jobs,
wait_timeout,
disable_hook,
force,
@@ -31,3 +31,4 @@ test_namespace:
- "helm-insecure-{{ helm_version | replace('.', '-') }}"
- "helm-test-take-ownership-{{ helm_version | replace('.', '-') }}"
- "helm-skip-schema-validation-{{ helm_version | replace('.', '-') }}"
- "helm-wait-for-jobs-{{ helm_version | replace('.', '-') }}"
@@ -0,0 +1,6 @@
apiVersion: v2
name: test-chart-job
description: A chart with a Job for testing wait_for_jobs
type: application
version: 0.1.0
appVersion: "default"
@@ -0,0 +1,21 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-job"
spec:
backoffLimit: 0
template:
spec:
automountServiceAccountToken: false
restartPolicy: Never
containers:
- name: test
image: "busybox:1.37"
command: ["sh", "-c", "echo done"]
resources:
requests:
cpu: "50m"
memory: "32Mi"
ephemeral-storage: "16Mi"
limits:
memory: "64Mi"
@@ -49,6 +49,9 @@
- name: Test helm skip_schema_validation
include_tasks: test_skip_schema_validation.yml
- name: Test helm wait_for_jobs
include_tasks: test_helm_wait_for_jobs.yml
always:
- name: Remove helm-diff plugin
helm_plugin:
@@ -0,0 +1,59 @@
---
- name: Test helm wait_for_jobs
vars:
helm_namespace: "{{ test_namespace[15] }}"
chart_local: "{{ role_path }}/files/test-chart-job"
block:
- name: Install chart with wait and wait_for_jobs
helm:
binary_path: "{{ helm_binary }}"
chart_ref: "{{ chart_local }}"
release_name: test-wait-for-jobs
release_namespace: "{{ helm_namespace }}"
create_namespace: true
wait: true
wait_for_jobs: true
wait_timeout: "120s"
register: install
ignore_errors: true
- name: Validate wait_for_jobs with helm >= 3.5.0 works
assert:
that:
- install is changed
- "'--wait' in install.command"
- "'--wait-for-jobs' in install.command"
when: "helm_version is ansible.builtin.version('v3.5.0', '>=')"
- name: Validate wait_for_jobs with helm < 3.5.0 fails
assert:
that:
- install is failed
- "'wait_for_jobs requires helm >= 3.5.0' in install.msg"
when: "helm_version is ansible.builtin.version('v3.5.0', '<')"
- name: Install chart with wait_for_jobs but without wait
helm:
binary_path: "{{ helm_binary }}"
chart_ref: "{{ chart_local }}"
release_name: test-wait-for-jobs-no-wait
release_namespace: "{{ helm_namespace }}"
create_namespace: true
wait_for_jobs: true
register: install_no_wait
- name: Validate wait_for_jobs is ignored without wait
assert:
that:
- install_no_wait is changed
- "'--wait-for-jobs' not in install_no_wait.command"
- "'--wait' not in install_no_wait.command"
always:
- name: Remove helm namespace
k8s:
api_version: v1
kind: Namespace
name: "{{ helm_namespace }}"
state: absent
+1
View File
@@ -21,6 +21,7 @@ tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-job/Chart.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
+1
View File
@@ -21,6 +21,7 @@ tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-job/Chart.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
+1
View File
@@ -18,6 +18,7 @@ tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-job/Chart.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
+1
View File
@@ -18,6 +18,7 @@ tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-job/Chart.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
+1
View File
@@ -21,6 +21,7 @@ tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-job/Chart.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
+1
View File
@@ -21,6 +21,7 @@ tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-job/Chart.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
+1
View File
@@ -21,6 +21,7 @@ tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-job/Chart.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip