Skip to content

Commit

Permalink
fix ipv6 service ip not added to ovn lb vips due to pod cache not syn…
Browse files Browse the repository at this point in the history
…ced (#4223)

Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored and bobz965 committed Jul 22, 2024
1 parent f873ea8 commit 2b5fd83
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
24 changes: 24 additions & 0 deletions pkg/controller/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
klog.Errorf("failed to get pods for service %s in namespace %s: %v", name, namespace, err)
return err
}
for i, pod := range pods {
if pod.Status.PodIP != "" || len(pod.Status.PodIPs) != 0 {
continue
}

for _, subset := range ep.Subsets {
for _, addr := range subset.Addresses {
if addr.TargetRef == nil || addr.TargetRef.Kind != "Pod" || addr.TargetRef.Name != pod.Name {
continue
}

p, err := c.config.KubeClient.CoreV1().Pods(pod.Namespace).Get(context.Background(), pod.Name, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get pod %s/%s: %v", pod.Namespace, pod.Name, err)
return err
}
pods[i] = p.DeepCopy()
break
}
if pods[i] != pod {
break
}
}
}

vpcName, subnetName = c.getVpcSubnetName(pods, ep, svc)

Expand Down
7 changes: 1 addition & 6 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,7 @@ func (c *Controller) gcLoadBalancer() error {
)

for _, svc := range svcs {
ips := util.ServiceClusterIPs(*svc)
if v, ok := svc.Annotations[util.SwitchLBRuleVipsAnnotation]; ok {
ips = strings.Split(v, ",")
}

for _, ip := range ips {
for _, ip := range getVipIps(svc) {
for _, port := range svc.Spec.Ports {
vip := util.JoinHostPort(ip, port.Port)
switch port.Protocol {
Expand Down
8 changes: 3 additions & 5 deletions pkg/controller/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,9 @@ func (c *Controller) handleUpdateService(key string) error {
return err
}

if !needUpdateEndpointQueue {
if _, ok := lb.Vips[vip]; !ok {
klog.Infof("add vip %s to LB %s", vip, lbName)
needUpdateEndpointQueue = true
}
if _, ok := lb.Vips[vip]; !ok {
klog.Infof("add vip %s to LB %s", vip, lbName)
needUpdateEndpointQueue = true
}
}
for vip := range lb.Vips {
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/kube-ovn/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,18 @@ var _ = framework.Describe("[group:service]", func() {
selector := map[string]string{"app": "svc-dual"}
service := framework.MakeService(serviceName, corev1.ServiceTypeClusterIP, nil, selector, ports, corev1.ServiceAffinityNone)
service.Namespace = namespaceName
service.Spec.IPFamilyPolicy = ptr.To(corev1.IPFamilyPolicyRequireDualStack)
service = serviceClient.CreateSync(service, func(s *corev1.Service) (bool, error) {
return len(s.Spec.ClusterIPs) != 0, nil
}, "cluster ips are not empty")
return len(util.ServiceClusterIPs(*s)) == 2, nil
}, "both ipv4 and ipv6 cluster ips are allocated")
v6ClusterIP := service.Spec.ClusterIPs[1]
originService := service.DeepCopy()
framework.Logf("created service %s with cluster ips %s", serviceName, strings.Join(util.ServiceClusterIPs(*service), ","))

ginkgo.By("Creating pod " + podName)
podBackend := framework.MakePod(namespaceName, podName, selector, nil, framework.PauseImage, nil, nil)
_ = podClient.CreateSync(podBackend)
podBackend = podClient.CreateSync(podBackend)
framework.Logf("created pod %s with ips %s", podName, strings.Join(util.PodIPs(*podBackend), ","))

checkContainsClusterIP := func(v6ClusterIP string, isContain bool) {
ginkgo.GinkgoHelper()
Expand Down

0 comments on commit 2b5fd83

Please sign in to comment.