From 6d5fd4cbbe9c46b372d10275247e6abfe59fa2e7 Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Mon, 3 Jun 2024 17:11:03 +0200 Subject: [PATCH] :bug: Fix labels validation print (#251) * Fix labels validation print Fixing fmt.Fprintln to correctly recognize first argument as a writer buffer. Bug was introduced in https://github.com/konveyor/kantra/pull/243 Should fix kantra CI. Signed-off-by: Marek Aufart * Force runnerImg env lookup Signed-off-by: Marek Aufart * Fix env config load override Signed-off-by: Marek Aufart * Revert "Fix env config load override" This reverts commit 2950638835a843a0d8bc2fb0d457404ae02aaaee. Signed-off-by: Marek Aufart * Update env settings with field values Signed-off-by: Marek Aufart * Adding RUNNER_IMG setting test Signed-off-by: Marek Aufart * Revert Settings changes Signed-off-by: Marek Aufart --------- Signed-off-by: Marek Aufart --- cmd/analyze.go | 6 +++--- cmd/settings.go | 7 ++++++- cmd/settings_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 cmd/settings_test.go diff --git a/cmd/analyze.go b/cmd/analyze.go index 48a0830e..b11f497c 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -495,12 +495,12 @@ func listOptionsFromLabels(sl []string, label string, out io.Writer) { sort.Strings(newSl) if label == outputv1.SourceTechnologyLabel { - fmt.Println(out, "available source technologies:") + fmt.Fprintln(out, "available source technologies:") } else { - fmt.Println(out, "available target technologies:") + fmt.Fprintln(out, "available target technologies:") } for _, tech := range newSl { - fmt.Println(out, tech) + fmt.Fprintln(out, tech) } } diff --git a/cmd/settings.go b/cmd/settings.go index 2c7828a0..cd2d1761 100644 --- a/cmd/settings.go +++ b/cmd/settings.go @@ -85,8 +85,13 @@ func (c *Config) trySetDefaultPodmanBin(file string) (found bool, err error) { } func (c *Config) loadRunnerImg() error { + // TODO(maufart): ensure Config struct works/parses it values from ENV and defaults correctly + runnerImg, found := os.LookupEnv("RUNNER_IMG"); + if !found { + runnerImg = "quay.io/konveyor/kantra" + } // if version tag is given in image - img := strings.TrimSuffix(RunnerImage, fmt.Sprintf(":%v", Version)) + img := strings.TrimSuffix(runnerImg, fmt.Sprintf(":%v", Version)) updatedImg := fmt.Sprintf("%v:%v", img, Version) err := os.Setenv("RUNNER_IMG", updatedImg) if err != nil { diff --git a/cmd/settings_test.go b/cmd/settings_test.go new file mode 100644 index 00000000..525edd2b --- /dev/null +++ b/cmd/settings_test.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "os" + "testing" +) + +// Test RUNNER_IMG settings +func TestRunnerImgDefault(t *testing.T) { + os.Unsetenv("RUNNER_IMG") // Ensure empty variable + s := &Config{} + s.Load(); + if s.RunnerImage != "quay.io/konveyor/kantra:latest" { + t.Errorf("Unexpected RUNNER_IMG default: %s", s.RunnerImage) + } +} + +func TestRunnerImgCustom(t *testing.T) { + os.Setenv("RUNNER_IMG", "quay.io/some-contributor/my-kantra") + s := &Config{} + s.Load(); + if s.RunnerImage != "quay.io/some-contributor/my-kantra:latest" { + t.Errorf("Unexpected RUNNER_IMG: %s", s.RunnerImage) + } +}