Skip to content

🐛 Skip draining failed DaemonSet pods to prevent recreation loops #12640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions internal/controllers/machine/drain/drain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestGetPodsForEviction(t *testing.T) {
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-2-delete-succeeded-daemonset-pod",
Name: "pod-2-skip-succeeded-daemonset-pod",
Namespace: metav1.NamespaceDefault,
OwnerReferences: []metav1.OwnerReference{
{
Expand All @@ -283,7 +283,22 @@ func TestGetPodsForEviction(t *testing.T) {
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-3-delete-orphaned-daemonset-pod",
Name: "pod-3-skip-failed-daemonset-pod",
Namespace: metav1.NamespaceDefault,
OwnerReferences: []metav1.OwnerReference{
{
Kind: "DaemonSet",
Controller: ptr.To(true),
},
},
},
Status: corev1.PodStatus{
Phase: corev1.PodFailed,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-4-delete-orphaned-daemonset-pod",
Namespace: metav1.NamespaceDefault,
OwnerReferences: []metav1.OwnerReference{
{
Expand All @@ -299,7 +314,7 @@ func TestGetPodsForEviction(t *testing.T) {
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-4-skip-daemonset-pod",
Name: "pod-5-skip-daemonset-pod",
Namespace: metav1.NamespaceDefault,
OwnerReferences: []metav1.OwnerReference{
{
Expand Down Expand Up @@ -332,21 +347,7 @@ func TestGetPodsForEviction(t *testing.T) {
{
Pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-2-delete-succeeded-daemonset-pod",
Namespace: metav1.NamespaceDefault,
},
},
// Delete this DaemonSet Pod because it is succeeded.
Status: PodDeleteStatus{
DrainBehavior: clusterv1.MachineDrainRuleDrainBehaviorDrain,
DrainOrder: ptr.To[int32](0),
Reason: PodDeleteStatusTypeOkay,
},
},
{
Pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-3-delete-orphaned-daemonset-pod",
Name: "pod-4-delete-orphaned-daemonset-pod",
Namespace: metav1.NamespaceDefault,
},
},
Expand All @@ -361,7 +362,7 @@ func TestGetPodsForEviction(t *testing.T) {
{
Pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-4-skip-daemonset-pod",
Name: "pod-5-skip-daemonset-pod",
Namespace: metav1.NamespaceDefault,
},
},
Expand Down
4 changes: 0 additions & 4 deletions internal/controllers/machine/drain/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ func (d *Helper) daemonSetFilter(ctx context.Context, pod *corev1.Pod) PodDelete
if controllerRef == nil || controllerRef.Kind != appsv1.SchemeGroupVersion.WithKind("DaemonSet").Kind {
return MakePodDeleteStatusOkay()
}
// Any finished pod can be removed.
if pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed {
return MakePodDeleteStatusOkay()
}

if err := d.RemoteClient.Get(ctx, client.ObjectKey{Namespace: pod.Namespace, Name: controllerRef.Name}, &appsv1.DaemonSet{}); err != nil {
// remove orphaned pods with a warning
Expand Down