Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added envvar (CLEANUPDEPLOYMENTS) to cleanup failed tests. #118

Merged
merged 3 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def buildTestSteps(Map myParams, String kubeConfigRoot, String kubeconfig) {
timestamps {
withCredentials([string(credentialsId: 'ENTERPRISEIMAGE', variable: 'DEFAULTENTERPRISEIMAGE')]) {
withEnv([
"CLEANDEPLOYMENTS=1",
"DEPLOYMENTNAMESPACE=${myParams.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${myParams.DOCKERNAMESPACE}",
"ENTERPRISEIMAGE=${myParams.ENTERPRISEIMAGE}",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TESTLENGTHOPTIONS := -test.short
TESTTIMEOUT := 20m
ifeq ($(LONG), 1)
TESTLENGTHOPTIONS :=
TESTTIMEOUT := 60m
TESTTIMEOUT := 120m
endif
ifdef VERBOSE
TESTVERBOSEOPTIONS := -v
Expand Down
1 change: 1 addition & 0 deletions scripts/kube_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ kubectl --namespace ${DEPLOYMENTNAMESPACE} \
--image=${IMAGEID} \
--env="ENTERPRISEIMAGE=${ENTERPRISEIMAGE}" \
--env="TEST_NAMESPACE=${DEPLOYMENTNAMESPACE}" \
--env="CLEANDEPLOYMENTS=${CLEANDEPLOYMENTS}" \
-- \
-test.v -test.timeout $TESTTIMEOUT $TESTLENGTHOPTIONS $TESTOPTIONS
10 changes: 8 additions & 2 deletions tests/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestAuthenticationSingleDefaultSecret(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -86,6 +87,7 @@ func TestAuthenticationSingleCustomSecret(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand All @@ -106,7 +108,7 @@ func TestAuthenticationSingleCustomSecret(t *testing.T) {

// Secret must still exist
if _, err := waitUntilSecret(kubecli, depl.Spec.Authentication.GetJWTSecretName(), ns, nil, time.Second); err != nil {
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.JWTSecretName, err)
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.GetJWTSecretName(), err)
}

// Cleanup secret
Expand All @@ -132,6 +134,7 @@ func TestAuthenticationNoneSingle(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -169,6 +172,7 @@ func TestAuthenticationClusterDefaultSecret(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -222,6 +226,7 @@ func TestAuthenticationClusterCustomSecret(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand All @@ -242,7 +247,7 @@ func TestAuthenticationClusterCustomSecret(t *testing.T) {

// Secret must still exist
if _, err := waitUntilSecret(kubecli, depl.Spec.Authentication.GetJWTSecretName(), ns, nil, time.Second); err != nil {
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.JWTSecretName, err)
t.Fatalf("JWT secret '%s' not found: %v", depl.Spec.Authentication.GetJWTSecretName(), err)
}

// Cleanup secret
Expand All @@ -268,6 +273,7 @@ func TestAuthenticationNoneCluster(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions tests/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage
// Create deployment
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate)
require.NoError(t, err, fmt.Sprintf("Create deployment failed: %v", err))
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)

// Wait for deployment to be ready
deployment, err := waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
Expand Down Expand Up @@ -124,9 +125,11 @@ func TestMultiDeployment(t *testing.T) {
// Create deployments
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate1)
require.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err))
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace)

_, err = deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate2)
require.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err))
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace)

// Wait for deployments to be ready
deployment1, err := waitUntilDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace, deploymentIsReady())
Expand Down
1 change: 1 addition & 0 deletions tests/environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestProduction(t *testing.T) {
// REVIEW - should the test already fail here
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)

_, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
assert.Error(t, err, fmt.Sprintf("Deployment is up and running when it should not! There are not enough nodes(%d) for all DBServers(%d) in production modes.", numNodes, dbserverCount))
Expand Down
1 change: 1 addition & 0 deletions tests/immutable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestImmutableFields(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions tests/member_resilience_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestMemberResilienceAgents(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -134,6 +135,7 @@ func TestMemberResilienceCoordinators(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -230,6 +232,7 @@ func TestMemberResilienceDBServers(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions tests/resilience_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestResiliencePod(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -117,6 +118,7 @@ func TestResiliencePVC(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -201,6 +203,7 @@ func TestResiliencePVDBServer(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -304,6 +307,7 @@ func TestResilienceService(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err = waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down
1 change: 1 addition & 0 deletions tests/rocksdb_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestRocksDBEncryptionSingle(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady())
Expand Down
2 changes: 2 additions & 0 deletions tests/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestScaleClusterNonTLS(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down Expand Up @@ -101,6 +102,7 @@ func TestScaleCluster(t *testing.T) {
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady()); err != nil {
Expand Down
18 changes: 18 additions & 0 deletions tests/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func getEnterpriseImageOrSkip(t *testing.T) string {
return image
}

// shouldCleanDeployments returns true when deployments created
// by tests should be removed, even when the test fails.
func shouldCleanDeployments() bool {
return os.Getenv("CLEANDEPLOYMENTS") != ""
}

// mustNewKubeClient creates a kubernetes client
// failing the test on errors.
func mustNewKubeClient(t *testing.T) kubernetes.Interface {
Expand Down Expand Up @@ -307,6 +313,18 @@ func removeDeployment(cli versioned.Interface, deploymentName, ns string) error
return nil
}

// deferedCleanupDeployment removes a deployment when shouldCleanDeployments return true.
// This function is intended to be used in a defer statement.
func deferedCleanupDeployment(cli versioned.Interface, deploymentName, ns string) error {
if !shouldCleanDeployments() {
return nil
}
if err := removeDeployment(cli, deploymentName, ns); err != nil {
return maskAny(err)
}
return nil
}

// removeSecret removes a secret
func removeSecret(cli kubernetes.Interface, secretName, ns string) error {
if err := cli.CoreV1().Secrets(ns).Delete(secretName, nil); err != nil && k8sutil.IsNotFound(err) {
Expand Down
1 change: 1 addition & 0 deletions tests/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func upgradeSubTest(t *testing.T, mode api.DeploymentMode, engine api.StorageEng
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)

// Wait for deployment to be ready
deployment, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
Expand Down