Skip to content

Commit 782c16c

Browse files
authored
k8s-operator: reset service status before append (tailscale#17120)
This commit fixes an issue within the service reconciler where we end up in a constant reconciliation loop. When reconciling, the loadbalancer status is appended to but not reset between each reconciliation, leading to an ever growing slice of duplicate statuses. Fixes tailscale#17105 Fixes tailscale#17107 Signed-off-by: David Bond <[email protected]>
1 parent 7d2101f commit 782c16c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cmd/k8s-operator/operator_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func TestLoadBalancerClass(t *testing.T) {
173173
},
174174
},
175175
}
176+
177+
// Perform an additional reconciliation loop here to ensure resources don't change through side effects. Mainly
178+
// to prevent infinite reconciliation
179+
expectReconciled(t, sr, "default", "test")
176180
expectEqual(t, fc, want)
177181

178182
// Turn the service back into a ClusterIP service, which should make the

cmd/k8s-operator/svc.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,10 @@ func (a *ServiceReconciler) maybeProvision(ctx context.Context, logger *zap.Suga
348348

349349
dev := devices[0]
350350
logger.Debugf("setting Service LoadBalancer status to %q, %s", dev.hostname, strings.Join(dev.ips, ", "))
351-
svc.Status.LoadBalancer.Ingress = append(svc.Status.LoadBalancer.Ingress, corev1.LoadBalancerIngress{
352-
Hostname: dev.hostname,
353-
})
351+
352+
ingress := []corev1.LoadBalancerIngress{
353+
{Hostname: dev.hostname},
354+
}
354355

355356
clusterIPAddr, err := netip.ParseAddr(svc.Spec.ClusterIP)
356357
if err != nil {
@@ -365,10 +366,11 @@ func (a *ServiceReconciler) maybeProvision(ctx context.Context, logger *zap.Suga
365366
continue
366367
}
367368
if addr.Is4() == clusterIPAddr.Is4() { // only add addresses of the same family
368-
svc.Status.LoadBalancer.Ingress = append(svc.Status.LoadBalancer.Ingress, corev1.LoadBalancerIngress{IP: ip})
369+
ingress = append(ingress, corev1.LoadBalancerIngress{IP: ip})
369370
}
370371
}
371372

373+
svc.Status.LoadBalancer.Ingress = ingress
372374
tsoperator.SetServiceCondition(svc, tsapi.ProxyReady, metav1.ConditionTrue, reasonProxyCreated, reasonProxyCreated, a.clock, logger)
373375
return nil
374376
}

0 commit comments

Comments
 (0)