Skip to content

Commit 874eac1

Browse files
committed
improve webhook management during authorizer e2e tests
On-behalf-of: @SAP [email protected]
1 parent 1933949 commit 874eac1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

test/e2e/authorizer/authorizationorder_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func TestAuthorizationOrder(t *testing.T) {
5353

5454
// stop the webhook and switch to a deny policy
5555
webhookStop()
56-
RunWebhook(ctx, t, webhookPort, "kubernetes:authz:deny")
56+
webhookStop = RunWebhook(ctx, t, webhookPort, "kubernetes:authz:deny")
57+
t.Cleanup(webhookStop)
5758

5859
t.Log("Admin should not be allowed to list ConfigMaps.")
5960
_, err = kubeClusterClient.Cluster(logicalcluster.NewPath("root")).CoreV1().ConfigMaps("default").List(ctx, metav1.ListOptions{})
@@ -82,7 +83,8 @@ func TestAuthorizationOrder(t *testing.T) {
8283

8384
// stop the webhook and switch to a deny policy
8485
webhookStop()
85-
RunWebhook(ctx, t, webhookPort, "kubernetes:authz:deny")
86+
webhookStop = RunWebhook(ctx, t, webhookPort, "kubernetes:authz:deny")
87+
t.Cleanup(webhookStop)
8688

8789
t.Log("Admin should not be allowed now to list Logical clusters.")
8890
_, err = kcpClusterClient.Cluster(logicalcluster.NewPath("root")).CoreV1alpha1().LogicalClusters().List(ctx, metav1.ListOptions{})

test/e2e/authorizer/utils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net"
2323
"os"
2424
"os/exec"
25+
"sync"
2526
"testing"
2627
"time"
2728

@@ -66,11 +67,11 @@ func RunWebhook(ctx context.Context, t *testing.T, port string, response string)
6667
return true, ""
6768
}, wait.ForeverTestTimeout, time.Millisecond*200)
6869

69-
return func() {
70+
return sync.OnceFunc(func() {
7071
t.Log("Stopping webhook...")
7172
cancel()
72-
if err := cmd.Wait(); err != nil {
73-
t.Logf("error waiting for webhook to finish: %v", err)
73+
if err := cmd.Wait(); err != nil && err.Error() != "signal: killed" {
74+
t.Logf("Error waiting for webhook to finish: %v", err)
7475
}
75-
}
76+
})
7677
}

0 commit comments

Comments
 (0)