From 0df8f7c8830387ab12ecf37912f9b8fe556d6577 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Mon, 11 Nov 2024 15:48:26 +0100 Subject: [PATCH] Improve dev environnement Without this patch, while developping (on uncommitted work), the image with previous SHA gets overriden, which leads to mishaps. This fixes it by ensuring only the kured:dev tags (full path and short one) are used everywhere. At the same time, it cleans up the main_test to be more flexible by passing more of the main features as options. Signed-off-by: Jean-Philippe Evrard --- Makefile | 7 ++-- tests/kind/main_test.go | 77 +++++++++++++++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index c81b1d31a..dd05d9aff 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ bootstrap-tools: $(HACKDIR) clean: rm -rf ./dist -kured: bootstrap-tools +kured: clean bootstrap-tools $(GORELEASER_CMD) build --clean --single-target --snapshot kured-all: bootstrap-tools @@ -39,8 +39,9 @@ kured-release-snapshot: bootstrap-tools image: kured $(SUDO) docker buildx build --no-cache --load -t ghcr.io/$(DH_ORG)/kured:$(VERSION) . -dev-image: image - $(SUDO) docker tag ghcr.io/$(DH_ORG)/kured:$(VERSION) kured:dev +dev-image: kured + $(SUDO) docker buildx build --no-cache --load -t ghcr.io/$(DH_ORG)/kured:dev . + $(SUDO) docker tag ghcr.io/$(DH_ORG)/kured:dev kured:dev dev-manifest: # basic e2e scenario diff --git a/tests/kind/main_test.go b/tests/kind/main_test.go index fec78a917..8df4c02e7 100644 --- a/tests/kind/main_test.go +++ b/tests/kind/main_test.go @@ -84,14 +84,27 @@ func LocalImage(nameTag string) Option { } } +// Deploy can be passed to NewKind to deploy extra components, in addition to the base deployment. +func WithClusterName(name string) Option { + return func(k *KindTest) { + k.clusterName = name + } +} + +func ForTestInstance(t *testing.T) Option { + return func(k *KindTest) { + k.testInstance = t + } +} + // NewKind creates a kind cluster given a name and set of Option instances. -func NewKindTester(kindClusterName string, filePath string, t *testing.T, options ...Option) *KindTest { +func NewKindTester(config string, options ...Option) *KindTest { k := &KindTest{ - clusterName: kindClusterName, + clusterName: "kured", timeout: 10 * time.Minute, - kindConfigPath: filePath, - testInstance: t, + kindConfigPath: config, + testInstance: nil, } for _, option := range options { option(k) @@ -157,7 +170,14 @@ func TestE2EWithCommand(t *testing.T) { kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds.yaml")) + k := NewKindTester( + kindClusterConfigFile, + ForTestInstance(t), + WithClusterName(kindClusterName), + LocalImage(kuredDevImage), + Deploy("../../kured-rbac.yaml"), + Deploy("testfiles/kured-ds.yaml"), + ) defer k.FlushLog() err := k.Create() @@ -207,7 +227,14 @@ func TestE2EWithSignal(t *testing.T) { kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-signal.yaml")) + k := NewKindTester( + kindClusterConfigFile, + ForTestInstance(t), + WithClusterName(kindClusterName), + LocalImage(kuredDevImage), + Deploy("../../kured-rbac.yaml"), + Deploy("testfiles/kured-ds-signal.yaml"), + ) defer k.FlushLog() err := k.Create() @@ -257,7 +284,14 @@ func TestE2EConcurrentWithCommand(t *testing.T) { kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent-command.yaml")) + k := NewKindTester( + kindClusterConfigFile, + ForTestInstance(t), + WithClusterName(kindClusterName), + LocalImage(kuredDevImage), + Deploy("../../kured-rbac.yaml"), + Deploy("testfiles/kured-ds-concurrent-command.yaml"), + ) defer k.FlushLog() err := k.Create() @@ -307,7 +341,14 @@ func TestE2EConcurrentWithSignal(t *testing.T) { kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent-signal.yaml")) + k := NewKindTester( + kindClusterConfigFile, + ForTestInstance(t), + WithClusterName(kindClusterName), + LocalImage(kuredDevImage), + Deploy("../../kured-rbac.yaml"), + Deploy("testfiles/kured-ds-concurrent-signal.yaml"), + ) defer k.FlushLog() err := k.Create() @@ -362,7 +403,16 @@ func TestCordonningIsKept(t *testing.T) { } else { manifest = "testfiles/kured-ds-concurrent-signal.yaml" } - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(manifest)) + + k := NewKindTester( + kindClusterConfigFile, + ForTestInstance(t), + WithClusterName(kindClusterName), + LocalImage(kuredDevImage), + Deploy("../../kured-rbac.yaml"), + Deploy(manifest), + ) + defer k.FlushLog() err := k.Create() @@ -405,7 +455,14 @@ func TestE2EBlocker(t *testing.T) { kindClusterConfigFile := "../../.github/kind-cluster-next.yaml" kindContext := fmt.Sprintf("kind-%v", kindClusterName) - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(fmt.Sprintf("testfiles/kured-ds-%v.yaml", variant))) + k := NewKindTester( + kindClusterConfigFile, + ForTestInstance(t), + WithClusterName(kindClusterName), + LocalImage(kuredDevImage), + Deploy("../../kured-rbac.yaml"), + Deploy(fmt.Sprintf("testfiles/kured-ds-%v.yaml", variant)), + ) defer k.FlushLog() err := k.Create()