Repository navigation
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.
Author
|
Could you plz help review this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.