diff --git a/pkg/controller/podunavailablebudget/pub_pod_event_handler.go b/pkg/controller/podunavailablebudget/pub_pod_event_handler.go index d4a6b2c64c..f0e83162bb 100644 --- a/pkg/controller/podunavailablebudget/pub_pod_event_handler.go +++ b/pkg/controller/podunavailablebudget/pub_pod_event_handler.go @@ -100,8 +100,6 @@ func GetPubForPod(c client.Client, pod *corev1.Pod) (*policyv1alpha1.PodUnavaila workload, err := controllerfinder.Finder.GetScaleAndSelectorForRef(ref.APIVersion, ref.Kind, pod.Namespace, ref.Name, "") if err != nil { return nil, err - } else if workload == nil { - return nil, nil } pubList := &policyv1alpha1.PodUnavailableBudgetList{} if err = c.List(context.TODO(), pubList, &client.ListOptions{Namespace: pod.Namespace}, utilclient.DisableDeepCopy); err != nil { @@ -110,7 +108,7 @@ func GetPubForPod(c client.Client, pod *corev1.Pod) (*policyv1alpha1.PodUnavaila for i := range pubList.Items { pub := &pubList.Items[i] // if targetReference isn't nil, priority to take effect - if pub.Spec.TargetReference != nil { + if pub.Spec.TargetReference != nil && workload != nil { // belongs the same workload if pubcontrol.IsReferenceEqual(&policyv1alpha1.TargetReference{ APIVersion: workload.APIVersion,