diff --git a/src/cloud-api-adaptor/test/e2e/nginx_deployment.go b/src/cloud-api-adaptor/test/e2e/nginx_deployment.go index e5d234a3f..7b9833698 100644 --- a/src/cloud-api-adaptor/test/e2e/nginx_deployment.go +++ b/src/cloud-api-adaptor/test/e2e/nginx_deployment.go @@ -23,8 +23,12 @@ import ( "sigs.k8s.io/e2e-framework/pkg/features" ) -const WAIT_NGINX_DEPLOYMENT_TIMEOUT = time.Second * 900 +const ( + FEATURE_SETUP_FAILED contextValueString = "WithSetupFailed" + WAIT_NGINX_DEPLOYMENT_TIMEOUT = time.Second * 900 +) +type contextValueString string type deploymentOption func(*appsv1.Deployment) func WithReplicaCount(replicas int32) deploymentOption { @@ -103,6 +107,7 @@ func DoTestNginxDeployment(t *testing.T, testEnv env.Environment, assert CloudAs nginxImageFeature := features.New("Nginx image deployment test"). WithSetup("Create nginx deployment", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + ctx = context.WithValue(ctx, FEATURE_SETUP_FAILED, false) client, err := cfg.NewClient() if err != nil { t.Fatal(err) @@ -112,17 +117,28 @@ func DoTestNginxDeployment(t *testing.T, testEnv env.Environment, assert CloudAs t.Fatal(err) } waitForNginxDeploymentAvailable(ctx, t, client, deployment, replicas) - t.Log("nginx deployment is available now") + if !t.Failed() { + t.Log("nginx deployment is available now") + } else { + ctx = context.WithValue(ctx, FEATURE_SETUP_FAILED, true) + } return ctx }). Assess("Access for nginx deployment test", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + if ctx.Value(FEATURE_SETUP_FAILED).(bool) { + // Test setup failed, so skip this assess + t.Skip() + return ctx + } client, err := cfg.NewClient() if err != nil { - t.Fatal(err) + t.Error(err) + return ctx } var podlist v1.PodList if err := client.Resources(deployment.ObjectMeta.Namespace).List(ctx, &podlist); err != nil { - t.Fatal(err) + t.Error(err) + return ctx } for _, pod := range podlist.Items { if pod.ObjectMeta.Labels["app"] == "nginx" { @@ -168,8 +184,10 @@ func waitForNginxDeploymentAvailable(ctx context.Context, t *testing.T, client k return deployObj.Status.AvailableReplicas == rc }), wait.WithTimeout(WAIT_NGINX_DEPLOYMENT_TIMEOUT), wait.WithInterval(10*time.Second)); err != nil { var podlist v1.PodList + t.Errorf("%v", err) if err := client.Resources(deployment.ObjectMeta.Namespace).List(ctx, &podlist); err != nil { - t.Fatal(err) + t.Errorf("%v", err) + return } for _, pod := range podlist.Items { if pod.ObjectMeta.Labels["app"] == "nginx" { @@ -195,6 +213,5 @@ func waitForNginxDeploymentAvailable(ctx context.Context, t *testing.T, client k } } } - t.Fatal(err) } }