Skip to content

Commit 45a4c1c

Browse files
committed
e2e: Improve detection of missing DNSRecord for Gateway
- Add more logs to DNSRecord ensuring logic - Ensure the `Programmed` condition is checked on the Gateway resource
1 parent 6fe4db1 commit 45a4c1c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

pkg/resources/dnsrecord/dns.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ func EnsureDNSRecord(client client.Client, name types.NamespacedName, dnsRecordL
8383
if updated, err := updateDNSRecord(client, current, desired); err != nil {
8484
return true, current, fmt.Errorf("failed to update dnsrecord %s/%s: %v", desired.Namespace, desired.Name, err)
8585
} else if updated {
86+
log.Info("updated dnsrecord", "dnsrecord", desired)
8687
return CurrentDNSRecord(client, name)
8788
}
8889
}
90+
log.Info("no desired dnsrecord")
8991

9092
return haveWC, current, nil
9193
}
@@ -130,6 +132,7 @@ func desiredWildcardDNSRecord(name types.NamespacedName, dnsRecordLabels map[str
130132
func desiredDNSRecord(name types.NamespacedName, dnsRecordLabels map[string]string, ownerRef metav1.OwnerReference, domain string, dnsPolicy iov1.DNSManagementPolicy, service *corev1.Service) (bool, *iov1.DNSRecord) {
131133
// No LB target exists for the domain record to point at.
132134
if len(service.Status.LoadBalancer.Ingress) == 0 {
135+
log.Info("no load balancer target for dnsrecord", "dnsrecord", name, "service", service.Name)
133136
return false, nil
134137
}
135138

@@ -138,6 +141,7 @@ func desiredDNSRecord(name types.NamespacedName, dnsRecordLabels map[string]stri
138141
// Quick sanity check since we don't know how to handle both being set (is
139142
// that even a valid state?)
140143
if len(ingress.Hostname) > 0 && len(ingress.IP) > 0 {
144+
log.Info("no load balancer hostname or IP for dnsrecord", "dnsrecord", name, "service", service.Name)
141145
return false, nil
142146
}
143147

test/e2e/util_gatewayapi_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,27 +562,39 @@ func assertGatewaySuccessful(t *testing.T, namespace, name string) (*gatewayapiv
562562

563563
gw := &gatewayapiv1.Gateway{}
564564
nsName := types.NamespacedName{Namespace: namespace, Name: name}
565-
recordedConditionMsg := "not found"
565+
recordedAcceptedConditionMsg, recordedProgrammedConditionMsg := "not found", "not found"
566566

567567
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 1*time.Minute, false, func(context context.Context) (bool, error) {
568568
if err := kclient.Get(context, nsName, gw); err != nil {
569569
t.Logf("Failed to get gateway %v: %v; retrying...", nsName, err)
570570
return false, nil
571571
}
572+
acceptedConditionFound, programmedConditionFound := false, false
572573
for _, condition := range gw.Status.Conditions {
573574
if condition.Type == string(gatewayapiv1.GatewayConditionAccepted) {
574-
recordedConditionMsg = condition.Message
575+
recordedAcceptedConditionMsg = condition.Message
575576
if condition.Status == metav1.ConditionTrue {
576577
t.Logf("Found gateway %v as Accepted", nsName)
577-
return true, nil
578+
acceptedConditionFound = true
579+
}
580+
}
581+
if condition.Type == string(gatewayapiv1.GatewayConditionProgrammed) {
582+
recordedProgrammedConditionMsg = condition.Message
583+
if condition.Status == metav1.ConditionTrue {
584+
t.Logf("Found gateway %v as Programmed", nsName)
585+
programmedConditionFound = true
578586
}
579587
}
580588
}
589+
if acceptedConditionFound && programmedConditionFound {
590+
return true, nil
591+
}
592+
t.Logf("Not all expected gateway conditions are found, retrying...")
581593
return false, nil
582594
})
583595
if err != nil {
584596
t.Logf("Last observed gateway:\n%s", util.ToYaml(gw))
585-
return nil, fmt.Errorf("gateway %v not %v, last recorded status message: %s", nsName, gatewayapiv1.GatewayConditionAccepted, recordedConditionMsg)
597+
return nil, fmt.Errorf("gateway %v does not have all expected conditions, last recorded status messages: %q, %q", nsName, recordedAcceptedConditionMsg, recordedProgrammedConditionMsg)
586598
}
587599

588600
t.Logf("Observed that gateway %v has been accepted: %+v", nsName, gw.Status)
@@ -851,21 +863,21 @@ func assertDNSRecord(t *testing.T, recordName types.NamespacedName) error {
851863

852864
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 1*time.Minute, false, func(context context.Context) (bool, error) {
853865
if err := kclient.Get(context, recordName, dnsRecord); err != nil {
854-
t.Logf("Failed to get DNSRecord %v: %v; retrying...", recordName, err)
866+
t.Logf("[%s] Failed to get DNSRecord %v: %v; retrying...", time.Now().Format(time.DateTime), recordName, err)
855867
return false, nil
856868
}
857869
// Determine the current state of the DNSRecord.
858870
if len(dnsRecord.Status.Zones) > 0 {
859871
for _, zone := range dnsRecord.Status.Zones {
860872
for _, condition := range zone.Conditions {
861873
if condition.Type == v1.DNSRecordPublishedConditionType && condition.Status == string(metav1.ConditionTrue) {
862-
t.Logf("Found DNSRecord %v %s=%s", recordName, condition.Type, condition.Status)
874+
t.Logf("[%s] Found DNSRecord %v %s=%s", time.Now().Format(time.DateTime), recordName, condition.Type, condition.Status)
863875
return true, nil
864876
}
865877
}
866878
}
867879
}
868-
t.Logf("Found DNSRecord %v but could not determine its readiness; retrying...", recordName)
880+
t.Logf("[%s] Found DNSRecord %v but could not determine its readiness; retrying...", time.Now().Format(time.DateTime), recordName)
869881
return false, nil
870882
})
871883
return err

0 commit comments

Comments
 (0)