Skip to content

Commit

Permalink
Fix e2e-tls tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ReToCode committed Sep 20, 2024
1 parent 9d0fa73 commit d96521b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
2 changes: 1 addition & 1 deletion openshift/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env

failed=0

export ENABLE_INTERNAL_TLS="${ENABLE_INTERNAL_TLS:-false}"
export ENABLE_TLS="${ENABLE_TLS:-false}"

(( !failed )) && install_knative || failed=1
(( !failed )) && prepare_knative_serving_tests_nightly || failed=2
Expand Down
67 changes: 67 additions & 0 deletions openshift/patches/014-ocp-system-internal-tls-test.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/test/e2e/systeminternaltls/system_internal_tls_test.go b/test/e2e/systeminternaltls/system_internal_tls_test.go
--- a/test/e2e/systeminternaltls/system_internal_tls_test.go (revision 9d0fa738d33402b893659610ddf4d4635cfa61f4)
+++ b/test/e2e/systeminternaltls/system_internal_tls_test.go (revision 4f646561395fb011368360e35365f8664383cdc5)
@@ -113,6 +113,7 @@

// TestTLSCertificateRotation tests certificate rotation and automatic reloading of certs.
func TestTLSCertificateRotation(t *testing.T) {
+
if !test.ServingFlags.EnableAlphaFeatures {
t.Skip("Alpha features not enabled")
}
@@ -162,6 +163,7 @@

t.Log("Creating ConfigMap with old and new CA certs")
systemNS := os.Getenv(system.NamespaceEnvKey)
+ ingressNS := os.Getenv(test.GatewayNamespaceOverride)

// Create ConfigMap with networking.knative.dev/trust-bundle label in required namespaces
cm := &corev1.ConfigMap{
@@ -179,7 +181,15 @@
_, err = clients.KubeClient.CoreV1().ConfigMaps(systemNS).
Create(context.Background(), cm, v1.CreateOptions{})
if err != nil {
- t.Fatal("Failed to create configmap:", err)
+ t.Fatal("Failed to create configmap in "+systemNS, err)
+ }
+
+ if ingressNS != "" && systemNS != ingressNS {
+ _, err = clients.KubeClient.CoreV1().ConfigMaps(ingressNS).
+ Create(context.Background(), cm, v1.CreateOptions{})
+ if err != nil {
+ t.Fatal("Failed to create configmap in "+ingressNS, err)
+ }
}

// Clean up on test failure or interrupt
@@ -187,7 +197,14 @@
test.TearDown(clients, &names)
if err := clients.KubeClient.CoreV1().ConfigMaps(systemNS).
Delete(context.Background(), cm.Name, v1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) {
- t.Fatal("Failed to delete configmap:", err)
+ t.Fatal("Failed to delete configmap in "+systemNS, err)
+ }
+
+ if ingressNS != "" && systemNS != ingressNS {
+ if err := clients.KubeClient.CoreV1().ConfigMaps(ingressNS).
+ Delete(context.Background(), cm.Name, v1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) {
+ t.Fatal("Failed to delete configmap in "+ingressNS, err)
+ }
}
})

@@ -218,6 +235,14 @@
if err := clients.KubeClient.CoreV1().Secrets(systemNS).Delete(context.Background(), config.ServingRoutingCertName, v1.DeleteOptions{}); err != nil {
t.Fatalf("Failed to delete secret %s in system namespace: %v", config.ServingRoutingCertName, err)
}
+
+ if ingressNS != "" && systemNS != ingressNS {
+ t.Log("Deleting secret in ingress namespace")
+ if err := clients.KubeClient.CoreV1().Secrets(ingressNS).Delete(context.Background(), config.ServingRoutingCertName, v1.DeleteOptions{}); err != nil {
+ t.Fatalf("Failed to delete secret %s in ingress namespace: %v", config.ServingRoutingCertName, err)
+ }
+ }
+
checkEndpointState(t, clients, url)
}

29 changes: 27 additions & 2 deletions test/e2e/systeminternaltls/system_internal_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func TestSystemInternalTLS(t *testing.T) {

// TestTLSCertificateRotation tests certificate rotation and automatic reloading of certs.
func TestTLSCertificateRotation(t *testing.T) {

if !test.ServingFlags.EnableAlphaFeatures {
t.Skip("Alpha features not enabled")
}
Expand Down Expand Up @@ -162,6 +163,7 @@ func TestTLSCertificateRotation(t *testing.T) {

t.Log("Creating ConfigMap with old and new CA certs")
systemNS := os.Getenv(system.NamespaceEnvKey)
ingressNS := os.Getenv(test.GatewayNamespaceOverride)

// Create ConfigMap with networking.knative.dev/trust-bundle label in required namespaces
cm := &corev1.ConfigMap{
Expand All @@ -179,15 +181,30 @@ func TestTLSCertificateRotation(t *testing.T) {
_, err = clients.KubeClient.CoreV1().ConfigMaps(systemNS).
Create(context.Background(), cm, v1.CreateOptions{})
if err != nil {
t.Fatal("Failed to create configmap:", err)
t.Fatal("Failed to create configmap in "+systemNS, err)
}

if ingressNS != "" && systemNS != ingressNS {
_, err = clients.KubeClient.CoreV1().ConfigMaps(ingressNS).
Create(context.Background(), cm, v1.CreateOptions{})
if err != nil {
t.Fatal("Failed to create configmap in "+ingressNS, err)
}
}

// Clean up on test failure or interrupt
test.EnsureCleanup(t, func() {
test.TearDown(clients, &names)
if err := clients.KubeClient.CoreV1().ConfigMaps(systemNS).
Delete(context.Background(), cm.Name, v1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) {
t.Fatal("Failed to delete configmap:", err)
t.Fatal("Failed to delete configmap in "+systemNS, err)
}

if ingressNS != "" && systemNS != ingressNS {
if err := clients.KubeClient.CoreV1().ConfigMaps(ingressNS).
Delete(context.Background(), cm.Name, v1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) {
t.Fatal("Failed to delete configmap in "+ingressNS, err)
}
}
})

Expand Down Expand Up @@ -218,6 +235,14 @@ func TestTLSCertificateRotation(t *testing.T) {
if err := clients.KubeClient.CoreV1().Secrets(systemNS).Delete(context.Background(), config.ServingRoutingCertName, v1.DeleteOptions{}); err != nil {
t.Fatalf("Failed to delete secret %s in system namespace: %v", config.ServingRoutingCertName, err)
}

if ingressNS != "" && systemNS != ingressNS {
t.Log("Deleting secret in ingress namespace")
if err := clients.KubeClient.CoreV1().Secrets(ingressNS).Delete(context.Background(), config.ServingRoutingCertName, v1.DeleteOptions{}); err != nil {
t.Fatalf("Failed to delete secret %s in ingress namespace: %v", config.ServingRoutingCertName, err)
}
}

checkEndpointState(t, clients, url)
}

Expand Down

0 comments on commit d96521b

Please sign in to comment.