Răsfoiți Sursa

e2e: add v2 fake provider bootstrap plumbing

Moritz Johner 2 luni în urmă
părinte
comite
5919ea40ce

+ 3 - 0
e2e/Makefile

@@ -18,6 +18,7 @@ export GOMODCACHE ?= $(CURDIR)/.cache/go-mod
 export OCI_IMAGE_NAME = ghcr.io/external-secrets/external-secrets
 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_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"
 
 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')
@@ -75,6 +76,7 @@ test.v2: start-kind e2e-image ## Run v2 e2e tests against current kube context
 		ARCH=amd64 \
 		DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux"
 	$(if $(filter true,$(SKIP_PROVIDER_KUBERNETES_BUILD)),,$(TEST_V2_PROVIDER_KUBERNETES_BUILD_CMD))
+	$(TEST_V2_PROVIDER_FAKE_BUILD_CMD)
 	$(MAKE) -C ../ docker.build.controller.e2e \
 		IMAGE_NAME=$(OCI_IMAGE_NAME) \
 		VERSION=$(VERSION) \
@@ -84,6 +86,7 @@ test.v2: start-kind e2e-image ## Run v2 e2e tests against current kube context
 	kind load docker-image --name="$(KIND_CLUSTER_NAME)" $(OCI_IMAGE_NAME):$(VERSION)
 	kind load docker-image --name="$(KIND_CLUSTER_NAME)" $(E2E_IMAGE_NAME):$(VERSION)
 	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-fake:$(VERSION)
 	KUBECTL_CONTEXT="$(KIND_CONTEXT)" GINKGO_LABELS="$(V2_GINKGO_LABELS)" E2E_PROVIDER_MODE="v2" TEST_SUITES="provider" ./run.sh
 
 test.managed: e2e-image ## Run e2e tests against current kube context

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

@@ -57,6 +57,25 @@ func WithV2KubernetesProvider() MutationFunc {
 	}
 }
 
+func WithV2FakeProvider() MutationFunc {
+	return func(eso *ESO) {
+		version := os.Getenv("VERSION")
+		vars := []StringTuple{
+			{Key: "providers.enabled", Value: "true"},
+			{Key: "providers.list[1].name", Value: "fake"},
+			{Key: "providers.list[1].type", Value: "fake"},
+			{Key: "providers.list[1].enabled", Value: "true"},
+			{Key: "providers.list[1].replicaCount", Value: "1"},
+			{Key: "providers.list[1].image.repository", Value: "ghcr.io/external-secrets/provider-fake"},
+			{Key: "providers.list[1].image.tag", Value: version},
+			{Key: "providers.list[1].image.pullPolicy", Value: "IfNotPresent"},
+		}
+		for _, variable := range vars {
+			setOrAppendVar(eso.HelmChart, variable)
+		}
+	}
+}
+
 func setOrAppendVar(chart *HelmChart, variable StringTuple) {
 	for i := range chart.Vars {
 		if chart.Vars[i].Key == variable.Key {

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

@@ -0,0 +1,79 @@
+/*
+Copyright © The ESO Authors
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    https://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package addon
+
+import "testing"
+
+func TestWithV2FakeProvider(t *testing.T) {
+	t.Setenv("VERSION", "test-version")
+
+	eso := NewESO(WithV2FakeProvider())
+
+	assertVarValue(t, eso.HelmChart, "providers.enabled", "true")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].name", "fake")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].type", "fake")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].enabled", "true")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].replicaCount", "1")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].image.repository", "ghcr.io/external-secrets/provider-fake")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].image.tag", "test-version")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].image.pullPolicy", "IfNotPresent")
+}
+
+func TestWithV2ProvidersCompose(t *testing.T) {
+	t.Setenv("VERSION", "test-version")
+
+	eso := NewESO(
+		WithV2Namespace(),
+		WithV2KubernetesProvider(),
+		WithV2FakeProvider(),
+	)
+
+	if eso.HelmChart.Namespace != v2HelmNamespace {
+		t.Fatalf("expected namespace %q, got %q", v2HelmNamespace, eso.HelmChart.Namespace)
+	}
+	if eso.HelmChart.ReleaseName != v2HelmReleaseName {
+		t.Fatalf("expected release name %q, got %q", v2HelmReleaseName, eso.HelmChart.ReleaseName)
+	}
+	if !containsArg(eso.HelmChart.Args, "--create-namespace") {
+		t.Fatalf("expected --create-namespace arg, got %v", eso.HelmChart.Args)
+	}
+
+	assertVarValue(t, eso.HelmChart, "v2.enabled", "true")
+	assertVarValue(t, eso.HelmChart, "providers.enabled", "true")
+	assertVarValue(t, eso.HelmChart, "providers.list[0].name", "kubernetes")
+	assertVarValue(t, eso.HelmChart, "providers.list[0].image.repository", "ghcr.io/external-secrets/provider-kubernetes")
+	assertVarValue(t, eso.HelmChart, "providers.list[0].image.tag", "test-version")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].name", "fake")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].type", "fake")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].image.repository", "ghcr.io/external-secrets/provider-fake")
+	assertVarValue(t, eso.HelmChart, "providers.list[1].image.tag", "test-version")
+}
+
+func assertVarValue(t *testing.T, chart *HelmChart, key, wantValue string) {
+	t.Helper()
+
+	for _, variable := range chart.Vars {
+		if variable.Key == key {
+			if variable.Value != wantValue {
+				t.Fatalf("expected %s=%s, got %s", key, wantValue, variable.Value)
+			}
+			return
+		}
+	}
+
+	t.Fatalf("expected %s=%s to be set", key, wantValue)
+}

+ 12 - 1
e2e/makefile_test.go

@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-
 package e2e
 
 import (
@@ -31,17 +30,29 @@ func TestV2MakeTargetCanSkipKubernetesProviderBuild(t *testing.T) {
 	if !strings.Contains(defaultDryRun, "docker.build.provider.kubernetes") {
 		t.Fatalf("expected default test.v2 dry-run to build the kubernetes provider image, output:\n%s", defaultDryRun)
 	}
+	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 !strings.Contains(defaultDryRun, "ghcr.io/external-secrets/provider-kubernetes:test-version") {
 		t.Fatalf("expected default test.v2 dry-run to still load the kubernetes provider image, output:\n%s", defaultDryRun)
 	}
+	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)
+	}
 
 	skippedDryRun := runMakeDryRun(t, "VERSION=test-version", "SKIP_PROVIDER_KUBERNETES_BUILD=true")
 	if strings.Contains(skippedDryRun, "docker.build.provider.kubernetes") {
 		t.Fatalf("expected skipped test.v2 dry-run to omit the kubernetes provider build, output:\n%s", skippedDryRun)
 	}
+	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 !strings.Contains(skippedDryRun, "ghcr.io/external-secrets/provider-kubernetes:test-version") {
 		t.Fatalf("expected skipped test.v2 dry-run to still load the kubernetes provider image, output:\n%s", skippedDryRun)
 	}
+	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)
+	}
 }
 
 func runMakeDryRun(t *testing.T, extraArgs ...string) string {

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

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