Skip to content

Commit

Permalink
Improve dev environnement
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
evrardjp committed Nov 11, 2024
1 parent 4687d88 commit 0df8f7c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 13 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
77 changes: 67 additions & 10 deletions tests/kind/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0df8f7c

Please sign in to comment.