Skip to content

Commit 138fc5f

Browse files
committed
fix kube-ovn-controller crash on startup (#2305)
1 parent 50b0c86 commit 138fc5f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/controller/network_policy.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,20 @@ func isSvcMatchPod(svc *corev1.Service, pod *corev1.Pod) (bool, error) {
804804
}
805805

806806
func (c *Controller) podMatchNetworkPolicies(pod *corev1.Pod) []string {
807-
podNs, _ := c.namespacesLister.Get(pod.Namespace)
808-
nps, _ := c.npsLister.NetworkPolicies(corev1.NamespaceAll).List(labels.Everything())
807+
podNs, err := c.namespacesLister.Get(pod.Namespace)
808+
if err != nil {
809+
klog.Errorf("failed to get namespace %s: %v", pod.Namespace, err)
810+
utilruntime.HandleError(err)
811+
return nil
812+
}
813+
814+
nps, err := c.npsLister.NetworkPolicies(corev1.NamespaceAll).List(labels.Everything())
815+
if err != nil {
816+
klog.Errorf("failed to list network policies: %v", err)
817+
utilruntime.HandleError(err)
818+
return nil
819+
}
820+
809821
match := []string{}
810822
for _, np := range nps {
811823
if isPodMatchNetworkPolicy(pod, *podNs, np, np.Namespace) {

0 commit comments

Comments
 (0)