From 5d7b5cb825c794e2d0f8daf778b305910d83d7b4 Mon Sep 17 00:00:00 2001 From: hasbro17 Date: Thu, 24 May 2018 13:38:05 -0700 Subject: [PATCH] test: run e2e test pod without framework setup --- test/e2e/backup_restore_test.go | 20 +++++++++++++++++--- test/e2e/framework/framework.go | 10 ++++++++++ test/pod/simple/Dockerfile | 16 ++++++++++++++++ test/pod/simple/run-e2e | 9 +++++++++ test/pod/simple/simple-pod-templ.yaml | 15 +++++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 test/pod/simple/Dockerfile create mode 100755 test/pod/simple/run-e2e create mode 100644 test/pod/simple/simple-pod-templ.yaml diff --git a/test/e2e/backup_restore_test.go b/test/e2e/backup_restore_test.go index 8cd503d..f8e53d9 100644 --- a/test/e2e/backup_restore_test.go +++ b/test/e2e/backup_restore_test.go @@ -76,7 +76,7 @@ func createBackup(t *testing.T, vaultCR *api.VaultService, etcdClusterName, s3Pa if err != nil { t.Fatalf("failed to get endpoints: %v", err) } - backupCR := eope2eutil.NewS3Backup(endpoints, etcdClusterName, s3Path, os.Getenv("TEST_AWS_SECRET"), k8sutil.EtcdClientTLSSecretName(vaultCR.Name)) + backupCR := eope2eutil.NewS3Backup(endpoints, etcdClusterName, s3Path, os.Getenv(awsEnv), k8sutil.EtcdClientTLSSecretName(vaultCR.Name)) eb, err := f.EtcdCRClient.EtcdV1beta2().EtcdBackups(f.Namespace).Create(backupCR) if err != nil { t.Fatalf("failed to create etcd backup cr: %v", err) @@ -127,7 +127,7 @@ func killEtcdCluster(t *testing.T, etcdClusterName string) { // restoreEtcdCluster restores an etcd cluster with name "etcdClusterName" from a backup saved on "s3Path". func restoreEtcdCluster(t *testing.T, s3Path, etcdClusterName string) { f := framework.Global - restoreSource := eopapi.RestoreSource{S3: eope2eutil.NewS3RestoreSource(s3Path, os.Getenv("TEST_AWS_SECRET"))} + restoreSource := eopapi.RestoreSource{S3: eope2eutil.NewS3RestoreSource(s3Path, os.Getenv(awsEnv))} er := eope2eutil.NewEtcdRestore(etcdClusterName, 3, restoreSource, eopapi.BackupStorageTypeS3) er, err := f.EtcdCRClient.EtcdV1beta2().EtcdRestores(f.Namespace).Create(er) if err != nil { @@ -186,9 +186,23 @@ func verifyRestoredVault(t *testing.T, vaultCR *api.VaultService, secretData map e2eutil.VerifySecretData(t, vClient, secretData, keyPath, podName) } +const ( + // Env specifying S3 bucket name + s3Env = "TEST_S3_BUCKET" + // Env specifying aws credentials secret name + awsEnv = "TEST_AWS_SECRET" +) + func TestBackupRestoreOnVault(t *testing.T) { + if len(os.Getenv(s3Env)) == 0 { + t.Skipf("S3 bucket name env (%s) not set", s3Env) + } + if len(os.Getenv(awsEnv)) == 0 { + t.Skipf("AWS credentials secret name env (%s) not set", awsEnv) + } + f := framework.Global - s3Path := path.Join(os.Getenv("TEST_S3_BUCKET"), "jenkins", strconv.Itoa(int(rand.Uint64())), time.Now().Format(time.RFC3339), "etcd.backup") + s3Path := path.Join(os.Getenv(s3Env), "jenkins", strconv.Itoa(int(rand.Uint64())), time.Now().Format(time.RFC3339), "etcd.backup") vaultCR, tlsConfig, rootToken := e2eutil.SetupUnsealedVaultCluster(t, f.KubeClient, f.VaultsCRClient, f.Namespace) defer func(vaultCR *api.VaultService) { diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 7889d92..635cb8f 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -97,6 +97,11 @@ func Setup() error { // Teardown removes the vault-operator deployment and waits for its termination func Teardown() error { + // Skip the operators teardown if either image is not specified + if len(Global.vopImage) == 0 || len(Global.eopImage) == 0 { + return nil + } + err := Global.KubeClient.CoreV1().Pods(Global.Namespace).Delete(vaultOperatorName, k8sutil.CascadeDeleteBackground()) if err != nil { return fmt.Errorf("failed to delete pod: %v", err) @@ -111,6 +116,11 @@ func Teardown() error { } func (f *Framework) setup() error { + // Skip the operators setup if either image is not specified + if len(Global.vopImage) == 0 || len(Global.eopImage) == 0 { + return nil + } + if err := f.deployEtcdOperatorPod(); err != nil { return fmt.Errorf("failed to setup etcd operator: %v", err) } diff --git a/test/pod/simple/Dockerfile b/test/pod/simple/Dockerfile new file mode 100644 index 0000000..e4932b5 --- /dev/null +++ b/test/pod/simple/Dockerfile @@ -0,0 +1,16 @@ +# golang:X-alpine can't be used since it does not support the race detector flag which assumes a glibc based system, whereas alpine linux uses musl libc +# https://github.com/golang/go/issues/14481 +FROM golang:1.10.2 as builder + +ADD ./ /go/src/github.com/coreos/vault-operator + +WORKDIR /go/src/github.com/coreos/vault-operator + +RUN go test ./test/e2e/ -c -o /bin/vault-operator-e2e --race + +FROM busybox:1.28.3-glibc + +COPY --from=builder /bin/vault-operator-e2e /bin +COPY --from=builder /go/src/github.com/coreos/vault-operator/test/pod/simple/run-e2e /bin/run-e2e + +CMD ["/bin/run-e2e"] diff --git a/test/pod/simple/run-e2e b/test/pod/simple/run-e2e new file mode 100755 index 0000000..44bac0e --- /dev/null +++ b/test/pod/simple/run-e2e @@ -0,0 +1,9 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +: ${TEST_NAMESPACE:?"Need to set TEST_NAMESPACE"} + +# Run e2e tests +/bin/vault-operator-e2e -test.timeout 30m -test.failfast -test.parallel 4 --namespace=${TEST_NAMESPACE} diff --git a/test/pod/simple/simple-pod-templ.yaml b/test/pod/simple/simple-pod-templ.yaml new file mode 100644 index 0000000..b298e3b --- /dev/null +++ b/test/pod/simple/simple-pod-templ.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: vault-operator-e2e-tests +spec: + restartPolicy: Never + containers: + - name: vault-operator-e2e-tests + image: + imagePullPolicy: Always + env: + - name: TEST_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace