Skip to content

Commit c03350c

Browse files
oilbeaterclaude
andcommitted
fix(e2e): wait for DNSNameResolver CR creation instead of status population
The dnsnameresolver CoreDNS plugin populates Status.ResolvedNames reactively (only when actual DNS queries flow through CoreDNS), not proactively. The previous waitForDNSResolversReady checked for non-empty Status.ResolvedNames before any connectivity test, creating a deadlock: no DNS query happens → Status never populated → 60s timeout → test fails. Replace with waitForDNSResolversCreated that only verifies the CR exists, ensuring the controller has processed the CNP. The connectivity retry logic (30 attempts × 3s) naturally handles the async chain: DNS query → plugin intercepts → Status updated → address set updated → ACL applied. Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent c455a53 commit c03350c

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

test/e2e/cnp-domain/e2e_test.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/onsi/ginkgo/v2"
1313
corev1 "k8s.io/api/core/v1"
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15-
"k8s.io/apimachinery/pkg/util/wait"
1615
clientset "k8s.io/client-go/kubernetes"
1716
"k8s.io/klog/v2"
1817
"k8s.io/kubernetes/test/e2e"
@@ -115,27 +114,29 @@ var _ = framework.SerialDescribe("[group:cluster-network-policy]", func() {
115114
testNetworkConnectivityWithRetry(target, shouldSucceed, description, 30, 3*time.Second)
116115
}
117116

118-
// waitForDNSResolversReady waits for all DNSNameResolver CRs associated with a CNP
119-
// to be created and have at least one resolved address. This ensures the OVN ACL
120-
// address sets are populated before connectivity checks.
121-
waitForDNSResolversReady := func(name string, expectedCount int) {
122-
ginkgo.By(fmt.Sprintf("Waiting for %d DNSNameResolver(s) to be ready for CNP %s", expectedCount, name))
117+
// waitForDNSResolversCreated waits for DNSNameResolver CRs associated with a CNP
118+
// to be created. This ensures the controller has processed the CNP and created the
119+
// DNSNameResolver CRs, so the CoreDNS dnsnameresolver plugin can intercept DNS
120+
// queries for the configured domains.
121+
// Note: We intentionally do NOT check Status.ResolvedNames here because the
122+
// dnsnameresolver CoreDNS plugin populates it reactively (only when actual DNS
123+
// queries flow through CoreDNS), not proactively. The connectivity retry logic
124+
// in testNetworkConnectivity handles the async chain:
125+
// DNS query → plugin intercepts → Status updated → address set updated → ACL applied.
126+
waitForDNSResolversCreated := func(name string, expectedCount int) {
127+
ginkgo.By(fmt.Sprintf("Waiting for %d DNSNameResolver(s) to be created for CNP %s", expectedCount, name))
123128
dnsClient := f.DNSNameResolverClient()
124129
labelSelector := fmt.Sprintf("anp=%s", name)
125130

126-
err := wait.PollUntilContextTimeout(context.TODO(), 2*time.Second, 60*time.Second, true, func(_ context.Context) (bool, error) {
131+
framework.WaitUntil(2*time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
127132
resolverList := dnsClient.ListByLabel(labelSelector)
128133
if len(resolverList.Items) < expectedCount {
134+
framework.Logf("Found %d/%d DNSNameResolver(s) for CNP %s", len(resolverList.Items), expectedCount, name)
129135
return false, nil
130136
}
131-
for _, resolver := range resolverList.Items {
132-
if len(resolver.Status.ResolvedNames) == 0 {
133-
return false, nil
134-
}
135-
}
137+
framework.Logf("All %d DNSNameResolver(s) created for CNP %s", expectedCount, name)
136138
return true, nil
137-
})
138-
framework.ExpectNoError(err, "DNSNameResolvers for CNP %s failed to be ready within timeout", name)
139+
}, fmt.Sprintf("DNSNameResolvers for CNP %s to be created", name))
139140
}
140141

141142
framework.ConformanceIt("should create CNP with domainName deny rule and verify connectivity behavior", func() {
@@ -182,7 +183,7 @@ var _ = framework.SerialDescribe("[group:cluster-network-policy]", func() {
182183
framework.ExpectEqual(cnp.Spec.Priority, int32(55))
183184
framework.ExpectEqual(cnp.Spec.Subject.Namespaces.MatchLabels["kubernetes.io/metadata.name"], namespaceName)
184185

185-
waitForDNSResolversReady(cnpName, 1)
186+
waitForDNSResolversCreated(cnpName, 1)
186187
testNetworkConnectivity("https://www.baidu.com", false, "Testing connectivity to baidu.com after applying CNP (should be blocked)")
187188

188189
ginkgo.By("Deleting ClusterNetworkPolicy " + cnpName)
@@ -254,8 +255,8 @@ var _ = framework.SerialDescribe("[group:cluster-network-policy]", func() {
254255
framework.ExpectEqual(string(peer2.DomainNames[0]), "*.google.com.")
255256
framework.ExpectEqual(cnp2.Spec.Priority, int32(45))
256257

257-
waitForDNSResolversReady(cnpName, 1)
258-
waitForDNSResolversReady(cnpName2, 1)
258+
waitForDNSResolversCreated(cnpName, 1)
259+
waitForDNSResolversCreated(cnpName2, 1)
259260
testNetworkConnectivity("https://www.baidu.com", false, "Testing connectivity to baidu.com after applying both CNPs (should be blocked)")
260261
testNetworkConnectivity("https://www.google.com", true, "Testing connectivity to google.com after applying both CNPs (should be allowed)")
261262

@@ -315,7 +316,7 @@ var _ = framework.SerialDescribe("[group:cluster-network-policy]", func() {
315316
updatedCNP, _ := cnpClient.Update(context.TODO(), createdCNP, metav1.UpdateOptions{})
316317
framework.Logf("Successfully updated ClusterNetworkPolicy with baidu.com deny rule: %s", updatedCNP.Name)
317318

318-
waitForDNSResolversReady(cnpName, 1)
319+
waitForDNSResolversCreated(cnpName, 1)
319320
testNetworkConnectivity("https://www.baidu.com", false, "Testing connectivity to baidu.com after adding deny rule (should be blocked)")
320321
testNetworkConnectivity("https://www.google.com", true, "Testing connectivity to google.com after adding baidu.com deny rule (should still succeed)")
321322

@@ -327,7 +328,7 @@ var _ = framework.SerialDescribe("[group:cluster-network-policy]", func() {
327328
updatedcnp2, _ := cnpClient.Update(context.TODO(), updatedCNP, metav1.UpdateOptions{})
328329
framework.Logf("Successfully updated ClusterNetworkPolicy with both deny rules: %s", updatedcnp2.Name)
329330

330-
waitForDNSResolversReady(cnpName, 2)
331+
waitForDNSResolversCreated(cnpName, 2)
331332

332333
testNetworkConnectivity("https://www.baidu.com", false, "Testing connectivity to baidu.com after adding both deny rules (should be blocked)")
333334
testNetworkConnectivity("https://www.google.com", false, "Testing connectivity to google.com after adding both deny rules (should be blocked)")
@@ -403,7 +404,7 @@ var _ = framework.SerialDescribe("[group:cluster-network-policy]", func() {
403404
framework.ExpectEqual(len(cnp.Spec.Egress), 2)
404405
framework.ExpectEqual(cnp.Spec.Priority, int32(80))
405406

406-
waitForDNSResolversReady(cnpName, 1)
407+
waitForDNSResolversCreated(cnpName, 1)
407408
testNetworkConnectivity("https://www.baidu.com", false, "Testing connectivity to baidu.com after applying cnp (should be blocked)")
408409
testNetworkConnectivity("https://www.google.com", true, "Testing connectivity to google.com after applying cnp (should be allowed)")
409410
testNetworkConnectivity("https://8.8.8.8", false, "Testing connectivity to 8.8.8.8 after applying cnp (should be blocked by CIDR rule)")
@@ -452,7 +453,7 @@ var _ = framework.SerialDescribe("[group:cluster-network-policy]", func() {
452453
framework.ExpectEqual(len(cnp.Spec.Egress), 1)
453454
framework.ExpectEqual(cnp.Spec.Priority, int32(85))
454455

455-
waitForDNSResolversReady(cnpName, 1)
456+
waitForDNSResolversCreated(cnpName, 1)
456457
testNetworkConnectivity("https://www.baidu.com", false, "Testing connectivity to www.baidu.com after applying cnp (should be blocked by wildcard)")
457458
testNetworkConnectivity("https://api.baidu.com", false, "Testing connectivity to api.baidu.com after applying cnp (should be blocked by wildcard)")
458459
testNetworkConnectivity("https://news.baidu.com", false, "Testing connectivity to news.baidu.com after applying cnp (should be blocked by wildcard)")

0 commit comments

Comments
 (0)