Просмотр исходного кода

test(gcp): wire provider v2 shared e2e setup

Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>
Moritz Johner 2 месяцев назад
Родитель
Сommit
66ee74bd87

+ 18 - 2
Makefile

@@ -403,7 +403,7 @@ docker.build.controller.e2e: build-$(LOCAL_GOARCH) ## Build the controller docke
 	@$(OK) $(DOCKER) build controller for $(LOCAL_GOARCH)
 
 .PHONY: docker.build.providers
-docker.build.providers: docker.build.provider.kubernetes docker.build.provider.aws docker.build.provider.fake ## Build all provider images
+docker.build.providers: docker.build.provider.kubernetes docker.build.provider.aws docker.build.provider.fake docker.build.provider.gcp ## Build all provider images
 
 .PHONY: docker.build.provider.kubernetes
 docker.build.provider.kubernetes: ## Build Kubernetes provider image
@@ -435,6 +435,16 @@ docker.build.provider.fake: ## Build Fake provider image
 		-t $(IMAGE_REGISTRY)/external-secrets/provider-fake:$(IMAGE_TAG)
 	@$(OK) $(DOCKER) build Fake provider
 
+.PHONY: docker.build.provider.gcp
+docker.build.provider.gcp: ## Build GCP provider image
+	@$(INFO) $(DOCKER) build GCP provider
+	@DOCKER_BUILDKIT=1 $(DOCKER) build \
+		-f providers/v2/gcp/Dockerfile \
+		. \
+		$(DOCKER_BUILD_ARGS) \
+		-t $(IMAGE_REGISTRY)/external-secrets/provider-gcp:$(IMAGE_TAG)
+	@$(OK) $(DOCKER) build GCP provider
+
 .PHONY: docker.push
 docker.push: docker.push.controller docker.push.providers ## Push all docker images to the registry
 
@@ -445,7 +455,7 @@ docker.push.controller: ## Push the controller docker image to the registry
 	@$(OK) $(DOCKER) push controller
 
 .PHONY: docker.push.providers
-docker.push.providers: docker.push.provider.kubernetes docker.push.provider.aws docker.push.provider.fake ## Push all provider images
+docker.push.providers: docker.push.provider.kubernetes docker.push.provider.aws docker.push.provider.fake docker.push.provider.gcp ## Push all provider images
 
 .PHONY: docker.push.provider.kubernetes
 docker.push.provider.kubernetes: ## Push Kubernetes provider image
@@ -465,6 +475,12 @@ docker.push.provider.fake: ## Push Fake provider image
 	@$(DOCKER) push $(IMAGE_REGISTRY)/external-secrets/provider-fake:$(IMAGE_TAG)
 	@$(OK) $(DOCKER) push Fake provider
 
+.PHONY: docker.push.provider.gcp
+docker.push.provider.gcp: ## Push GCP provider image
+	@$(INFO) $(DOCKER) push GCP provider
+	@$(DOCKER) push $(IMAGE_REGISTRY)/external-secrets/provider-gcp:$(IMAGE_TAG)
+	@$(OK) $(DOCKER) push GCP provider
+
 # RELEASE_TAG is tag to promote. Default is promoting to main branch, but can be overriden
 # to promote a tag to a specific version.
 RELEASE_TAG ?= $(IMAGE_TAG)

+ 3 - 0
e2e/Makefile

@@ -21,6 +21,7 @@ export IMAGE_NAME ?= $(OCI_IMAGE_NAME)
 TEST_V2_PROVIDER_KUBERNETES_BUILD_CMD = $(MAKE) -C ../ docker.build.provider.kubernetes VERSION=$(VERSION) ARCH=amd64 DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux"
 TEST_V2_PROVIDER_AWS_BUILD_CMD = $(MAKE) -C ../ docker.build.provider.aws VERSION=$(VERSION) ARCH=amd64 DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux"
 TEST_V2_PROVIDER_FAKE_BUILD_CMD = $(MAKE) -C ../ docker.build.provider.fake VERSION=$(VERSION) ARCH=amd64 DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux"
+TEST_V2_PROVIDER_GCP_BUILD_CMD = $(MAKE) -C ../ docker.build.provider.gcp VERSION=$(VERSION) ARCH=amd64 DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux"
 
 ifeq ($(shell git tag),)
 export VERSION ?= $(shell echo "v0.0.0-$$(git rev-list HEAD --count)-g$$(git describe --dirty --always)" | sed 's/-/./2' | sed 's/-/./2')
@@ -74,6 +75,7 @@ test.v2: start-kind e2e-image ## Run v2 e2e tests against current kube context
 	$(if $(filter true,$(SKIP_PROVIDER_KUBERNETES_BUILD)),,$(TEST_V2_PROVIDER_KUBERNETES_BUILD_CMD))
 	$(TEST_V2_PROVIDER_AWS_BUILD_CMD)
 	$(TEST_V2_PROVIDER_FAKE_BUILD_CMD)
+	$(TEST_V2_PROVIDER_GCP_BUILD_CMD)
 ifneq ($(IMAGE_NAME),$(OCI_IMAGE_NAME))
 	$(MAKE) -C ../ docker.build.controller.e2e \
 		IMAGE_NAME=$(OCI_IMAGE_NAME) \
@@ -89,6 +91,7 @@ endif
 	kind load docker-image --name="$(KIND_CLUSTER_NAME)" ghcr.io/external-secrets/provider-kubernetes:$(VERSION)
 	kind load docker-image --name="$(KIND_CLUSTER_NAME)" ghcr.io/external-secrets/provider-aws:$(VERSION)
 	kind load docker-image --name="$(KIND_CLUSTER_NAME)" ghcr.io/external-secrets/provider-fake:$(VERSION)
+	kind load docker-image --name="$(KIND_CLUSTER_NAME)" ghcr.io/external-secrets/provider-gcp:$(VERSION)
 ifeq ($(CI),true)
 	docker system prune --all --force --volumes
 endif

+ 7 - 0
e2e/framework/addon/eso_v2_mutators.go

@@ -58,6 +58,13 @@ func WithV2AWSProvider() MutationFunc {
 	}
 }
 
+func WithV2GCPProvider() MutationFunc {
+	return func(eso *ESO) {
+		ensureV2ProviderConfig(eso.HelmChart)
+		setProvider(eso.HelmChart, "gcp", "gcp", "ghcr.io/external-secrets/provider-gcp", os.Getenv("VERSION"))
+	}
+}
+
 func WithV2ProviderServiceAccount(providerName, serviceAccountName string) MutationFunc {
 	return func(eso *ESO) {
 		index := findProviderIndex(eso.HelmChart, providerName)

+ 38 - 0
e2e/framework/addon/eso_v2_mutators_test.go

@@ -74,6 +74,32 @@ func TestWithV2AWSProvider(t *testing.T) {
 	}
 }
 
+func TestWithV2GCPProvider(t *testing.T) {
+	t.Setenv("VERSION", "test-version")
+
+	eso := NewESO(WithV2GCPProvider())
+
+	assertV2ProviderBaseVars(t, eso.HelmChart)
+	assertVarValue(t, eso.HelmChart, "providers.enabled", "true")
+	assertProvider(
+		t,
+		eso.HelmChart,
+		"gcp",
+		"gcp",
+		"ghcr.io/external-secrets/provider-gcp",
+		"test-version",
+	)
+	assertSequentialProviderIndexes(t, eso.HelmChart)
+
+	providers := providerEntries(t, eso.HelmChart)
+	if len(providers) != 1 {
+		t.Fatalf("expected exactly one provider entry, got %d", len(providers))
+	}
+	if providers[0].Name != "gcp" {
+		t.Fatalf("expected gcp to be at index 0 when standalone, got index 0 name %q", providers[0].Name)
+	}
+}
+
 func TestWithV2ProvidersComposeIncludesAWS(t *testing.T) {
 	t.Setenv("VERSION", "test-version")
 
@@ -82,6 +108,7 @@ func TestWithV2ProvidersComposeIncludesAWS(t *testing.T) {
 		WithV2KubernetesProvider(),
 		WithV2FakeProvider(),
 		WithV2AWSProvider(),
+		WithV2GCPProvider(),
 	)
 
 	if eso.HelmChart.Namespace != v2HelmNamespace {
@@ -120,6 +147,14 @@ func TestWithV2ProvidersComposeIncludesAWS(t *testing.T) {
 		"ghcr.io/external-secrets/provider-aws",
 		"test-version",
 	)
+	assertProvider(
+		t,
+		eso.HelmChart,
+		"gcp",
+		"gcp",
+		"ghcr.io/external-secrets/provider-gcp",
+		"test-version",
+	)
 	assertSequentialProviderIndexes(t, eso.HelmChart)
 
 	providers := providerEntries(t, eso.HelmChart)
@@ -132,6 +167,9 @@ func TestWithV2ProvidersComposeIncludesAWS(t *testing.T) {
 	if providers[2].Name != "aws" {
 		t.Fatalf("expected aws to be third provider entry, got %q at index 2", providers[2].Name)
 	}
+	if providers[3].Name != "gcp" {
+		t.Fatalf("expected gcp to be fourth provider entry, got %q at index 3", providers[3].Name)
+	}
 }
 
 func TestWithV2FakeProviderDoesNotDuplicateOnRepeat(t *testing.T) {

+ 29 - 2
e2e/makefile_test.go

@@ -26,7 +26,10 @@ import (
 const (
 	testVersionArg           = "VERSION=test-version"
 	kubernetesBuildTarget    = "docker.build.provider.kubernetes"
+	gcpBuildTarget           = "docker.build.provider.gcp"
 	kubernetesProviderImage  = "ghcr.io/external-secrets/provider-kubernetes:test-version"
+	gcpProviderImage         = "ghcr.io/external-secrets/provider-gcp:test-version"
+	gcpProviderImageLoad     = `kind load docker-image --name="external-secrets" ghcr.io/external-secrets/provider-gcp:test-version`
 	helmDependencyEnsureCmd  = "../hack/helm.dependency.ensure.sh ../deploy/charts/external-secrets"
 	controllerImageLoadCount = `kind load docker-image --name="external-secrets" ghcr.io/external-secrets/external-secrets:test-version`
 	controllerImageBuildCmd  = "docker.build.controller.e2e"
@@ -50,12 +53,18 @@ func TestClassicMakeTargetBuildsOnlyControllerImageOnce(t *testing.T) {
 	if strings.Contains(dryRun, "docker.build.provider.fake") {
 		t.Fatalf("expected classic test dry-run to omit fake provider image builds, output:\n%s", dryRun)
 	}
+	if strings.Contains(dryRun, gcpBuildTarget) {
+		t.Fatalf("expected classic test dry-run to omit gcp provider image builds, output:\n%s", dryRun)
+	}
 	if count := strings.Count(dryRun, controllerImageLoadCount); count != 1 {
 		t.Fatalf("expected classic test dry-run to load the controller image once, got %d occurrences, output:\n%s", count, dryRun)
 	}
 	if strings.Contains(dryRun, kubernetesProviderImage) {
 		t.Fatalf("expected classic test dry-run to avoid loading the kubernetes provider image, output:\n%s", dryRun)
 	}
+	if strings.Contains(dryRun, gcpProviderImage) {
+		t.Fatalf("expected classic test dry-run to avoid loading the gcp provider image, output:\n%s", dryRun)
+	}
 	if !strings.Contains(dryRun, helmDependencyEnsureCmd) {
 		t.Fatalf("expected classic test dry-run to ensure helm dependencies before copying the chart, output:\n%s", dryRun)
 	}
@@ -77,6 +86,9 @@ func TestV2MakeTargetCanSkipKubernetesProviderBuild(t *testing.T) {
 	if !strings.Contains(defaultDryRun, "docker.build.provider.fake") {
 		t.Fatalf("expected default test.v2 dry-run to build the fake provider image, output:\n%s", defaultDryRun)
 	}
+	if count := strings.Count(defaultDryRun, gcpBuildTarget); count != 1 {
+		t.Fatalf("expected default test.v2 dry-run to build the gcp provider image once, got %d occurrences, output:\n%s", count, defaultDryRun)
+	}
 	if count := strings.Count(defaultDryRun, controllerImageLoadCount); count != 1 {
 		t.Fatalf("expected default test.v2 dry-run to load the controller image once, got %d occurrences, output:\n%s", count, defaultDryRun)
 	}
@@ -89,6 +101,12 @@ func TestV2MakeTargetCanSkipKubernetesProviderBuild(t *testing.T) {
 	if !strings.Contains(defaultDryRun, "ghcr.io/external-secrets/provider-fake:test-version") {
 		t.Fatalf("expected default test.v2 dry-run to load the fake provider image, output:\n%s", defaultDryRun)
 	}
+	if !strings.Contains(defaultDryRun, gcpProviderImage) {
+		t.Fatalf("expected default test.v2 dry-run to load the gcp provider image, output:\n%s", defaultDryRun)
+	}
+	if count := strings.Count(defaultDryRun, gcpProviderImageLoad); count != 1 {
+		t.Fatalf("expected default test.v2 dry-run to load the gcp provider image once, got %d occurrences, output:\n%s", count, defaultDryRun)
+	}
 	if !strings.Contains(defaultDryRun, helmDependencyEnsureCmd) {
 		t.Fatalf("expected default test.v2 dry-run to ensure helm dependencies before copying the chart, output:\n%s", defaultDryRun)
 	}
@@ -109,6 +127,9 @@ func TestV2MakeTargetCanSkipKubernetesProviderBuild(t *testing.T) {
 	if !strings.Contains(skippedDryRun, "docker.build.provider.fake") {
 		t.Fatalf("expected skipped test.v2 dry-run to still build the fake provider image, output:\n%s", skippedDryRun)
 	}
+	if count := strings.Count(skippedDryRun, gcpBuildTarget); count != 1 {
+		t.Fatalf("expected skipped test.v2 dry-run to still build the gcp provider image once, got %d occurrences, output:\n%s", count, skippedDryRun)
+	}
 	if count := strings.Count(skippedDryRun, controllerImageLoadCount); count != 1 {
 		t.Fatalf("expected skipped test.v2 dry-run to load the controller image once, got %d occurrences, output:\n%s", count, skippedDryRun)
 	}
@@ -121,6 +142,12 @@ func TestV2MakeTargetCanSkipKubernetesProviderBuild(t *testing.T) {
 	if !strings.Contains(skippedDryRun, "ghcr.io/external-secrets/provider-fake:test-version") {
 		t.Fatalf("expected skipped test.v2 dry-run to still load the fake provider image, output:\n%s", skippedDryRun)
 	}
+	if !strings.Contains(skippedDryRun, gcpProviderImage) {
+		t.Fatalf("expected skipped test.v2 dry-run to still load the gcp provider image, output:\n%s", skippedDryRun)
+	}
+	if count := strings.Count(skippedDryRun, gcpProviderImageLoad); count != 1 {
+		t.Fatalf("expected skipped test.v2 dry-run to still load the gcp provider image once, got %d occurrences, output:\n%s", count, skippedDryRun)
+	}
 	if !strings.Contains(skippedDryRun, helmDependencyEnsureCmd) {
 		t.Fatalf("expected skipped test.v2 dry-run to ensure helm dependencies before copying the chart, output:\n%s", skippedDryRun)
 	}
@@ -142,10 +169,10 @@ func TestV2OperationalMakeTarget(t *testing.T) {
 	t.Parallel()
 
 	dryRun := runMakeDryRun(t, "test.v2.operational", testVersionArg)
-	if !strings.Contains(dryRun, `V2_GINKGO_LABELS='v2 && operational && fake'`) {
+	if !strings.Contains(dryRun, "V2_GINKGO_LABELS=") || !strings.Contains(dryRun, "v2 && operational && fake") {
 		t.Fatalf("expected operational labels in target, got:\n%s", dryRun)
 	}
-	if !strings.Contains(dryRun, `V2_TEST_SUITES='provider'`) {
+	if !strings.Contains(dryRun, "V2_TEST_SUITES=") || !strings.Contains(dryRun, "provider") {
 		t.Fatalf("expected provider suite in target, got:\n%s", dryRun)
 	}
 	if !strings.Contains(dryRun, `TEST_SUITES="provider"`) {

+ 1 - 0
e2e/suites/provider/suite_test.go

@@ -42,6 +42,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
 			addon.WithV2KubernetesProvider(),
 			addon.WithV2FakeProvider(),
 			addon.WithV2AWSProvider(),
+			addon.WithV2GCPProvider(),
 		))
 		return nil
 	}