diff --git a/hack/make/tests/e2e.mk b/hack/make/tests/e2e.mk index 784f41b0a3..26d449a532 100644 --- a/hack/make/tests/e2e.mk +++ b/hack/make/tests/e2e.mk @@ -26,7 +26,7 @@ test/e2e-publish: ## Run standard e2e test only test/e2e/standard: manifests/crd/helm - $(GOTESTCMD) -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 200m -count=1 ./test/scenarios/standard -args --skip-labels "name=cloudnative-network-zone" $(SKIPCLEANUP) + $(GOTESTCMD) -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 200m -count=1 ./test/scenarios/standard -args $(SKIPCLEANUP) ## Run istio e2e test only test/e2e/istio: manifests/crd/helm @@ -38,99 +38,92 @@ test/e2e/release: manifests/crd/helm ## Runs ActiveGate e2e test only test/e2e/activegate: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=activegate-default" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "activegate" $(SKIPCLEANUP) ## Runs ActiveGate proxy e2e test only test/e2e/activegate/proxy: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=activegate-proxy" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --feature "activegate" $(SKIPCLEANUP) ## Runs ClassicFullStack e2e test only test/e2e/classic: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=classic" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "classic" $(SKIPCLEANUP) ## Runs ClassicFullStack switch mode e2e test only test/e2e/classic/switchmodes: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=classic-to-cloudnative" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "classic-to-cloudnative" $(SKIPCLEANUP) ## Runs CloudNative codemodules e2e test only test/e2e/cloudnative/codemodules: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=cloudnative-codemodules-image" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "cloudnative-codemodules-image" $(SKIPCLEANUP) ## Runs CloudNative codemodules-with-proxy e2e test only test/e2e/cloudnative/codemodules-with-proxy: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=codemodules-with-proxy" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --feature "codemodules-with-proxy" $(SKIPCLEANUP) ## Runs CloudNative codemodules-with-proxy-custom-ca e2e test only test/e2e/cloudnative/codemodules-with-custom-ca: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=codemodules-with-proxy-custom-ca" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --feature "codemodules-with-proxy-custom-ca" $(SKIPCLEANUP) ## Runs CloudNative codemodules e2e test with proxy and AG custom certificate test/e2e/cloudnative/codemodules-with-proxy-and-ag-cert: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=codemodules-with-proxy-and-ag-cert" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --feature "codemodules-with-proxy-and-ag-cert" $(SKIPCLEANUP) ## Runs CloudNative codemodules e2e test with proxy and AG custom certificates test/e2e/cloudnative/codemodules-with-proxy-custom-ca-ag-cert: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=codemodules-with-proxy-custom-ca-ag-cert" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --feature "codemodules-with-proxy-custom-ca-ag-cert" $(SKIPCLEANUP) ## Runs CloudNative automatic injection disabled e2e test only test/e2e/cloudnative/disabledautoinjection: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=cloudnative-disabled-auto-inject" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "cloudnative-disabled-auto-inject" $(SKIPCLEANUP) ## Runs CloudNative default e2e test only test/e2e/cloudnative/default: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=cloudnative-default" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "cloudnative" $(SKIPCLEANUP) ## Runs CloudNative istio e2e test only test/e2e/cloudnative/istio: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=cloudnative-istio" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --feature "cloudnative" $(SKIPCLEANUP) ## Runs CloudNative network problem e2e test only test/e2e/cloudnative/resilience: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=cloudnative-csi-resilience" $(SKIPCLEANUP) - -test/e2e/cloudnative/network-zone: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=cloudnative-network-zone" $(SKIPCLEANUP) - -## Runs CloudNative proxy e2e test only -test/e2e/cloudnative/proxy: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --labels "name=cloudnative-proxy" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/istio -args --feature "cloudnative-csi-resilience" $(SKIPCLEANUP) ## Runs Classic/CloudNative mode switching tests test/e2e/cloudnative/switchmodes: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=cloudnative-to-classic" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "cloudnative-to-classic" $(SKIPCLEANUP) ## Runs CloudNative upgrade e2e test only test/e2e/cloudnative/upgrade: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/release -args --labels "name=cloudnative-upgrade" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/release -args --feature "cloudnative-upgrade" $(SKIPCLEANUP) ## Runs Application Monitoring metadata-enrichment e2e test only test/e2e/applicationmonitoring/metadataenrichment: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=app-metadata-enrichment" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "metadata-enrichment" $(SKIPCLEANUP) ## Runs Application Monitoring label versio detection e2e test only test/e2e/applicationmonitoring/labelversion: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=app-label-version" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "label-version" $(SKIPCLEANUP) ## Runs Application Monitoring readonly csi-volume e2e test only test/e2e/applicationmonitoring/readonlycsivolume: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=app-read-only-csi-volume" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "app-read-only-csi-volume" $(SKIPCLEANUP) ## Runs Application Monitoring without CSI e2e test only test/e2e/applicationmonitoring/withoutcsi: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=app-without-csi" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "app-monitoring-without-csi" $(SKIPCLEANUP) ## Runs public registry images e2e test only test/e2e/publicregistry: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=public-registry-images" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "public-registry-images" $(SKIPCLEANUP) ## Runs SupportArchive e2e test only test/e2e/supportarchive: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=support-archive" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "support-archive" $(SKIPCLEANUP) ## Runs Edgeconnect e2e test only test/e2e/edgeconnect: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=edgeconnect-install,name=edgeconnect-install-provisioner,name=edgeconnect-install-k8s-automation" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "edgeconnect-.*" $(SKIPCLEANUP) ## Runs e2e tests on gke-autopilot test/e2e/gke-autopilot: manifests/crd/helm - go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --labels "name=app-metadata-enrichment,name=app-read-only-csi-volume,name=app-read-only-csi-volume,name=app-without-csi,name=activegate-default" $(SKIPCLEANUP) + go test -v -tags "$(shell ./hack/build/create_go_build_tags.sh true)" -timeout 20m -count=1 ./test/scenarios/standard -args --feature "app-metadata-enrichment|app-read-only-csi-volume|app-read-only-csi-volume|app-without-csi|activegate" $(SKIPCLEANUP) diff --git a/pkg/webhook/mutation/pod/init_container.go b/pkg/webhook/mutation/pod/init_container.go index 0dd31ce9c8..4e6c2a9ec9 100644 --- a/pkg/webhook/mutation/pod/init_container.go +++ b/pkg/webhook/mutation/pod/init_container.go @@ -152,6 +152,9 @@ func updateContainerInfo(request *dtwebhook.ReinvocationRequest, installContaine pod := request.Pod if installContainer == nil { installContainer = findInstallContainer(pod.Spec.InitContainers) + if installContainer == nil { + return false + } } newContainers := request.NewContainers(containerIsInjected) diff --git a/pkg/webhook/mutation/pod/webhook.go b/pkg/webhook/mutation/pod/webhook.go index d095c08f1d..756c938149 100644 --- a/pkg/webhook/mutation/pod/webhook.go +++ b/pkg/webhook/mutation/pod/webhook.go @@ -159,7 +159,9 @@ func (wh *webhook) handlePodMutation(ctx context.Context, mutationRequest *dtweb mutationRequest.InstallContainer = createInstallInitContainerBase(wh.webhookImage, wh.clusterID, mutationRequest.Pod, mutationRequest.DynaKube) - isMutated := updateContainerInfo(mutationRequest.ToReinvocationRequest(), mutationRequest.InstallContainer) + _ = updateContainerInfo(mutationRequest.ToReinvocationRequest(), mutationRequest.InstallContainer) + + var isMutated bool for _, mutator := range wh.mutators { if !mutator.Enabled(mutationRequest.BaseRequest) { @@ -191,7 +193,11 @@ func (wh *webhook) handlePodReinvocation(mutationRequest *dtwebhook.MutationRequ reinvocationRequest := mutationRequest.ToReinvocationRequest() - updateContainerInfo(reinvocationRequest, nil) + isMutated := updateContainerInfo(reinvocationRequest, nil) + + if !isMutated { // == no new containers were detected, we only mutate new containers during reinvoke + return false + } for _, mutator := range wh.mutators { if mutator.Enabled(mutationRequest.BaseRequest) { diff --git a/test/features/activegate/activegate.go b/test/features/activegate/activegate.go index e1596cf446..658981eeac 100644 --- a/test/features/activegate/activegate.go +++ b/test/features/activegate/activegate.go @@ -63,11 +63,6 @@ func Feature(t *testing.T, proxySpec *dynakube.DynaKubeProxy) features.Feature { dynakubeComponents.WithProxy(proxySpec)) builder := features.New("activegate") - if proxySpec == nil { - builder.WithLabel("name", "activegate-default") - } else { - builder.WithLabel("name", "activegate-proxy") - } proxy.SetupProxyWithTeardown(t, builder, testDynakube) proxy.CutOffDynatraceNamespace(builder, proxySpec) proxy.IsDynatraceNamespaceCutOff(builder, testDynakube) diff --git a/test/features/applicationmonitoring/label_version_detection.go b/test/features/applicationmonitoring/label_version_detection.go index c3c38d4070..ede4a0572d 100644 --- a/test/features/applicationmonitoring/label_version_detection.go +++ b/test/features/applicationmonitoring/label_version_detection.go @@ -96,27 +96,26 @@ var ( // - preserved values of existing variables - build variables exist, feature flag exists, with additional configuration, values of build variables not get overwritten // - incorrect custom mapping - invalid name of BUILD VERSION label, reference exists but actual label doesn't exist func LabelVersionDetection(t *testing.T) features.Feature { - builder := features.New("label version") - builder.WithLabel("name", "app-label-version") + builder := features.New("label-version") secretConfig := tenant.GetSingleTenantSecret(t) defaultDynakube := *dynakubeComponents.New( - dynakubeComponents.WithName("dynakubeComponents-default"), + dynakubeComponents.WithName("dynakube-components-default"), dynakubeComponents.WithApiUrl(secretConfig.ApiUrl), - dynakubeComponents.WithNameBasedOneAgentNamespaceSelector(), dynakubeComponents.WithApplicationMonitoringSpec(&dynakube.ApplicationMonitoringSpec{ UseCSIDriver: false, }), + dynakubeComponents.WithNameBasedOneAgentNamespaceSelector(), ) labelVersionDynakube := *dynakubeComponents.New( - dynakubeComponents.WithName("dynakubeComponents-labels"), + dynakubeComponents.WithName("dynakube-components-labels"), dynakubeComponents.WithAnnotations(map[string]string{dynakube.AnnotationFeatureLabelVersionDetection: "true"}), dynakubeComponents.WithApiUrl(secretConfig.ApiUrl), - dynakubeComponents.WithNameBasedOneAgentNamespaceSelector(), dynakubeComponents.WithApplicationMonitoringSpec(&dynakube.ApplicationMonitoringSpec{ UseCSIDriver: false, }), + dynakubeComponents.WithNameBasedOneAgentNamespaceSelector(), ) sampleApps := []*sample.App{ diff --git a/test/features/applicationmonitoring/metadata_enrichment.go b/test/features/applicationmonitoring/metadata_enrichment.go index 12668d3966..fda702568c 100644 --- a/test/features/applicationmonitoring/metadata_enrichment.go +++ b/test/features/applicationmonitoring/metadata_enrichment.go @@ -43,7 +43,6 @@ type metadata struct { // file contains required fields. func MetadataEnrichment(t *testing.T) features.Feature { builder := features.New("metadata-enrichment") - builder.WithLabel("name", "app-metadata-enrichment") secretConfig := tenant.GetSingleTenantSecret(t) testDynakube := *dynakubeComponents.New( dynakubeComponents.WithApiUrl(secretConfig.ApiUrl), diff --git a/test/features/applicationmonitoring/read_only_csi_volume.go b/test/features/applicationmonitoring/read_only_csi_volume.go index be1abbb376..5288fc316c 100644 --- a/test/features/applicationmonitoring/read_only_csi_volume.go +++ b/test/features/applicationmonitoring/read_only_csi_volume.go @@ -28,8 +28,7 @@ import ( var readOnlyInjection = map[string]string{dynakube.AnnotationFeatureReadOnlyCsiVolume: "true"} func ReadOnlyCSIVolume(t *testing.T) features.Feature { - builder := features.New("read only csi volume") - builder.WithLabel("name", "app-read-only-csi-volume") + builder := features.New("app-read-only-csi-volume") secretConfig := tenant.GetSingleTenantSecret(t) testDynakube := *dynakubeComponents.New( dynakubeComponents.WithAnnotations(readOnlyInjection), diff --git a/test/features/applicationmonitoring/without_csi.go b/test/features/applicationmonitoring/without_csi.go index 8a4db4425e..98b0b3e53c 100644 --- a/test/features/applicationmonitoring/without_csi.go +++ b/test/features/applicationmonitoring/without_csi.go @@ -20,8 +20,7 @@ import ( // ApplicationMonitoring deployment without CSI driver func WithoutCSI(t *testing.T) features.Feature { - builder := features.New("application monitoring without csi driver enabled") - builder.WithLabel("name", "app-without-csi") + builder := features.New("app-monitoring-without-csi") secretConfig := tenant.GetSingleTenantSecret(t) appOnlyDynakube := *dynakubeComponents.New( dynakubeComponents.WithApiUrl(secretConfig.ApiUrl), diff --git a/test/features/classic/classic.go b/test/features/classic/classic.go index 78dfc2e957..6a7bfacdda 100644 --- a/test/features/classic/classic.go +++ b/test/features/classic/classic.go @@ -18,8 +18,7 @@ import ( // installed and restarted to check if OneAgent is injected and can communicate // with the *Dynatrace Cluster*. func Feature(t *testing.T) features.Feature { - builder := features.New("install classic fullstack") - builder.WithLabel("name", "classic") + builder := features.New("classic") secretConfig := tenant.GetSingleTenantSecret(t) testDynakube := *dynakubeComponents.New( dynakubeComponents.WithApiUrl(secretConfig.ApiUrl), diff --git a/test/features/classic/switch_modes/switch_modes.go b/test/features/classic/switch_modes/switch_modes.go index 38c751d0aa..af59b2afad 100644 --- a/test/features/classic/switch_modes/switch_modes.go +++ b/test/features/classic/switch_modes/switch_modes.go @@ -22,8 +22,7 @@ const ( ) func Feature(t *testing.T) features.Feature { - builder := features.New("switch from classic to cloudnative") - builder.WithLabel("name", "classic-to-cloudnative") + builder := features.New("classic-to-cloudnative") // build classic full stack dynakube secretConfig := tenant.GetSingleTenantSecret(t) diff --git a/test/features/cloudnative/codemodules/codemodules.go b/test/features/cloudnative/codemodules/codemodules.go index 2e4617881b..9b3d61b73a 100644 --- a/test/features/cloudnative/codemodules/codemodules.go +++ b/test/features/cloudnative/codemodules/codemodules.go @@ -63,27 +63,28 @@ const ( // Verification that the storage in the CSI driver directory does not increase when // there are multiple tenants and pods which are monitored. func InstallFromImage(t *testing.T) features.Feature { - builder := features.New("cloudnative codemodules injection from image") - builder.WithLabel("name", "cloudnative-codemodules-image") + builder := features.New("cloudnative-codemodules-image") storageMap := make(map[string]int) secretConfigs := tenant.GetMultiTenantSecret(t) require.Len(t, secretConfigs, 2) cloudNativeDynakube := *dynakubeComponents.New( dynakubeComponents.WithName("cloudnative-codemodules"), + dynakubeComponents.WithCloudNativeSpec(codeModulesCloudNativeSpec(t)), dynakubeComponents.WithNameBasedOneAgentNamespaceSelector(), + dynakubeComponents.WithNameBasedMetadataEnrichmentNamespaceSelector(), dynakubeComponents.WithApiUrl(secretConfigs[0].ApiUrl), - dynakubeComponents.WithCloudNativeSpec(codeModulesCloudNativeSpec(t)), ) appDynakube := *dynakubeComponents.New( dynakubeComponents.WithName("app-codemodules"), - dynakubeComponents.WithNameBasedOneAgentNamespaceSelector(), - dynakubeComponents.WithApiUrl(secretConfigs[1].ApiUrl), dynakubeComponents.WithApplicationMonitoringSpec(&dynakube.ApplicationMonitoringSpec{ AppInjectionSpec: *codeModulesAppInjectSpec(t), UseCSIDriver: true, }), + dynakubeComponents.WithNameBasedOneAgentNamespaceSelector(), + dynakubeComponents.WithNameBasedMetadataEnrichmentNamespaceSelector(), + dynakubeComponents.WithApiUrl(secretConfigs[1].ApiUrl), ) labels := cloudNativeDynakube.OneAgentNamespaceSelector().MatchLabels @@ -134,8 +135,7 @@ const ( // the local cluster. Sample application is installed. The test checks if DT_PROXY environment // variable is defined in the *dynakubeComponents-oneagent* container and the *application container*. func WithProxy(t *testing.T, proxySpec *dynakube.DynaKubeProxy) features.Feature { - builder := features.New("codemodules injection with proxy") - builder.WithLabel("name", "codemodules-with-proxy") + builder := features.New("codemodules-with-proxy") secretConfigs := tenant.GetMultiTenantSecret(t) require.Len(t, secretConfigs, 2) @@ -190,8 +190,7 @@ func WithProxy(t *testing.T, proxySpec *dynakube.DynaKubeProxy) features.Feature func WithProxyCA(t *testing.T, proxySpec *dynakube.DynaKubeProxy) features.Feature { const configMapName = "proxy-ca" - builder := features.New("codemodules injection with proxy and custom CA") - builder.WithLabel("name", "codemodules-with-proxy-custom-ca") + builder := features.New("codemodules-with-proxy-custom-ca") secretConfigs := tenant.GetMultiTenantSecret(t) require.Len(t, secretConfigs, 2) @@ -251,8 +250,7 @@ func WithProxyCA(t *testing.T, proxySpec *dynakube.DynaKubeProxy) features.Featu } func WithProxyAndAGCert(t *testing.T, proxySpec *dynakube.DynaKubeProxy) features.Feature { - builder := features.New("codemodules injection with proxy and AG certificate") - builder.WithLabel("name", "codemodules-with-proxy-and-ag-cert") + builder := features.New("codemodules-with-proxy-and-ag-cert") secretConfigs := tenant.GetMultiTenantSecret(t) require.Len(t, secretConfigs, 2) @@ -317,8 +315,7 @@ func WithProxyAndAGCert(t *testing.T, proxySpec *dynakube.DynaKubeProxy) feature } func WithProxyCAAndAGCert(t *testing.T, proxySpec *dynakube.DynaKubeProxy) features.Feature { - builder := features.New("codemodules injection with proxy and custom CA and AG certificate") - builder.WithLabel("name", "codemodules-with-proxy-custom-ca-ag-cert") + builder := features.New("codemodules-with-proxy-custom-ca-ag-cert") secretConfigs := tenant.GetMultiTenantSecret(t) require.Len(t, secretConfigs, 2) diff --git a/test/features/cloudnative/default/default.go b/test/features/cloudnative/default/default.go index 35904a9819..af0af50a9b 100644 --- a/test/features/cloudnative/default/default.go +++ b/test/features/cloudnative/default/default.go @@ -48,13 +48,7 @@ import ( // Sample application Deployment is installed and restarted to check if OneAgent is // injected and VERSION environment variable is correct. func Feature(t *testing.T, istioEnabled bool) features.Feature { - builder := features.New("cloudnative default installation") - // Register operator install - if istioEnabled { - builder.WithLabel("name", "cloudnative-istio") - } else { - builder.WithLabel("name", "cloudnative-default") - } + builder := features.New("cloudnative") t.Logf("istio enabled: %v", istioEnabled) secretConfig := tenant.GetSingleTenantSecret(t) diff --git a/test/features/cloudnative/disabled_auto_injection/disabled_auto_injection.go b/test/features/cloudnative/disabled_auto_injection/disabled_auto_injection.go index 9e83c0b3e7..3b6bbd2e82 100644 --- a/test/features/cloudnative/disabled_auto_injection/disabled_auto_injection.go +++ b/test/features/cloudnative/disabled_auto_injection/disabled_auto_injection.go @@ -19,8 +19,7 @@ import ( ) func Feature(t *testing.T) features.Feature { - builder := features.New("cloudnative disabled auto injection") - builder.WithLabel("name", "cloudnative-disabled-auto-inject") + builder := features.New("cloudnative-disabled-auto-inject") secretConfig := tenant.GetSingleTenantSecret(t) testDynakube := *dynakubeComponents.New( diff --git a/test/features/cloudnative/init_containers.go b/test/features/cloudnative/init_containers.go index b3fd3bb995..d06631bb7f 100644 --- a/test/features/cloudnative/init_containers.go +++ b/test/features/cloudnative/init_containers.go @@ -61,7 +61,7 @@ func checkInitContainers(sampleApp *sample.App) features.Func { }).Stream(ctx) require.NoError(t, err) - logs.AssertContains(t, logStream, "standalone agent init completed") + logs.AssertContains(t, logStream, "init completed") ifNotEmptyCommand := shell.Shell(shell.CheckIfNotEmpty("/opt/dynatrace/oneagent-paas/log/php/")) executionResult, err := pod.Exec(ctx, resources, podItem, sampleApp.ContainerName(), ifNotEmptyCommand...) diff --git a/test/features/cloudnative/network_problems/network_problems.go b/test/features/cloudnative/network_problems/network_problems.go index e2c7c563cf..15abd79ce6 100644 --- a/test/features/cloudnative/network_problems/network_problems.go +++ b/test/features/cloudnative/network_problems/network_problems.go @@ -47,8 +47,7 @@ var ( // checks if init container was attached, run successfully and that the sample // pods are up and running. func ResilienceFeature(t *testing.T) features.Feature { - builder := features.New("cloudnative resilience in case of network problems") - builder.WithLabel("name", "cloudnative-csi-resilience") + builder := features.New("cloudnative-csi-resilience") secretConfig := tenant.GetSingleTenantSecret(t) restrictCSI(builder) diff --git a/test/features/cloudnative/network_zones/network_zones.go b/test/features/cloudnative/network_zones/network_zones.go deleted file mode 100644 index 9eadd73ebb..0000000000 --- a/test/features/cloudnative/network_zones/network_zones.go +++ /dev/null @@ -1,157 +0,0 @@ -//go:build e2e - -package network_zones - -import ( - "context" - "fmt" - "testing" - "time" - - "github.com/Dynatrace/dynatrace-operator/pkg/api/status" - "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube" - "github.com/Dynatrace/dynatrace-operator/test/features/cloudnative" - "github.com/Dynatrace/dynatrace-operator/test/helpers" - "github.com/Dynatrace/dynatrace-operator/test/helpers/components/activegate" - dynakubeComponents "github.com/Dynatrace/dynatrace-operator/test/helpers/components/dynakube" - "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/namespace" - "github.com/Dynatrace/dynatrace-operator/test/helpers/rand" - "github.com/Dynatrace/dynatrace-operator/test/helpers/sample" - "github.com/Dynatrace/dynatrace-operator/test/helpers/tenant" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - appsv1 "k8s.io/api/apps/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/e2e-framework/klient/k8s" - "sigs.k8s.io/e2e-framework/klient/wait" - "sigs.k8s.io/e2e-framework/klient/wait/conditions" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "sigs.k8s.io/e2e-framework/pkg/features" -) - -const ( - annotationInjected = "oneagent.dynatrace.com/injected" - annotationReason = "oneagent.dynatrace.com/reason" - timeout = 2 * time.Minute -) - -// Feature defines the overall e2e test for testing OneAgent -// injection behavior when Dynatrace is configured with a network zone. -// -// It does the following to cover the scenario of ensuring OneAgent injection is properly -// blocked when no ActiveGate is available, and enabled once one is added: -// - Creates test a network zone via the tenant helper (can be highly destructive) -// - Configures a DynaKube custom resource without an ActiveGate => no activegate == no networkzone communication -// - Installs a sample application -// - Verifies the sample app pods do NOT have OneAgent injected, validated via pod annotations -// - Updates the DynaKube to add an ActiveGate => so now networkzone communication is possible -// - Restarts the sample app pods -// - Verifies the sample app pods now DO have OneAgent injected -// -// Prerequisites: -// Have a tenant that has no activegates bound to it. -func Feature(t *testing.T) features.Feature { - builder := features.New("dynakube in network zone") - builder.WithLabel("name", "cloudnative-network-zone") - secretConfig := tenant.GetSingleTenantSecret(t) - - networkZone, err := rand.GetRandomName(rand.WithPrefix("op-e2e-"), rand.WithLength(8)) - require.NoError(t, err) - - builder.Assess("create network zone before hand", - tenant.CreateNetworkZone(secretConfig, networkZone, []string{}, tenant.FallbackNone)) - - builder.Assess("wait for network zone to be ready", - tenant.WaitForNetworkZone(secretConfig, networkZone, tenant.FallbackNone)) - - // intentionally no ActiveGate, to block OA rollout and codemodules injection - options := []dynakubeComponents.Option{ - dynakubeComponents.WithApiUrl(secretConfig.ApiUrl), - dynakubeComponents.WithNetworkZone(networkZone), - dynakubeComponents.WithCloudNativeSpec(cloudnative.DefaultCloudNativeSpec()), - } - - testDynakube := *dynakubeComponents.New(options...) - - // Register sample app install - sampleNamespace := *namespace.New("cloudnative-network-zone") - sampleApp := sample.NewApp(t, &testDynakube, - sample.AsDeployment(), - sample.WithNamespace(sampleNamespace), - ) - - builder.Assess("create sample namespace", sampleApp.InstallNamespace()) - - // Register dynakubeComponents install, do not wait for OneAgents to start up, because them not to is expected in this scenario - dynakubeComponents.Create(builder, helpers.LevelAssess, &secretConfig, testDynakube) - builder.Assess( - fmt.Sprintf("'%s' dynakubeComponents phase changes to 'Running'", testDynakube.Name), - dynakubeComponents.WaitForPhase(testDynakube, status.Deploying)) - builder.Assess("install sample app", sampleApp.Install()) - - // Register actual tests - builder.Assess("check injection annotations on sample app pods", checkInjectionAnnotations(sampleApp, "false", "EmptyConnectionInfo")) - builder.Assess("make sure that OneAgent pods do not yet start up", checkOneAgentPodsDoNotStart(testDynakube, timeout)) - - // update DynaKube to start AG, which should than enable OA rollout - options = append(options, dynakubeComponents.WithActiveGate()) - testDynaKubeWithAG := *dynakubeComponents.New(options...) - dynakubeComponents.Update(builder, helpers.LevelAssess, testDynaKubeWithAG) - dynakubeComponents.VerifyStartup(builder, helpers.LevelAssess, testDynaKubeWithAG) - - builder.Assess("Restart sample app pods", sampleApp.Restart()) - builder.Assess("check injection annotations on sample app pods", checkInjectionAnnotations(sampleApp, "true", "")) - - // Register sample, DynaKube and operator uninstall - builder.Teardown(sampleApp.Uninstall()) - dynakubeComponents.Delete(builder, helpers.LevelTeardown, testDynakube) - - builder.Teardown(activegate.WaitForStatefulSetPodsDeletion(&testDynakube, "activegate")) - builder.Teardown(tenant.WaitForNetworkZoneDeletion(secretConfig, networkZone)) - - return builder.Feature() -} - -func checkInjectionAnnotations(sampleApp *sample.App, injected string, reason string) features.Func { - return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context { - resource := envConfig.Client().Resources() - samplePods := sampleApp.GetPods(ctx, t, resource) - - require.NotNil(t, samplePods) - - for _, pod := range samplePods.Items { - require.NotNil(t, pod.Annotations) - - require.Contains(t, pod.Annotations, annotationInjected) - assert.Equal(t, injected, pod.Annotations[annotationInjected]) - - if injected == "false" && pod.Annotations[annotationInjected] == "false" { - require.Contains(t, pod.Annotations, annotationReason) - assert.Equal(t, reason, pod.Annotations[annotationReason]) - } - } - - return ctx - } -} - -func checkOneAgentPodsDoNotStart(dk dynakube.DynaKube, timeout time.Duration) features.Func { - return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context { - resources := envConfig.Client().Resources() - err := wait.For(conditions.New(resources).ResourceMatch(&appsv1.DaemonSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: dk.OneAgentDaemonsetName(), - Namespace: dk.Namespace, - }, - }, func(object k8s.Object) bool { - daemonset, isDaemonset := object.(*appsv1.DaemonSet) - - return isDaemonset && daemonset.Status.DesiredNumberScheduled == daemonset.Status.UpdatedNumberScheduled && - daemonset.Status.DesiredNumberScheduled == daemonset.Status.NumberReady - }), wait.WithTimeout(timeout)) - - require.Error(t, err) - - return ctx - } -} diff --git a/test/features/cloudnative/switch_modes/switch_modes.go b/test/features/cloudnative/switch_modes/switch_modes.go index 1a25d250dd..bb8b071b45 100644 --- a/test/features/cloudnative/switch_modes/switch_modes.go +++ b/test/features/cloudnative/switch_modes/switch_modes.go @@ -20,8 +20,7 @@ const ( ) func Feature(t *testing.T) features.Feature { - builder := features.New("switch from cloudnative to classic") - builder.WithLabel("name", "cloudnative-to-classic") + builder := features.New("cloudnative-to-classic") // build cloud native full stack dynakubeComponents secretConfig := tenant.GetSingleTenantSecret(t) diff --git a/test/features/cloudnative/upgrade/upgrade.go b/test/features/cloudnative/upgrade/upgrade.go index b985a5e999..c2a92cdda0 100644 --- a/test/features/cloudnative/upgrade/upgrade.go +++ b/test/features/cloudnative/upgrade/upgrade.go @@ -17,8 +17,7 @@ import ( ) func Feature(t *testing.T) features.Feature { - builder := features.New("upgrade a cloudnative installation") - builder.WithLabel("name", "cloudnative-upgrade") + builder := features.New("cloudnative-upgrade") secretConfig := tenant.GetSingleTenantSecret(t) testDynakube := *dynakube.New( dynakube.WithApiUrl(secretConfig.ApiUrl), diff --git a/test/features/edgeconnect/edgeconnect.go b/test/features/edgeconnect/edgeconnect.go index e72159084c..2075e47bec 100644 --- a/test/features/edgeconnect/edgeconnect.go +++ b/test/features/edgeconnect/edgeconnect.go @@ -38,8 +38,7 @@ type tenantConfig struct { } func NormalModeFeature(t *testing.T) features.Feature { - builder := features.New("install edgeconnect - normal mode") - builder.WithLabel("name", "edgeconnect-install") + builder := features.New("edgeconnect-install") secretConfig := tenant.GetEdgeConnectTenantSecret(t) @@ -72,8 +71,7 @@ func NormalModeFeature(t *testing.T) features.Feature { } func ProvisionerModeFeature(t *testing.T) features.Feature { - builder := features.New("install edgeconnect - provisioner mode") - builder.WithLabel("name", "edgeconnect-install-provisioner") + builder := features.New("edgeconnect-install-provisioner") secretConfig := tenant.GetEdgeConnectTenantSecret(t) @@ -109,8 +107,7 @@ func ProvisionerModeFeature(t *testing.T) features.Feature { } func AutomationModeFeature(t *testing.T) features.Feature { - builder := features.New("install edgeconnect - k8s automation mode") - builder.WithLabel("name", "edgeconnect-install-k8s-automation") + builder := features.New("edgeconnect-install-k8s-automation") secretConfig := tenant.GetEdgeConnectTenantSecret(t) diff --git a/test/features/publicregistry/publicregistry.go b/test/features/publicregistry/publicregistry.go index 4dcd1d3d8d..e4325210ec 100644 --- a/test/features/publicregistry/publicregistry.go +++ b/test/features/publicregistry/publicregistry.go @@ -24,9 +24,7 @@ import ( // // It determines the latest version of each image using the registry. func Feature(t *testing.T) features.Feature { - builder := features.New("Public registry images") - // Register operator install - builder.WithLabel("name", "public-registry-images") + builder := features.New("public-registry-images") secretConfig := tenant.GetSingleTenantSecret(t) oaSpec := cloudnative.DefaultCloudNativeSpec() diff --git a/test/features/support_archive/support_archive.go b/test/features/support_archive/support_archive.go index c1164572a3..6ab0a1aed7 100644 --- a/test/features/support_archive/support_archive.go +++ b/test/features/support_archive/support_archive.go @@ -43,8 +43,7 @@ type CustomResources struct { // to the standard output is a valid tar.gz package and contains required *operator-version.txt* // file. func Feature(t *testing.T) features.Feature { - builder := features.New("support archive execution") - builder.WithLabel("name", "support-archive") + builder := features.New("support-archive") secretConfig := tenant.GetSingleTenantSecret(t) edgeconnectSecretConfig := tenant.GetEdgeConnectTenantSecret(t) diff --git a/test/helpers/components/activegate/installation.go b/test/helpers/components/activegate/installation.go index 9df7c5e625..c34226e711 100644 --- a/test/helpers/components/activegate/installation.go +++ b/test/helpers/components/activegate/installation.go @@ -9,7 +9,6 @@ import ( "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube" "github.com/Dynatrace/dynatrace-operator/pkg/controllers/dynakube/activegate/consts" - "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/pod" "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/statefulset" "github.com/Dynatrace/dynatrace-operator/test/helpers/logs" "sigs.k8s.io/e2e-framework/pkg/envconf" @@ -31,7 +30,3 @@ func GetActiveGatePodName(dk *dynakube.DynaKube, component string) string { func ReadActiveGateLog(ctx context.Context, t *testing.T, envConfig *envconf.Config, dk *dynakube.DynaKube, component string) string { return logs.ReadLog(ctx, t, envConfig, dk.Namespace, GetActiveGatePodName(dk, component), consts.ActiveGateContainerName) } - -func WaitForStatefulSetPodsDeletion(dk *dynakube.DynaKube, component string) features.Func { - return pod.WaitForPodsDeletionWithOwner(GetActiveGateStateFulSetName(dk, component), dk.Namespace) -} diff --git a/test/helpers/components/dynakube/options.go b/test/helpers/components/dynakube/options.go index 1a57ef9df3..223f2f53ad 100644 --- a/test/helpers/components/dynakube/options.go +++ b/test/helpers/components/dynakube/options.go @@ -150,9 +150,3 @@ func WithApplicationMonitoringSpec(applicationMonitoringSpec *dynakube.Applicati dk.Spec.OneAgent.ApplicationMonitoring = applicationMonitoringSpec } } - -func WithNetworkZone(networkZone string) Option { - return func(dk *dynakube.DynaKube) { - dk.Spec.NetworkZone = networkZone - } -} diff --git a/test/helpers/registry/registry.go b/test/helpers/registry/registry.go index 851fd1e399..659f4f954d 100644 --- a/test/helpers/registry/registry.go +++ b/test/helpers/registry/registry.go @@ -19,19 +19,45 @@ const ( cmPublicECR = "public.ecr.aws/dynatrace/dynatrace-codemodules" ) +var ( + latestActiveGateURI string + latestOneAgentURI string + latestCodeModuleURI string +) + func GetLatestActiveGateImageURI(t *testing.T) string { - return getLatestImageURI(t, agPublicECR) + t.Helper() + + if latestActiveGateURI == "" { + latestActiveGateURI = getLatestImageURI(t, agPublicECR) + } + + return latestActiveGateURI } func GetLatestOneAgentImageURI(t *testing.T) string { - return getLatestImageURI(t, oaPublicECR) + t.Helper() + + if latestOneAgentURI == "" { + latestOneAgentURI = getLatestImageURI(t, oaPublicECR) + } + + return latestOneAgentURI } func GetLatestCodeModulesImageURI(t *testing.T) string { - return getLatestImageURI(t, cmPublicECR) + t.Helper() + + if latestCodeModuleURI == "" { + latestCodeModuleURI = getLatestImageURI(t, cmPublicECR) + } + + return latestCodeModuleURI } func getLatestImageURI(t *testing.T, repoURI string) string { + t.Helper() + repo, err := name.NewRepository(repoURI) require.NoError(t, err) diff --git a/test/helpers/tenant/network_zone.go b/test/helpers/tenant/network_zone.go deleted file mode 100644 index 58bc1ca603..0000000000 --- a/test/helpers/tenant/network_zone.go +++ /dev/null @@ -1,167 +0,0 @@ -//go:build e2e - -package tenant - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "io" - "net/http" - "strings" - "testing" - "time" - - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "sigs.k8s.io/e2e-framework/klient/wait" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "sigs.k8s.io/e2e-framework/pkg/features" -) - -type FallbackMode string - -const ( - FallbackAnyActiveGate FallbackMode = "ANY_ACTIVE_GATE" - FallbackNone FallbackMode = "NONE" - FallbackDefaultZone FallbackMode = "ONLY_DEFAULT_ZONE" -) - -type networkZoneRequestBody struct { - AlternativeZones []string `json:"alternativeZones,omitempty"` - FallbackMode string `json:"fallbackMode,omitempty"` - Id string `json:"id,omitempty"` -} - -func CreateNetworkZone(secret Secret, networkZone string, alternativeZones []string, fallbackMode FallbackMode) features.Func { - return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context { - // API documentation - // https://www.dynatrace.com/support/help/dynatrace-api/environment-api/network-zones/put-network-zone - - request := networkZoneRequestBody{ - AlternativeZones: alternativeZones, - FallbackMode: string(fallbackMode), - } - - body, err := json.Marshal(request) - require.NoError(t, err) - - statusCode, statusMsg, err := executeNetworkZoneRequest(secret, networkZone, http.MethodPut, bytes.NewReader(body)) - require.NoError(t, err) - assert.Truef(t, statusCode == http.StatusCreated || statusCode == http.StatusNoContent, statusMsg) - - return ctx - } -} - -func WaitForNetworkZoneDeletion(secret Secret, networkZone string) features.Func { - return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context { - err := wait.For(deleteNetworkZone(secret, networkZone), wait.WithTimeout(10*time.Minute), wait.WithInterval(30*time.Second)) - require.NoError(t, err) - - return ctx - } -} - -func WaitForNetworkZone(secret Secret, networkZone string, fallbackMode FallbackMode) features.Func { - return func(ctx context.Context, t *testing.T, envConfig *envconf.Config) context.Context { - err := wait.For(checkNetworkZone(secret, networkZone, fallbackMode), wait.WithTimeout(2*time.Minute), wait.WithInterval(5*time.Second)) - require.NoError(t, err) - - return ctx - } -} - -func createNetworkZoneRequest(secret Secret, networkZone string, method string, body io.Reader) (*http.Request, error) { - nzApiUrl := fmt.Sprintf("%s/v2/networkZones/%s", secret.ApiUrl, networkZone) - - req, err := http.NewRequest(method, nzApiUrl, body) - if err != nil { - return nil, err - } - req.Header.Add("Authorization", "Api-Token "+secret.ApiToken) - req.Header.Add("Content-Type", "application/json") - - return req, nil -} - -func executeNetworkZoneRequest(secret Secret, networkZone string, method string, body io.Reader) (statusCode int, msg string, err error) { - client := &http.Client{} - - req, err := createNetworkZoneRequest(secret, networkZone, method, body) - if err != nil { - return 0, "", err - } - - resp, err := client.Do(req) - defer func() { - if resp != nil && resp.Body != nil { - _ = resp.Body.Close() - } - }() - - if err != nil { - return 0, "", err - } - if resp == nil { - return 0, "", errors.Errorf("response was nil") - } - - var respBody []byte - if resp.Body != nil { - respBody, err = io.ReadAll(resp.Body) - if err != nil { - return resp.StatusCode, resp.Status, err - } - } - - return resp.StatusCode, resp.Status + " " + string(respBody), nil -} - -func deleteNetworkZone(secret Secret, networkZone string) func(ctx context.Context) (done bool, err error) { - return func(ctx context.Context) (done bool, err error) { - // API documentation - // https://www.dynatrace.com/support/help/dynatrace-api/environment-api/network-zones/del-network-zone - - statusCode, statusMsg, err := executeNetworkZoneRequest(secret, networkZone, http.MethodDelete, nil) - if err != nil { - return false, err - } - - if statusCode == http.StatusOK || statusCode == http.StatusNoContent { - return true, nil - } else if statusCode == http.StatusBadRequest { - // this error can indicate, that the network zone is still used by an ActiveGate, just try again later - return false, nil - } - - return false, errors.Errorf("delete network zone request returned status = %d (%s)", statusCode, statusMsg) - } -} - -func checkNetworkZone(secret Secret, networkZone string, fallbackMode FallbackMode) func(ctx context.Context) (done bool, err error) { - return func(ctx context.Context) (done bool, err error) { - // API documentation - // https://www.dynatrace.com/support/help/dynatrace-api/environment-api/network-zones/del-network-zone - - statusCode, statusMsg, err := executeNetworkZoneRequest(secret, networkZone, http.MethodGet, nil) - if err != nil { - return false, err - } - - if statusCode == http.StatusOK { - if strings.Contains(statusMsg, fmt.Sprintf("\"fallbackMode\":\"%s\"", fallbackMode)) { - return true, nil - } else { - return true, errors.Errorf("network zone fallback mode incorrect (expected: %s, actual: %s)", fallbackMode, statusMsg) - } - } else if statusCode == http.StatusNotFound { - // network zone does not exist - return false, nil - } - - return false, errors.Errorf("delete network zone request returned status = %d (%s)", statusCode, statusMsg) - } -} diff --git a/test/scenarios/filter.go b/test/scenarios/filter.go new file mode 100644 index 0000000000..e1955a49e1 --- /dev/null +++ b/test/scenarios/filter.go @@ -0,0 +1,20 @@ +package scenarios + +import ( + "sigs.k8s.io/e2e-framework/pkg/envconf" + "sigs.k8s.io/e2e-framework/pkg/features" +) + +func FilterFeatures(cfg envconf.Config, feats []features.Feature) (filtered []features.Feature) { + if cfg.FeatureRegex() != nil { + for _, feat := range feats { + if cfg.FeatureRegex().Match([]byte(feat.Name())) { + filtered = append(filtered, feat) + } + } + } else { + filtered = feats + } + + return +} diff --git a/test/scenarios/istio/istio_test.go b/test/scenarios/istio/istio_test.go index fcfe3edbbc..26b697266e 100644 --- a/test/scenarios/istio/istio_test.go +++ b/test/scenarios/istio/istio_test.go @@ -15,14 +15,19 @@ import ( "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/environment" "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/namespace" "github.com/Dynatrace/dynatrace-operator/test/helpers/proxy" + "github.com/Dynatrace/dynatrace-operator/test/scenarios" "sigs.k8s.io/e2e-framework/pkg/env" + "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" ) -var testEnv env.Environment +var ( + testEnv env.Environment + cfg *envconf.Config +) func TestMain(m *testing.M) { - cfg := environment.GetStandardKubeClusterEnvConfig() + cfg = environment.GetStandardKubeClusterEnvConfig() testEnv = env.NewWithConfig(cfg) nsWithIstio := *namespace.New(operator.DefaultNamespace, namespace.WithIstio()) @@ -52,5 +57,6 @@ func TestIstio(t *testing.T) { codemodules.WithProxyAndAGCert(t, proxy.ProxySpec), codemodules.WithProxyCAAndAGCert(t, proxy.HttpsProxySpec), } - testEnv.Test(t, feats...) + + testEnv.Test(t, scenarios.FilterFeatures(*cfg, feats)...) } diff --git a/test/scenarios/release/release_test.go b/test/scenarios/release/release_test.go index 8a679873f1..4559abc2bd 100644 --- a/test/scenarios/release/release_test.go +++ b/test/scenarios/release/release_test.go @@ -9,16 +9,21 @@ import ( "github.com/Dynatrace/dynatrace-operator/test/helpers" "github.com/Dynatrace/dynatrace-operator/test/helpers/components/operator" "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/environment" + "github.com/Dynatrace/dynatrace-operator/test/scenarios" "sigs.k8s.io/e2e-framework/pkg/env" + "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" ) -var testEnv env.Environment +var ( + testEnv env.Environment + cfg *envconf.Config +) const releaseTag = "1.1.0" func TestMain(m *testing.M) { - cfg := environment.GetStandardKubeClusterEnvConfig() + cfg = environment.GetStandardKubeClusterEnvConfig() testEnv = env.NewWithConfig(cfg) testEnv.Setup( helpers.SetScheme, @@ -35,5 +40,6 @@ func TestRelease(t *testing.T) { feats := []features.Feature{ upgrade.Feature(t), } - testEnv.Test(t, feats...) + + testEnv.Test(t, scenarios.FilterFeatures(*cfg, feats)...) } diff --git a/test/scenarios/standard/standard_test.go b/test/scenarios/standard/standard_test.go index b818418de5..d70bd58afd 100644 --- a/test/scenarios/standard/standard_test.go +++ b/test/scenarios/standard/standard_test.go @@ -12,7 +12,6 @@ import ( "github.com/Dynatrace/dynatrace-operator/test/features/cloudnative/codemodules" cloudnativeDefault "github.com/Dynatrace/dynatrace-operator/test/features/cloudnative/default" disabledAutoInjection "github.com/Dynatrace/dynatrace-operator/test/features/cloudnative/disabled_auto_injection" - "github.com/Dynatrace/dynatrace-operator/test/features/cloudnative/network_zones" cloudToClassic "github.com/Dynatrace/dynatrace-operator/test/features/cloudnative/switch_modes" "github.com/Dynatrace/dynatrace-operator/test/features/edgeconnect" "github.com/Dynatrace/dynatrace-operator/test/features/publicregistry" @@ -20,14 +19,19 @@ import ( "github.com/Dynatrace/dynatrace-operator/test/helpers" "github.com/Dynatrace/dynatrace-operator/test/helpers/components/operator" "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/environment" + "github.com/Dynatrace/dynatrace-operator/test/scenarios" "sigs.k8s.io/e2e-framework/pkg/env" + "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" ) -var testEnv env.Environment +var ( + testEnv env.Environment + cfg *envconf.Config +) func TestMain(m *testing.M) { - cfg := environment.GetStandardKubeClusterEnvConfig() + cfg = environment.GetStandardKubeClusterEnvConfig() testEnv = env.NewWithConfig(cfg) testEnv.Setup( helpers.SetScheme, @@ -42,7 +46,6 @@ func TestMain(m *testing.M) { func TestStandard(t *testing.T) { feats := []features.Feature{ - network_zones.Feature(t), // TODO: Fix so it can be enabled during pipeline tests, because if other tests deploy an ActiveGate then the network zone CAN still be present, which will make the test fail activegate.Feature(t, nil), cloudnativeDefault.Feature(t, false), applicationmonitoring.MetadataEnrichment(t), @@ -60,5 +63,6 @@ func TestStandard(t *testing.T) { classicToCloud.Feature(t), cloudToClassic.Feature(t), } - testEnv.Test(t, feats...) + + testEnv.Test(t, scenarios.FilterFeatures(*cfg, feats)...) }