mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-27 10:24:57 +00:00
Make the E2E testing pods obey the restricted pod security standard.
Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
This commit is contained in:
@@ -35,6 +35,11 @@ import (
|
|||||||
|
|
||||||
func CreateNamespace(ctx context.Context, client TestClient, namespace string) error {
|
func CreateNamespace(ctx context.Context, client TestClient, namespace string) error {
|
||||||
ns := builder.ForNamespace(namespace).Result()
|
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{})
|
_, err := client.ClientGo.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
|
||||||
if apierrors.IsAlreadyExists(err) {
|
if apierrors.IsAlreadyExists(err) {
|
||||||
return nil
|
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 {
|
func CreateNamespaceWithLabel(ctx context.Context, client TestClient, namespace string, label map[string]string) error {
|
||||||
ns := builder.ForNamespace(namespace).Result()
|
ns := builder.ForNamespace(namespace).Result()
|
||||||
ns.Labels = label
|
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{})
|
_, err := client.ClientGo.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
|
||||||
if apierrors.IsAlreadyExists(err) {
|
if apierrors.IsAlreadyExists(err) {
|
||||||
return nil
|
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 {
|
func CreateNamespaceWithAnnotation(ctx context.Context, client TestClient, namespace string, annotation map[string]string) error {
|
||||||
ns := builder.ForNamespace(namespace).Result()
|
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
|
ns.ObjectMeta.Annotations = annotation
|
||||||
_, err := client.ClientGo.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
|
_, err := client.ClientGo.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
|
||||||
if apierrors.IsAlreadyExists(err) {
|
if apierrors.IsAlreadyExists(err) {
|
||||||
|
|||||||
@@ -200,6 +200,13 @@ func installKibishii(ctx context.Context, namespace string, cloudPlatform, veler
|
|||||||
return errors.Wrapf(err, "failed to install kibishii, stderr=%s", stderr)
|
return errors.Wrapf(err, "failed to install kibishii, stderr=%s", stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
labelNamespaceCmd := exec.CommandContext(ctx, "kubectl", "label", "namespace", namespace, "pod-security.kubernetes.io/enforce=baseline", "pod-security.kubernetes.io/enforce-version=latest", "--overwrite=true")
|
||||||
|
_, stderr, err = veleroexec.RunCommand(labelNamespaceCmd)
|
||||||
|
fmt.Printf("Label namespace with PSA policy: %s\n", labelNamespaceCmd)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to label namespace with PSA policy, stderr=%s", stderr)
|
||||||
|
}
|
||||||
|
|
||||||
kibishiiSetWaitCmd := exec.CommandContext(ctx, "kubectl", "rollout", "status", "statefulset.apps/kibishii-deployment",
|
kibishiiSetWaitCmd := exec.CommandContext(ctx, "kubectl", "rollout", "status", "statefulset.apps/kibishii-deployment",
|
||||||
"-n", namespace, "-w", "--timeout=30m")
|
"-n", namespace, "-w", "--timeout=30m")
|
||||||
_, stderr, err = veleroexec.RunCommand(kibishiiSetWaitCmd)
|
_, stderr, err = veleroexec.RunCommand(kibishiiSetWaitCmd)
|
||||||
|
|||||||
Reference in New Issue
Block a user