Skip to content

Expose pod details to the webhook template - #1289

Open
zhan9san wants to merge 1 commit into
aws:mainfrom
zhan9san:webhook-pod-details
Open

zhan9san wants to merge 1 commit into
aws:mainfrom
zhan9san:webhook-pod-details

Conversation

@zhan9san

Copy link
Copy Markdown

Issue #, if available: Fixes #1288

Description of changes:

What

Adds a PodDetails field to the webhook template data, with each pod's namespace, phase, controller kind, labels and annotations.

Why

The webhook fires while the affected pods can still be inspected, but Pods only carries names. Without namespace, phase, owner, labels or annotations, a receiver can't tell which workloads an interruption actually hit, or route the notification to the team that owns them. Details are in #1288.

Changes

  • pkg/node: add a PodDetail type, FetchPodDetails and a PodNames helper. FetchPodDetails uses the same fetchAllPods List call as FetchPodNameList, so no extra API request is made.
  • pkg/interruptionevent/draincordon: the handler fetches pod details once and sets both Pods (unchanged) and PodDetails from that result.
  • pkg/monitor: add PodDetails []node.PodDetail to InterruptionEvent, tagged json:"-". The event is logged with Interface("event", ...) when handling fails, so this keeps pod annotations out of the logs. Templates still see the field.
  • OwnerKind is the kind of the pod's controller (metav1.GetControllerOf), or "" for a bare pod. Expose pod details (namespace, phase, owner, labels, annotations) to the webhook template #1288 proposed the first owner reference; the controller reference is more precise when a pod has non-controller owners.
  • Pods, LogPods and the default template are unchanged, so existing templates render the same as before.

Example: running workload pods only.

{{ range .PodDetails }}
{{- if and (eq .Phase "Running") (ne .OwnerKind "DaemonSet") }}
{{ .Namespace }}/{{ .Name }} {{ index .Annotations "example.com/owner" }}
{{ end }}{{ end }}

How you tested your changes:

  • New unit tests:
    • TestFetchPodDetails covers field mapping, a controller owner and a non-controller owner.
    • TestPodNames.
    • TestHandleEvent_PopulatesPodDetails checks that the handler sets Pods and PodDetails.
    • TestPostPodDetails filters by phase and owner and reads labels and annotations in a template.
    • TestInterruptionEventJSONOmitsPodDetails.
  • go test ./... passes.
  • e2e: test/e2e/webhook-test now ranges over .PodDetails in its template. If the field couldn't be rendered, template execution would fail and the test's Webhook Success assertion would not pass. I checked the escaped --set value with helm template, but I didn't run the kind-based e2e suite locally.

Environment (Linux / Windows): macOS (darwin/arm64), unit tests only
Kubernetes Version: client-go fake clientset (k8s.io/client-go v0.30.4)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Add PodDetails to the webhook template data: namespace, phase, controller
kind, labels and annotations for each pod on the node. It is filled from
the same pod List call as Pods, so no extra API request is made. Pods and
the default template are unchanged.

PodDetails is excluded from JSON so pod annotations do not end up in the
event logs.
@zhan9san
zhan9san requested a review from a team as a code owner October 29, 2026 06:03
@zhan9san

Copy link
Copy Markdown
Author

@LikithaVemulapalli

Could you plz help review this PR?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose pod details (namespace, phase, owner, labels, annotations) to the webhook template

1 participant