Skip to content

Commit 2cdc405

Browse files
gcs278claude
andcommitted
Fix race condition in internal-to-external LB migration test
When migrating from internal to external scope, use the Service LB address directly instead of DNSRecord target to avoid race condition where IngressController reports DNSReady before DNSRecord reconciles. Also add header comments to DNS migration tests for consistency. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 3c1da4b commit 2cdc405

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

test/e2e/unmanaged_dns_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ var operatorProgressingFalse = operatorv1.OperatorCondition{
3131
Type: operatorv1.OperatorStatusTypeProgressing, Status: operatorv1.ConditionFalse,
3232
}
3333

34+
// TestUnmanagedDNSToManagedDNSIngressController tests dnsManagementPolicy during
35+
// transitioning from Unmanaged to Managed DNS on an external ingress controller.
36+
// The load balancer scope remains external throughout the transition, so only the
37+
// DNS management policy changes.
3438
func TestUnmanagedDNSToManagedDNSIngressController(t *testing.T) {
3539
t.Parallel()
3640

@@ -107,6 +111,10 @@ func TestUnmanagedDNSToManagedDNSIngressController(t *testing.T) {
107111
verifyExternalIngressController(t, testPodName, "apps."+ic.Spec.Domain, wildcardRecord.Spec.Targets[0])
108112
}
109113

114+
// TestManagedDNSToUnmanagedDNSIngressController tests dnsManagementPolicy during
115+
// transitioning from Managed to Unmanaged DNS on an external ingress controller.
116+
// The load balancer scope remains external throughout the transition, so only the
117+
// DNS management policy changes.
110118
func TestManagedDNSToUnmanagedDNSIngressController(t *testing.T) {
111119
t.Parallel()
112120

@@ -277,8 +285,9 @@ func TestUnmanagedDNSToManagedDNSInternalIngressController(t *testing.T) {
277285
}
278286

279287
// Ensure the service's load-balancer status changes.
280-
err := wait.PollImmediate(10*time.Second, 5*time.Minute, func() (bool, error) {
281-
lbService := &corev1.Service{}
288+
lbService = &corev1.Service{}
289+
var lbAddress string
290+
err := wait.PollUntilContextTimeout(context.Background(), 10*time.Second, 5*time.Minute, true, func(ctx context.Context) (bool, error) {
282291
if err := kclient.Get(context.TODO(), controller.LoadBalancerServiceName(ic), lbService); err != nil {
283292
t.Logf("Get %q failed: %v, retrying ...", controller.LoadBalancerServiceName(ic), err)
284293
return false, nil
@@ -290,6 +299,14 @@ func TestUnmanagedDNSToManagedDNSInternalIngressController(t *testing.T) {
290299
// The service got updated, but is not external.
291300
return true, fmt.Errorf("load balancer %s is internal but should be external", lbService.Name)
292301
}
302+
if len(lbService.Status.LoadBalancer.Ingress) == 0 {
303+
t.Logf("service %s has no load balancer ingress, retrying...", lbService.Name)
304+
return false, nil
305+
}
306+
lbAddress = lbService.Status.LoadBalancer.Ingress[0].IP
307+
if lbAddress == "" {
308+
lbAddress = lbService.Status.LoadBalancer.Ingress[0].Hostname
309+
}
293310
return true, nil
294311
})
295312
if err != nil {
@@ -316,8 +333,12 @@ func TestUnmanagedDNSToManagedDNSInternalIngressController(t *testing.T) {
316333
t.Fatalf("DNSRecord %s expected allocated dnsZones but found none", wildcardRecordName.Name)
317334
}
318335

336+
// Use lbAddress from the service instead of wildcardRecord.Spec.Targets[0] because when migrating
337+
// from internal to external scope, the IngressController may report DNSReady=True (causing
338+
// waitForIngressControllerCondition to pass) before the ingress-operator has reconciled the DNSRecord
339+
// with the new external load balancer address.
319340
testPodName = types.NamespacedName{Name: name.Name + "-final", Namespace: testPodNamespace.Name}
320-
verifyExternalIngressController(t, testPodName, "apps."+ic.Spec.Domain, wildcardRecord.Spec.Targets[0])
341+
verifyExternalIngressController(t, testPodName, "apps."+ic.Spec.Domain, lbAddress)
321342
}
322343

323344
func verifyUnmanagedDNSRecordStatus(t *testing.T, record *iov1.DNSRecord) {

0 commit comments

Comments
 (0)