From 70c6eada53d70d4b989b71e825b4da83556fdf67 Mon Sep 17 00:00:00 2001 From: Xun Jiang Date: Tue, 23 May 2023 11:23:44 +0800 Subject: [PATCH] Make the E2E testing pods obey the restricted pod security standard. Signed-off-by: Xun Jiang --- test/e2e/util/k8s/namespace.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/e2e/util/k8s/namespace.go b/test/e2e/util/k8s/namespace.go index 9b28873ef92..cc5f05a0f43 100644 --- a/test/e2e/util/k8s/namespace.go +++ b/test/e2e/util/k8s/namespace.go @@ -35,6 +35,11 @@ import ( func CreateNamespace(ctx context.Context, client TestClient, namespace string) error { ns := builder.ForNamespace(namespace).Result() + // Add label to avoid PSA check. + ns.Labels = map[string]string{ + "pod-security.kubernetes.io/enforce": "baseline", + "pod-security.kubernetes.io/enforce-version": "latest", + } _, err := client.ClientGo.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}) if apierrors.IsAlreadyExists(err) { return nil @@ -45,6 +50,9 @@ func CreateNamespace(ctx context.Context, client TestClient, namespace string) e func CreateNamespaceWithLabel(ctx context.Context, client TestClient, namespace string, label map[string]string) error { ns := builder.ForNamespace(namespace).Result() ns.Labels = label + // Add label to avoid PSA check. + ns.Labels["pod-security.kubernetes.io/enforce"] = "baseline" + ns.Labels["pod-security.kubernetes.io/enforce-version"] = "latest" _, err := client.ClientGo.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}) if apierrors.IsAlreadyExists(err) { return nil @@ -54,6 +62,11 @@ func CreateNamespaceWithLabel(ctx context.Context, client TestClient, namespace func CreateNamespaceWithAnnotation(ctx context.Context, client TestClient, namespace string, annotation map[string]string) error { ns := builder.ForNamespace(namespace).Result() + // Add label to avoid PSA check. + ns.Labels = map[string]string{ + "pod-security.kubernetes.io/enforce": "baseline", + "pod-security.kubernetes.io/enforce-version": "latest", + } ns.ObjectMeta.Annotations = annotation _, err := client.ClientGo.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}) if apierrors.IsAlreadyExists(err) {