Skip to content

Commit

Permalink
fix kube-ovn-controller crash on startup (#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Feb 8, 2023
1 parent a1e8e40 commit b9d58b4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/controller/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,20 @@ func isSvcMatchPod(svc *corev1.Service, pod *corev1.Pod) (bool, error) {
}

func (c *Controller) podMatchNetworkPolicies(pod *corev1.Pod) []string {
podNs, _ := c.namespacesLister.Get(pod.Namespace)
nps, _ := c.npsLister.NetworkPolicies(corev1.NamespaceAll).List(labels.Everything())
podNs, err := c.namespacesLister.Get(pod.Namespace)
if err != nil {
klog.Errorf("failed to get namespace %s: %v", pod.Namespace, err)
utilruntime.HandleError(err)
return nil
}

nps, err := c.npsLister.NetworkPolicies(corev1.NamespaceAll).List(labels.Everything())
if err != nil {
klog.Errorf("failed to list network policies: %v", err)
utilruntime.HandleError(err)
return nil
}

match := []string{}
for _, np := range nps {
if isPodMatchNetworkPolicy(pod, *podNs, np, np.Namespace) {
Expand Down

0 comments on commit b9d58b4

Please sign in to comment.