Skip to content

Commit

Permalink
print compiled versions at operator startup
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Oct 16, 2024
1 parent c07fc52 commit a6233ad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
6 changes: 6 additions & 0 deletions operator/pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func RootCmd() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
err := printVersions()
if err != nil {
setupLog.Error(err, "unable to print versions")
os.Exit(1)
}

zaplog := zap.New(zap.UseDevMode(true))
ctrl.SetLogger(zaplog)

Expand Down
58 changes: 31 additions & 27 deletions operator/pkg/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,39 @@ func VersionCmd() *cobra.Command {
Short: "list versions",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
applierVersions, err := addons.NewApplier(
addons.WithoutPrompt(),
addons.OnlyDefaults(),
addons.Quiet(),
).Versions(config.AdditionalCharts())
if err != nil {
return fmt.Errorf("unable to get versions: %w", err)
}
writer := table.NewWriter()
writer.AppendHeader(table.Row{"component", "version"})
writer.AppendRow(table.Row{"Installer", versions.Version})
writer.AppendRow(table.Row{"Kubernetes", versions.K0sVersion})

keys := []string{}
for k := range applierVersions {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
version := applierVersions[k]
if !strings.HasPrefix(version, "v") {
version = fmt.Sprintf("v%s", version)
}
writer.AppendRow(table.Row{k, version})
}
fmt.Printf("%s\n", writer.Render())
return nil
return printVersions()
},
}

return cmd
}

func printVersions() error {
applierVersions, err := addons.NewApplier(
addons.WithoutPrompt(),
addons.OnlyDefaults(),
addons.Quiet(),
).Versions(config.AdditionalCharts())
if err != nil {
return fmt.Errorf("unable to get versions: %w", err)
}
writer := table.NewWriter()
writer.AppendHeader(table.Row{"component", "version"})
writer.AppendRow(table.Row{"Installer", versions.Version})
writer.AppendRow(table.Row{"Kubernetes", versions.K0sVersion})

keys := []string{}
for k := range applierVersions {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
version := applierVersions[k]
if !strings.HasPrefix(version, "v") {
version = fmt.Sprintf("v%s", version)
}
writer.AppendRow(table.Row{k, version})
}
fmt.Printf("%s\n", writer.Render())
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func Render() {
helmValues["kotsVersion"] = adminconsole.Metadata.Version
helmValues["embeddedClusterVersion"] = versions.Version
helmValues["embeddedClusterK0sVersion"] = versions.K0sVersion
Metadata.Version = versions.Version
}

// EmbeddedClusterOperator manages the installation of the embedded cluster operator
Expand Down

0 comments on commit a6233ad

Please sign in to comment.