Repository navigation
Expose pod details to the webhook template - #1289
Conversation
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.
|
Could you plz help review this PR? |
LikithaVemulapalli
left a comment
There was a problem hiding this comment.
Overall looks good, added some minor comments, will enable the PR tests to see if the change runs successfully on all the k8s versions that we have in our e2e tests. Thanks for owning the fix :)
| Labels map[string]string | ||
| Annotations map[string]string |
There was a problem hiding this comment.
Exposing full label/annotation maps is fine since the template opts in and the default template is unchanged, but annotations can hold sensitive data (e.g. last-applied-configuration). Add a docs caveat to select specific keys rather than dumping whole maps. The json:"-" keeping them out of logs is good.
There was a problem hiding this comment.
Added a "Webhook Template" section to the chart README listing the .PodDetails fields, with a caveat to select specific keys via index .Annotations "key" rather than rendering whole maps, since annotations like last-applied-configuration can carry sensitive data. Also noted it on the Annotations field.
There was a problem hiding this comment.
FetchPodNameList now has no in-repo caller, remove it or reimplement as PodNames(FetchPodDetails(...)).
There was a problem hiding this comment.
Removed it along with its test; the handler derives names via PodNames(FetchPodDetails(...)), and TestFetchPodDetails/TestPodNames cover that path.
Add a Webhook Template section to the chart README listing the .PodDetails fields, with a caveat to select specific annotation keys rather than rendering whole maps, since annotations such as last-applied-configuration can hold sensitive data. Remove FetchPodNameList, which no longer has a caller; the handler derives pod names from FetchPodDetails.
|
@LikithaVemulapalli Thanks for the review! Both comments are addressed in 7bb07c5. Could you approve the workflow run for the new commit, and add the |
|
@LikithaVemulapalli thanks for your help May I ask when we can have a new release for this? |
Issue #, if available: Fixes #1288
Description of changes:
What
Adds a
PodDetailsfield 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
Podsonly 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 aPodDetailtype,FetchPodDetailsand aPodNameshelper.FetchPodDetailsuses the samefetchAllPodsList call asFetchPodNameList, so no extra API request is made.pkg/interruptionevent/draincordon: the handler fetches pod details once and sets bothPods(unchanged) andPodDetailsfrom that result.pkg/monitor: addPodDetails []node.PodDetailtoInterruptionEvent, taggedjson:"-". The event is logged withInterface("event", ...)when handling fails, so this keeps pod annotations out of the logs. Templates still see the field.OwnerKindis 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,LogPodsand the default template are unchanged, so existing templates render the same as before.Example: running workload pods only.
How you tested your changes:
TestFetchPodDetailscovers field mapping, a controller owner and a non-controller owner.TestPodNames.TestHandleEvent_PopulatesPodDetailschecks that the handler setsPodsandPodDetails.TestPostPodDetailsfilters by phase and owner and reads labels and annotations in a template.TestInterruptionEventJSONOmitsPodDetails.go test ./...passes.test/e2e/webhook-testnow ranges over.PodDetailsin its template. If the field couldn't be rendered, template execution would fail and the test'sWebhook Successassertion would not pass. I checked the escaped--setvalue withhelm 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.