Skip to content

Commit 253f7a1

Browse files
committed
update
Signed-off-by: Huabing Zhao <[email protected]>
1 parent d885ef0 commit 253f7a1

File tree

2 files changed

+40
-52
lines changed

2 files changed

+40
-52
lines changed

test/e2e/tests/oidc.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ var OIDCTest = suite.ConformanceTest{
5454
})
5555

5656
t.Run("oidc bypass", func(t *testing.T) {
57-
ns := "gateway-conformance-infra"
57+
var (
58+
ns = "gateway-conformance-infra"
59+
keycloakSel = map[string]string{"app": "keycloak"}
60+
backendSel = map[string]string{"app": "infra-backend-v1"}
61+
)
5862

5963
podInitialized := corev1.PodCondition{Type: corev1.PodInitialized, Status: corev1.ConditionTrue}
6064
// Wait for the keycloak pod to be configured with the test user and client
6165
WaitForPods(t, suite.Client, ns, map[string]string{"job-name": "setup-keycloak"}, corev1.PodSucceeded, &podInitialized)
62-
keycloakSel := map[string]string{"app": "keycloak"}
63-
backendSel := map[string]string{"app": "infra-backend-v1"}
64-
6566
WaitForPods(t, suite.Client, ns, keycloakSel, corev1.PodRunning, &PodReady)
6667
WaitForPods(t, suite.Client, ns, backendSel, corev1.PodRunning, &PodReady)
6768

@@ -110,6 +111,16 @@ var OIDCTest = suite.ConformanceTest{
110111
},
111112
}
112113

114+
t.Cleanup(func() {
115+
if t.Failed() {
116+
// Log the status of the keycloak and backend pods for debugging purposes
117+
// The 503 errors may be caused by the keycloak or backend pods being evicted for some reason
118+
// https://github.com/envoyproxy/gateway/issues/7073
119+
LogPodsStatus(t, suite.Client, ns, keycloakSel, "OIDC failure - keycloak state")
120+
LogPodsStatus(t, suite.Client, ns, backendSel, "OIDC failure - backend state")
121+
}
122+
})
123+
113124
for i := range testCases {
114125
tc := testCases[i]
115126
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
@@ -133,13 +144,6 @@ func testOIDC(t *testing.T, suite *suite.ConformanceTestSuite, securityPolicyMan
133144
backendSel = map[string]string{"app": "infra-backend-v1"}
134145
)
135146

136-
t.Cleanup(func() {
137-
if t.Failed() {
138-
LogPodsStatus(t, suite.Client, ns, keycloakSel, "OIDC failure - keycloak state")
139-
LogPodsStatus(t, suite.Client, ns, backendSel, "OIDC failure - backend state")
140-
}
141-
})
142-
143147
podInitialized := corev1.PodCondition{Type: corev1.PodInitialized, Status: corev1.ConditionTrue}
144148
// Wait for the keycloak pod to be configured with the test user and client
145149
WaitForPods(t, suite.Client, ns, map[string]string{"job-name": "setup-keycloak"}, corev1.PodSucceeded, &podInitialized)

test/e2e/tests/utils.go

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ func LogPodsStatus(t *testing.T, cl client.Client, namespace string, selectors m
9292
for i := range pods.Items {
9393
p := &pods.Items[i]
9494
var containerSummaries []string
95-
for _, cs := range p.Status.ContainerStatuses {
95+
for i := 0; i < len(p.Status.ContainerStatuses); i++ {
96+
cs := p.Status.ContainerStatuses[i]
9697
state := "unknown"
9798
switch {
9899
case cs.State.Waiting != nil:
@@ -111,64 +112,47 @@ func LogPodsStatus(t *testing.T, cl client.Client, namespace string, selectors m
111112
}
112113
}
113114

114-
// WaitForPods waits for the pods in the given namespace and with the given selector
115-
// to be in the given phase and condition.
116115
func WaitForPods(t *testing.T, cl client.Client, namespace string, selectors map[string]string, phase corev1.PodPhase, condition *corev1.PodCondition) {
117116
if condition == nil {
118117
t.Fatalf("condition cannot be nil")
119118
}
120119
tlog.Logf(t, "waiting for %s/[%s] to be %v...", namespace, selectors, phase)
121120

122-
timeout := time.After(defaultServiceStartupTimeout)
123-
ticker := time.NewTicker(2 * time.Second)
124-
defer ticker.Stop()
125-
126-
for {
121+
require.Eventually(t, func() bool {
127122
pods := &corev1.PodList{}
123+
128124
err := cl.List(context.Background(), pods, &client.ListOptions{
129125
Namespace: namespace,
130126
LabelSelector: labels.SelectorFromSet(selectors),
131127
})
132-
if err == nil && len(pods.Items) > 0 {
133-
success := true
134-
checkPods:
135-
for i := range pods.Items {
136-
p := &pods.Items[i]
137-
if p.Status.Phase != phase {
138-
success = false
139-
break
140-
}
141128

142-
if p.Status.Conditions == nil {
143-
success = false
144-
break
145-
}
129+
if err != nil || len(pods.Items) == 0 {
130+
return false
131+
}
146132

147-
conditionMet := false
148-
for _, c := range p.Status.Conditions {
149-
if c.Type == condition.Type && c.Status == condition.Status {
150-
conditionMet = true
151-
continue checkPods
152-
}
153-
}
154-
if !conditionMet {
155-
success = false
156-
break
157-
}
133+
checkPods:
134+
for i := range pods.Items {
135+
p := &pods.Items[i]
136+
if p.Status.Phase != phase {
137+
return false
158138
}
159139

160-
if success {
161-
return
140+
if p.Status.Conditions == nil {
141+
return false
162142
}
163-
}
164143

165-
select {
166-
case <-timeout:
167-
LogPodsStatus(t, cl, namespace, selectors, fmt.Sprintf("timed out waiting for pods to reach %s/%s", phase, condition.Type))
168-
t.Fatalf("timed out waiting for pods in %s with selector %v to reach phase %s and condition %s", namespace, selectors, phase, condition.Type)
169-
case <-ticker.C:
144+
for _, c := range p.Status.Conditions {
145+
if c.Type == condition.Type && c.Status == condition.Status {
146+
continue checkPods // pod is ready, check next pod
147+
}
148+
}
149+
150+
tlog.Logf(t, "pod %s/%s status: %v", p.Namespace, p.Name, p.Status)
151+
return false
170152
}
171-
}
153+
154+
return true
155+
}, defaultServiceStartupTimeout, 2*time.Second)
172156
}
173157

174158
// SecurityPolicyMustBeAccepted waits for the specified SecurityPolicy to be accepted.

0 commit comments

Comments
 (0)