From 4078b04005ca5bb47aa6bb7954f075fa9c0ca755 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Wed, 6 Mar 2024 15:07:14 -0500 Subject: [PATCH] include troubleshoot and kubectl binary versions in metadata (#432) * include troubleshoot and kubectl binary versions in metadata * ensure versions show up * remove expected breakage --- Makefile | 2 ++ cmd/embedded-cluster/types/types.go | 13 +++++++++++++ cmd/embedded-cluster/version.go | 15 ++++----------- e2e/version_test.go | 14 ++++++++++---- pkg/defaults/defaults.go | 5 +++++ 5 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 cmd/embedded-cluster/types/types.go diff --git a/Makefile b/Makefile index e5ab8981f..00ac8cede 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,8 @@ TROUBLESHOOT_VERSION = v0.83.0 LD_FLAGS = -X github.com/replicatedhq/embedded-cluster/pkg/defaults.K0sVersion=$(K0S_VERSION) \ -X github.com/replicatedhq/embedded-cluster/pkg/defaults.Version=$(VERSION) \ -X github.com/replicatedhq/embedded-cluster/pkg/defaults.K0sBinaryURL=$(K0S_BINARY_SOURCE_OVERRIDE) \ + -X github.com/replicatedhq/embedded-cluster/pkg/defaults.TroubleshootVersion=$(TROUBLESHOOT_VERSION) \ + -X github.com/replicatedhq/embedded-cluster/pkg/defaults.KubectlVersion=$(KUBECTL_VERSION) \ -X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.ChartURL=$(ADMIN_CONSOLE_CHART_URL) \ -X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.ChartName=$(ADMIN_CONSOLE_CHART_NAME) \ -X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.Version=$(ADMIN_CONSOLE_CHART_VERSION) \ diff --git a/cmd/embedded-cluster/types/types.go b/cmd/embedded-cluster/types/types.go new file mode 100644 index 000000000..cc6233e59 --- /dev/null +++ b/cmd/embedded-cluster/types/types.go @@ -0,0 +1,13 @@ +package types + +import "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1" + +// ReleaseMetadata holds the metadata about a specific release, including addons and +// their versions. +type ReleaseMetadata struct { + Versions map[string]string + K0sSHA string + K0sBinaryURL string + Configs v1beta1.HelmExtensions + Protected map[string][]string +} diff --git a/cmd/embedded-cluster/version.go b/cmd/embedded-cluster/version.go index 3e1e7e8bf..9b79f9a3e 100644 --- a/cmd/embedded-cluster/version.go +++ b/cmd/embedded-cluster/version.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "github.com/replicatedhq/embedded-cluster/cmd/embedded-cluster/types" "sort" "strings" @@ -53,16 +54,6 @@ var versionCommand = &cli.Command{ }, } -// ReleaseMetadata holds the metadata about a specific release, including addons and -// their versions. -type ReleaseMetadata struct { - Versions map[string]string - K0sSHA string - K0sBinaryURL string - Configs k0sconfig.HelmExtensions - Protected map[string][]string -} - var metadataCommand = &cli.Command{ Name: "metadata", Usage: "Print metadata about this release", @@ -75,6 +66,8 @@ var metadataCommand = &cli.Command{ } versions["Kubernetes"] = defaults.K0sVersion versions["Installer"] = defaults.Version + versions["Troubleshoot"] = defaults.TroubleshootVersion + versions["Kubectl"] = defaults.KubectlVersion channelRelease, err := release.GetChannelRelease() if err == nil && channelRelease != nil { versions[defaults.BinaryName()] = channelRelease.VersionLabel @@ -83,7 +76,7 @@ var metadataCommand = &cli.Command{ if err != nil { return fmt.Errorf("unable to get k0s binary sha256: %w", err) } - meta := ReleaseMetadata{ + meta := types.ReleaseMetadata{ Versions: versions, K0sSHA: sha, K0sBinaryURL: defaults.K0sBinaryURL, diff --git a/e2e/version_test.go b/e2e/version_test.go index 0ce831555..5cda2397b 100644 --- a/e2e/version_test.go +++ b/e2e/version_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1" + "github.com/replicatedhq/embedded-cluster/cmd/embedded-cluster/types" "github.com/replicatedhq/embedded-cluster/e2e/cluster" ) @@ -50,14 +50,20 @@ func TestVersion(t *testing.T) { } output = fmt.Sprintf("%s\n%s", stdout, stderr) - parsed := struct { - Configs k0sconfig.HelmExtensions - }{} + parsed := types.ReleaseMetadata{} if err := json.Unmarshal([]byte(output), &parsed); err != nil { t.Log(output) t.Fatalf("fail to parse metadata output: %v", err) } + expectedVersions := []string{"Kubernetes", "Troubleshoot", "Kubectl", "EmbeddedClusterOperator", "AdminConsole", "OpenEBS", "goldpinger", "ingress-nginx"} + for _, v := range expectedVersions { + if val, ok := parsed.Versions[v]; !ok || val == "" { + t.Errorf("missing %q version in 'metadata' output", v) + failed = true + } + } + for _, foundChart := range parsed.Configs.Charts { if strings.Contains(foundChart.Values, "embeddedClusterID") { t.Errorf("metadata output for chart %s contains embeddedClusterID", foundChart.Name) diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index 0490e28bc..e82e3386c 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -9,6 +9,11 @@ var ( // K0sVersion holds the version of k0s binary we are embedding. this is // set at compile time via ldflags. K0sVersion = "0.0.0" + // TroubleshootVersion holds the version of troubleshoot and preflight + // binaries we are embedding. this is set at compile time via ldflags. + TroubleshootVersion = "0.0.0" + // KubectlVersion holds the version of kubectl binary we are embedding. + KubectlVersion = "0.0.0" // provider holds a global reference to the default provider. provider *Provider // K0sBinaryURL holds an alternative URL from where to download the k0s