Skip to content

Commit

Permalink
include troubleshoot and kubectl binary versions in metadata (#432)
Browse files Browse the repository at this point in the history
* include troubleshoot and kubectl binary versions in metadata

* ensure versions show up

* remove expected breakage
  • Loading branch information
laverya authored Mar 6, 2024
1 parent f628aab commit 4078b04
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
13 changes: 13 additions & 0 deletions cmd/embedded-cluster/types/types.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 4 additions & 11 deletions cmd/embedded-cluster/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/replicatedhq/embedded-cluster/cmd/embedded-cluster/types"
"sort"
"strings"

Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions e2e/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions pkg/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4078b04

Please sign in to comment.