backend: Skip DaemonSet pods during drain#5690
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the backend node drain logic to correctly skip DaemonSet-owned pods by detecting DaemonSet ownership via pod ownerReferences (while retaining the legacy kubernetes.io/created-by=daemonset-controller label check), aligning Headlamp’s drain behavior with modern Kubernetes semantics.
Changes:
- Added
isDaemonSetPodhelper to identify DaemonSet pods via legacy label andownerReferences.kind == "DaemonSet". - Updated
drainNodeto use the helper to skip DaemonSet pods during deletion. - Extended drain tests to validate deletion behavior and introduced a helper to extract deleted pod names from fake client actions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
backend/cmd/headlamp.go |
Adds DaemonSet pod detection helper and uses it to skip DaemonSet pods during node drain. |
backend/cmd/headlamp_test.go |
Updates drain tests and adds a helper to assert which pods were deleted. |
illume
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.
32a374f to
8f6fc4d
Compare
@illume |
8f6fc4d to
3f0cec4
Compare
illume
left a comment
There was a problem hiding this comment.
Sorry, noticed these two functions are missing some documentation. Could you please add it?
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: harrshita123 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Yeah sure . |
Detect DaemonSet-owned pods by owner reference so node drain does not try to delete pods that should be ignored.
3f0cec4 to
d868d57
Compare
|
@illume Added docs for both helper functions and force-pushed the branch as a single commit: |
| // It supports both the legacy daemonset-controller label and modern owner references. | ||
| func isDaemonSetPod(pod corev1.Pod) bool { | ||
| if pod.Labels["kubernetes.io/created-by"] == "daemonset-controller" { | ||
| return true | ||
| } | ||
|
|
||
| for _, owner := range pod.OwnerReferences { | ||
| if owner.Kind == "DaemonSet" && (owner.APIVersion == "" || strings.HasPrefix(owner.APIVersion, "apps/")) { |
Summary
This PR fixes backend node drain behavior so DaemonSet-owned pods are skipped even when they do not have the legacy
kubernetes.io/created-by=daemonset-controllerlabel.Related Issue
Fixes #5687
Changes
Steps to Test
cd backend && go test ./cmd -run 'TestDrainNodePodDeletionFailure|TestDrainNodeAllPodsDeletedSuccessfully'.cd backend && go test ./cmd.npm run backend:lint.Screenshots (if applicable)
Not applicable. This is a backend node drain change.
Notes for the Reviewer
The change is limited to the backend drain loop. It does not change how regular pods are deleted during drain; it only avoids deleting pods owned by DaemonSets.