Skip to content

Commit

Permalink
add unit test to check if default image tags for k8s control plane co…
Browse files Browse the repository at this point in the history
…mponents are in sync
  • Loading branch information
hidalgopl committed Aug 7, 2024
1 parent b6b52f2 commit 7051fc2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 23 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package config

import (
_ "embed"
"fmt"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -378,3 +380,24 @@ func TestConfig_IsProFeatureEnabled(t *testing.T) {
})
}
}

func TestIfDefaultImagesVersionsAreInSync(t *testing.T) {
defaultConfig, err := NewDefaultConfig()
assert.NilError(t, err)
// this will fail when this test is moved or _init-containers.tpl is moved
initContainersTplFilePath := "../chart/templates/_init-containers.tpl"
tplBytes, err := os.ReadFile(initContainersTplFilePath)

assert.NilError(t, err)
assert.Equal(t, defaultConfig.ControlPlane.Distro.K8S.ControllerManager.Image.Tag, defaultConfig.ControlPlane.Distro.K8S.APIServer.Image.Tag)
assert.Equal(t, defaultConfig.ControlPlane.Distro.K8S.ControllerManager.Image.Tag, defaultConfig.ControlPlane.Distro.K8S.Scheduler.Image.Tag)
assert.Equal(t, defaultConfig.ControlPlane.Distro.K8S.APIServer.Image.Tag, defaultConfig.ControlPlane.Distro.K8S.Scheduler.Image.Tag)
expectedDefaultTag := fmt.Sprintf("{{- $defaultTag := \"%s\" -}}", defaultConfig.ControlPlane.Distro.K8S.ControllerManager.Image.Tag)
got := strings.Count(string(tplBytes), expectedDefaultTag)
assert.Equal(
t, got, 3,
fmt.Sprintf("please update $defaultTag in %s so it's equal to the "+
".Values.controlPlane.distro.k8s.controllerManager.image.tag",
initContainersTplFilePath),
)
}
3 changes: 1 addition & 2 deletions hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export GOFLAGS=-mod=vendor
# Test if we can build the program
echo "Building virtual cluster..."
go generate ./... && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cmd/vcluster/main.go || exit 1

# List packages
PKGS=$(go list ./... | grep -v -e /vendor/ -e /test)

echo "Start testing..."
fail=false
for pkg in $PKGS; do
Expand Down

0 comments on commit 7051fc2

Please sign in to comment.