Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
test: run e2e test pod without framework setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hasbro17 committed May 24, 2018
1 parent 9f310f1 commit 7916621
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
21 changes: 18 additions & 3 deletions test/e2e/backup_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -186,9 +186,24 @@ 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) {
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions test/pod/simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
9 changes: 9 additions & 0 deletions test/pod/simple/run-e2e
Original file line number Diff line number Diff line change
@@ -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}
15 changes: 15 additions & 0 deletions test/pod/simple/simple-pod-templ.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: vault-operator-e2e-tests
spec:
restartPolicy: Never
containers:
- name: vault-operator-e2e-tests
image: <TEST_IMAGE>
imagePullPolicy: Always
env:
- name: TEST_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace

0 comments on commit 7916621

Please sign in to comment.