Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions clustertest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ var testConfig = struct {
}{}

func TestMain(m *testing.M) {
defaultImageTag := "127.0.0.1:5000/control-plane:" + os.Getenv("CONTROL_PLANE_VERSION")

flag.BoolVar(&testConfig.skipCleanup, "skip-cleanup", false, "skip cleaning up resources created by the tests")
flag.BoolVar(&testConfig.skipImageBuild, "skip-image-build", false, "skip building the control plane image. this setting is implied true when a non-default image-tag is specified.")
flag.StringVar(&testConfig.imageTag, "image-tag", defaultImageTag, "the control plane image to test")
flag.StringVar(&testConfig.imageTag, "image-tag", "", "the control plane image to test")
flag.StringVar(&testConfig.dataDirPrefix, "data-dir", "", "the directory to store test data. defaults to clustertest/data")

flag.Parse()

if !testConfig.skipImageBuild && testConfig.imageTag == defaultImageTag {
buildImage()
if testConfig.imageTag == "" {
// No explicit image tag: derive the default from CONTROL_PLANE_VERSION.
// Fatal here (after flag parsing) so runs that supply -image-tag are
// never blocked by a missing version.
version := os.Getenv("CONTROL_PLANE_VERSION")
if version == "" {
log.Fatal("CONTROL_PLANE_VERSION is not set; ensure common.mk version resolution succeeded or pass -image-tag explicitly")
}
testConfig.imageTag = "127.0.0.1:5000/control-plane:" + version
if !testConfig.skipImageBuild {
buildImage()
} else {
log.Println("skipping image build")
}
} else {
log.Println("skipping image build")
}
Expand Down
5 changes: 4 additions & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ go-licenses=$(gobin)/go-licenses
CHANGIE_LATEST = $(shell $(changie) latest)
# deferred simple variable expansion pattern:
# https://make.mad-scientist.net/deferred-simple-variable-expansion/
CONTROL_PLANE_VERSION ?= $(eval CONTROL_PLANE_VERSION := $$(shell git fetch --quiet && git describe --tags --abbrev=0 --match 'v*' release/$$(CHANGIE_LATEST)))$(CONTROL_PLANE_VERSION)
# The 'git fetch' and 'git describe' will return the latest tag if we're on the
# release branch. The 'echo' returns our fallback for every other branch,
# including main.
CONTROL_PLANE_VERSION ?= $(eval CONTROL_PLANE_VERSION := $$(shell git fetch --quiet --tags && git describe --tags --abbrev=0 --match '$$(CHANGIE_LATEST)*' 2>/dev/null || echo '$$(CHANGIE_LATEST)'))$(CONTROL_PLANE_VERSION)

.PHONY: install-tools
install-tools:
Expand Down