Skip to content

Commit 9596fb9

Browse files
committed
Make A1 passing
1 parent 28e38fb commit 9596fb9

4 files changed

Lines changed: 83 additions & 28 deletions

File tree

test/e2e-component-proxy/component_proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func testOIDCIdPThroughComponentProxy(withTrustedCA bool) {
129129
o.Expect(err).NotTo(o.HaveOccurred())
130130

131131
g.By("Verifying OAuth server deployment has proxy env vars and trustedCA volume/mount")
132-
test.VerifyOAuthServerDeploymentProxyConfig(t, clients.KubeClient, "", proxyURL, "", withTrustedCA)
132+
test.VerifyOAuthServerDeploymentProxyConfig(t, clients.KubeClient, "", proxyURL, ".cluster.local,.svc,127.0.0.1,localhost", withTrustedCA)
133133

134134
if withTrustedCA {
135135
g.By("Verifying trustedCA ConfigMap was synced to openshift-authentication")

test/library/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func NewClientConfigForTest(t testing.TB) *rest.Config {
4040
}
4141

4242
require.NoError(t, err)
43+
44+
config.QPS = 40
45+
config.Burst = 60
46+
4347
return config
4448
}
4549

test/library/idpdeployment.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ func addOIDCIDentityProvider(
307307
directExternalOIDC bool) ([]func(), error) {
308308
var cleanups []func()
309309

310+
success := false
311+
defer func() {
312+
if !success {
313+
for _, c := range cleanups {
314+
c()
315+
}
316+
}
317+
}()
318+
310319
secretName := idpName + "-secret"
311320
_, err := kubeClients.CoreV1().Secrets("openshift-config").Create(context.TODO(),
312321
&corev1.Secret{
@@ -321,7 +330,7 @@ func addOIDCIDentityProvider(
321330
metav1.CreateOptions{},
322331
)
323332
if err != nil {
324-
return cleanups, fmt.Errorf("failed to create keycloak client secret: %v", err)
333+
return nil, fmt.Errorf("failed to create keycloak client secret: %v", err)
325334
}
326335
cleanups = append(cleanups, func() {
327336
if err := kubeClients.CoreV1().Secrets("openshift-config").Delete(context.TODO(), secretName, metav1.DeleteOptions{}); err != nil {
@@ -330,7 +339,6 @@ func addOIDCIDentityProvider(
330339
})
331340

332341
caCMName := idpName + "-ca"
333-
// configure the default ingress CA as the CA for the IdP in the openshift-config NS
334342
cleanups = append(cleanups, SyncDefaultIngressCAToConfig(t, kubeClients.CoreV1(), caCMName))
335343

336344
if !directExternalOIDC {
@@ -354,14 +362,14 @@ func addOIDCIDentityProvider(
354362
},
355363
},
356364
})
365+
cleanups = append(cleanups, idpClean...)
357366
if err != nil {
358-
return cleanups, fmt.Errorf("failed to add identity provider to oauth server: %v", err)
367+
return nil, fmt.Errorf("failed to add identity provider to oauth server: %v", err)
359368
}
360-
361-
cleanups = append(cleanups, idpClean...)
362369
}
363370

364-
return cleanups, err
371+
success = true
372+
return cleanups, nil
365373
}
366374

367375
func addIdentityProvider(t testing.TB, configClient *configv1client.ConfigV1Client, idp *configv1.IdentityProvider) ([]func(), error) {

test/library/proxy.go

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,25 @@ func SaveAndRestoreProxyConfig(t testing.TB, operatorClient *operatorclient.Clie
5252

5353
return auth, func() {
5454
t.Log("cleaning up: restoring original proxy config")
55-
fresh, err := operatorClient.OperatorV1().Authentications().Get(ctx, "cluster", metav1.GetOptions{})
55+
err := wait.PollUntilContextTimeout(ctx, 1*time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) {
56+
fresh, err := operatorClient.OperatorV1().Authentications().Get(ctx, "cluster", metav1.GetOptions{})
57+
if err != nil {
58+
t.Logf("cleanup: failed to get operator auth: %v", err)
59+
return false, nil
60+
}
61+
if originalProxy != nil {
62+
fresh.Spec.Proxy = *originalProxy
63+
} else {
64+
fresh.Spec.Proxy = operatorv1.AuthenticationProxyConfig{}
65+
}
66+
if _, err := operatorClient.OperatorV1().Authentications().Update(ctx, fresh, metav1.UpdateOptions{}); err != nil {
67+
t.Logf("cleanup: failed to update operator auth (will retry): %v", err)
68+
return false, nil
69+
}
70+
return true, nil
71+
})
5672
if err != nil {
57-
t.Logf("cleanup: failed to get operator auth: %v", err)
58-
return
59-
}
60-
if originalProxy != nil {
61-
fresh.Spec.Proxy = *originalProxy
62-
} else {
63-
fresh.Spec.Proxy = operatorv1.AuthenticationProxyConfig{}
64-
}
65-
if _, err := operatorClient.OperatorV1().Authentications().Update(ctx, fresh, metav1.UpdateOptions{}); err != nil {
66-
t.Logf("cleanup: failed to restore proxy: %v", err)
73+
t.Logf("cleanup: failed to restore proxy config: %v", err)
6774
return
6875
}
6976
t.Log("cleanup: waiting for operator to pick up changes and stabilize")
@@ -117,8 +124,8 @@ https_port %d tls-cert=/etc/squid/tls/tls.crt tls-key=/etc/squid/tls/tls.key
117124
pid_filename /tmp/squid.pid
118125
acl all src all
119126
http_access allow all
120-
access_log stdio:/dev/stdout
121-
cache_log stdio:/dev/stderr
127+
access_log /tmp/squid/access.log
128+
cache_log /tmp/squid/cache.log
122129
cache deny all
123130
buffered_logs off
124131
`, squidHTTPPort, squidHTTPSPort)
@@ -176,6 +183,10 @@ buffered_logs off
176183
MountPath: "/etc/squid/tls",
177184
ReadOnly: true,
178185
},
186+
{
187+
Name: "squid-logs",
188+
MountPath: "/tmp/squid",
189+
},
179190
},
180191
ReadinessProbe: &corev1.Probe{
181192
ProbeHandler: corev1.ProbeHandler{
@@ -187,6 +198,17 @@ buffered_logs off
187198
PeriodSeconds: 5,
188199
},
189200
},
201+
{
202+
Name: "log",
203+
Image: squidImage,
204+
Command: []string{"tail", "-F", "/tmp/squid/access.log"},
205+
VolumeMounts: []corev1.VolumeMount{
206+
{
207+
Name: "squid-logs",
208+
MountPath: "/tmp/squid",
209+
},
210+
},
211+
},
190212
},
191213
Volumes: []corev1.Volume{
192214
{
@@ -207,6 +229,12 @@ buffered_logs off
207229
},
208230
},
209231
},
232+
{
233+
Name: "squid-logs",
234+
VolumeSource: corev1.VolumeSource{
235+
EmptyDir: &corev1.EmptyDirVolumeSource{},
236+
},
237+
},
210238
},
211239
},
212240
},
@@ -302,6 +330,13 @@ func DeployProxyNetworkPolicies(t testing.TB, kubeClient kubernetes.Interface, p
302330
},
303331
},
304332
},
333+
{
334+
NamespaceSelector: &metav1.LabelSelector{
335+
MatchLabels: map[string]string{
336+
"policy-group.network.openshift.io/ingress": "",
337+
},
338+
},
339+
},
305340
},
306341
},
307342
},
@@ -321,34 +356,42 @@ func DeployProxyNetworkPolicies(t testing.TB, kubeClient kubernetes.Interface, p
321356
}
322357
}
323358

324-
// GetSquidProxyLogs reads the logs from the Squid proxy pod in the given namespace.
325-
func GetSquidProxyLogs(t testing.TB, kubeClient kubernetes.Interface, namespace string) string {
359+
// GetSquidProxyLogs reads the Squid access log from the proxy pod via
360+
// the log sidecar container that tails the access log file.
361+
func GetSquidProxyLogs(kubeClient kubernetes.Interface, namespace string) (string, error) {
326362
ctx := context.TODO()
327363

328364
pods, err := kubeClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
329365
LabelSelector: fmt.Sprintf("app=%s", squidServiceName),
330366
})
331367
if err != nil {
332-
t.Fatalf("failed to list squid pods in %s: %v", namespace, err)
368+
return "", fmt.Errorf("failed to list squid pods in %s: %w", namespace, err)
333369
}
334370
if len(pods.Items) == 0 {
335-
t.Fatalf("no squid proxy pods found in namespace %s", namespace)
371+
return "", fmt.Errorf("no squid proxy pods found in namespace %s", namespace)
336372
}
337373

338-
logBytes, err := kubeClient.CoreV1().Pods(namespace).GetLogs(pods.Items[0].Name, &corev1.PodLogOptions{}).DoRaw(ctx)
374+
container := "log"
375+
logBytes, err := kubeClient.CoreV1().Pods(namespace).GetLogs(pods.Items[0].Name, &corev1.PodLogOptions{
376+
Container: container,
377+
}).DoRaw(ctx)
339378
if err != nil {
340-
t.Fatalf("failed to get squid pod logs: %v", err)
379+
return "", fmt.Errorf("failed to get logs from container %s: %w", container, err)
341380
}
342381

343-
return string(logBytes)
382+
return string(logBytes), nil
344383
}
345384

346385
// WaitForSquidProxyTraffic polls the Squid proxy logs until it sees CONNECT or
347386
// TCP_ entries, indicating traffic went through the proxy.
348387
func WaitForSquidProxyTraffic(t testing.TB, kubeClient kubernetes.Interface, namespace string, timeout time.Duration) error {
349388
t.Logf("waiting up to %s for traffic in squid proxy logs", timeout)
350389
return wait.PollUntilContextTimeout(context.TODO(), 10*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
351-
logs := GetSquidProxyLogs(t, kubeClient, namespace)
390+
logs, err := GetSquidProxyLogs(kubeClient, namespace)
391+
if err != nil {
392+
t.Logf("failed to read squid logs: %v", err)
393+
return false, nil
394+
}
352395
if strings.Contains(logs, "CONNECT") || strings.Contains(logs, "TCP_") {
353396
t.Logf("detected proxy traffic in squid logs")
354397
return true, nil

0 commit comments

Comments
 (0)