Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ipv6 service ip not added to ovn lb vips due to pod cache not synced #4223

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -495,12 +495,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
Loading