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 1aee6b2 commit a670d69
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ 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:
$(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
sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' kured-ds.yaml > tests/kind/testfiles/kured-ds.yaml
sed -e "s#image: ghcr.io/.*kured.*#image: ghcr.io/$(DH_ORG)/kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' kured-ds.yaml > tests/kind/testfiles/kured-ds.yaml
# signal e2e scenario
sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-signal.yaml
sed -e "s#image: ghcr.io/.*kured.*#image: ghcr.io/$(DH_ORG)/kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-signal.yaml
# concurrency e2e command scenario
sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds.yaml > tests/kind/testfiles/kured-ds-concurrent-command.yaml
sed -e "s#image: ghcr.io/.*kured.*#image: ghcr.io/$(DH_ORG)/kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds.yaml > tests/kind/testfiles/kured-ds-concurrent-command.yaml
# concurrency e2e signal scenario
sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-concurrent-signal.yaml
sed -e "s#image: ghcr.io/.*kured.*#image: ghcr.io/$(DH_ORG)/kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-concurrent-signal.yaml
# pod blocker e2e signal scenario
sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--blocking-pod-selector=name=temperamental/\1--blocking-pod-selector=app=blocker/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-podblocker.yaml
sed -e "s#image: ghcr.io/.*kured.*#image: ghcr.io/$(DH_ORG)/kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--blocking-pod-selector=name=temperamental/\1--blocking-pod-selector=app=blocker/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-podblocker.yaml

e2e-test: dev-manifest dev-image
echo "Running ALL go tests"
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 a670d69

Please sign in to comment.