Skip to content

Apply KubernetesPodOperator template fields only after rendering - #71174

Merged
shahar1 merged 1 commit into
apache:mainfrom
rjgoyln:fix-kpo-template-field-init
Sep 16, 2026
Merged

shahar1 merged 1 commit into
apache:mainfrom
rjgoyln:fix-kpo-template-field-init

Conversation

@rjgoyln

@rjgoyln rjgoyln commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

KubernetesPodOperator converted and merged several template-field values in __init__, which runs before Jinja rendering. A templated base_container_name was copied into the default container_logs and never rendered, so log fetching asked for a container that did not exist. A templated configmaps string was iterated character by character into env_from, and templated volumes / volume_mounts were rejected at Dag parse time before they could resolve.

__init__ now only stores these arguments; the conversions run in build_pod_request_obj() and container_logs resolves its base-container fallback lazily. configmaps becomes a declared template field, having previously been rendered by accident through the env_from list it was merged into.

An env_vars mapping is the one conversion that still precedes rendering, in a render_template_fields override: an env var name is a template field of V1EnvVar, while a plain dict renders only its values. Only the container shape is inspected, never the value.

Behavior change

SparkKubernetesOperator no longer warns that container_logs "is not supported and will be overridden" when the user never passed it; an explicitly requested container is still overridden to the driver container.

Clears the KubernetesPodOperator entry of the burn-down tracked in #70296.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

@boring-cyborg boring-cyborg Bot added area:dev-tools area:providers backport-to-v3-3-test Backport to v3-3-test provider:cncf-kubernetes Kubernetes (k8s) provider related issues labels Aug 5, 2026
@rjgoyln
rjgoyln force-pushed the fix-kpo-template-field-init branch from 36f2991 to 0253bf6 Compare August 5, 2026 15:47
@rjgoyln
rjgoyln marked this pull request as ready for review August 8, 2026 00:15
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Aug 13, 2026
@rjgoyln
rjgoyln force-pushed the fix-kpo-template-field-init branch from 71f16d1 to 6dde469 Compare August 25, 2026 14:16
Comment thread providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py Outdated
Template fields are rendered after the constructor runs, so converting or
merging their values there operates on the un-rendered Jinja expression:
a templated base_container_name never reached the container_logs fallback,
a templated configmaps string was iterated character by character, and
templated volumes were rejected at Dag parse time.

The one conversion that still has to precede rendering — a str-str env_vars
mapping, whose keys are only rendered once they are V1EnvVar names — hooks
_do_render_template_fields rather than render_template_fields, because a
mapped task reaches the operator only through the former.

Clears the KubernetesPodOperator entry of the burn-down tracked at
apache#70296.
@rjgoyln
rjgoyln force-pushed the fix-kpo-template-field-init branch from 6dde469 to b4bf207 Compare September 13, 2026 05:41
@shahar1

shahar1 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Great work!

@shahar1
shahar1 merged commit 073d1ed into apache:main Sep 16, 2026
108 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-3-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-3-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 073d1ed v3-3-test

This should apply the commit to the v3-3-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants