Change:
When using PDBs with or (percentage), it is not supported to reference pods via a PDB selector, that do not have a supported controller owner reference: Deployment, ReplicationController, ReplicaSet, and StatefulSet controllers or a resource implementing subresource This is also documented Nevertheless, there are still people who create PDBs a pods without controllers that ignore this. For example PDBs that set , want to block eviction, and node drain (it works for them but the PDB status is invalid). Unfortunately there is no feedback for the user to receive when this happens. The KCM logs is the only place that informs the user when unmanaged pods are found. Which I think is insufficient. There should be some way to inform users about this. Since it cannot be know on admission we probably have to do it when reconciling the PDB and unmanaged pods are found. Options: an event when this is detected - probably needs to be throttled in some way a condition in a PDB status that would be set and admins could monitor these to detect misbehaving PDBs create a PDB create unmanaged pod observe incorrect status because this configuration is unsupported No response <detailsNA </details<detailsNA </details<detailsNA </details<details</details<details</details<details</details
/sig apps
/triage accepted This was discussed during today's sig-apps, we've agreed to add a warning event right next to the log statement from the original description
I'll take this on.
/assign
/reopen I did some more testing for the unsupported controllers and found out that these are covered by the event, so I posted a followup to reflect that The new event should cover only the naked pods
Reopened this issue. <detailsIn response to : /reopen Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details

Discussion:
import ( "context" "fmt" <del> "strings" </del> "time" apps "k8s.io/api/apps/v1beta1"

} // We have unmamanged pods, instead of erroring and hotlooping in disruption controller, log and continue. if len(unmanagedPods) > 0 { <del> klog.V(4).Infof("found unmanaged pods associated with this PDB: %v", strings.Join(unmanagedPods, ",'")) </del> <ins> klog.V(4).Infof("found unmanaged pods associated with this PDB: %v", unmanagedPods) dc.recorder.Eventf(pdb, v1.EventTypeWarning, "UnmanagedPods", "Pods selected by this PodDisruptionBudget (selector: %v) were found "+ "to be unmanaged or managed by an unsupported controller (missing a /scale subresource). As a result, the status of the PDB "+ "cannot be calculated correctly, which may result in undefined behavior. To account for these pods please set ".spec.minAvailable" "+ "field of the PDB to an integer value.", pdb.Spec.Selector) </ins> } currentTime := dc.clock.Now()

scalefake "k8s.io/client-go/scale/fake" core "k8s.io/client-go/testing" "k8s.io/client-go/tools/cache" <ins> "k8s.io/client-go/tools/record" </ins> "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" _ "k8s.io/kubernetes/pkg/apis/core/install"

dc.rsListerSynced = alwaysReady dc.dListerSynced = alwaysReady dc.ssListerSynced = alwaysReady <ins> dc.recorder = record.NewFakeRecorder(10) </ins> informerFactory.Start(ctx.Done()) informerFactory.WaitForCacheSync(ctx.Done())

dc.sync(ctx, pdbName) ps.VerifyDisruptionAllowed(t, pdbName, 0) <ins> verifyUnsupportedControllerEventEmitted(t, dc) </ins> } // Verify that an integer MaxUnavailable will recompute allowed disruptions when the scale of

dc.sync(ctx, pdbName) ps.VerifyDisruptionAllowed(t, pdbName, 0) <ins> verifyUnsupportedControllerEventEmitted(t, dc) </ins> } // Verify that disruption controller is not erroring when unmanaged pods are found

pod, _ := newPod(t, "unmanaged") add(t, dc.podStore, pod) dc.sync(ctx, pdbName) ps.VerifyNoStatusError(t, pdbName) <ins> verifyUnsupportedControllerEventEmitted(t, dc) </ins> } // Check if the unmanaged pods are correctly collected or not

t.Fatalf("expected one pod to be unmanaged pod but found %d", len(unmanagedPods)) } ps.VerifyNoStatusError(t, pdbName) <ins> verifyUnsupportedControllerEventEmitted(t, dc) </ins> } // Verify that we count the scale of a ReplicaSet even when it has no Deployment.

}) } <ins> func verifyUnsupportedControllerEventEmitted(t *testing.T, dc *disruptionController) { // Verify that an UnmanagedPod event is generated found := false for e := range dc.recorder.(*record.FakeRecorder).Events { if strings.Contains(e, "managed by an unsupported controller") { found = true break } } if !found { t.Fatalf("UnmanagedPod event not generated") } } </ins> // TestMain adds klog flags to make debugging tests easier. func TestMain(m *testing.M) { klog.InitFlags(flag.CommandLine)