Skip to content

Commit

Permalink
add 'version' command for operator
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Oct 16, 2024
1 parent a618aad commit c07fc52
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
19 changes: 0 additions & 19 deletions cmd/embedded-cluster/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/replicatedhq/embedded-cluster/pkg/defaults"
"github.com/replicatedhq/embedded-cluster/pkg/goods"
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
Expand Down Expand Up @@ -560,24 +559,6 @@ func installAndWaitForK0s(c *cli.Context, provider *defaults.Provider, applier *
return nil, err
}

kcli, err := kubeutils.KubeClient()
if err != nil {
err = fmt.Errorf("unable to get kube client: %w", err)
metrics.ReportApplyFinished(c, err)
return nil, err
}
hostname, err := os.Hostname()
if err != nil {
err = fmt.Errorf("unable to get hostname: %w", err)
metrics.ReportApplyFinished(c, err)
return nil, err
}
if err := waitForNode(c.Context, kcli, hostname); err != nil {
err = fmt.Errorf("unable to wait for node: %w", err)
metrics.ReportApplyFinished(c, err)
return nil, err
}

loading.Infof("Node installation finished!")
return cfg, nil
}
Expand Down
1 change: 1 addition & 0 deletions operator/pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ func addSubcommands(cmd *cobra.Command) {
MigrateCmd(),
UpgradeCmd(),
UpgradeJobCmd(),
VersionCmd(),
)
}
53 changes: 53 additions & 0 deletions operator/pkg/cli/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cli

import (
"fmt"
"sort"
"strings"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/replicatedhq/embedded-cluster/pkg/addons"
"github.com/replicatedhq/embedded-cluster/pkg/config"
"github.com/replicatedhq/embedded-cluster/pkg/versions"
"github.com/spf13/cobra"
)

// VersionCmd returns a cobra command for listing versions of embedded cluster components
func VersionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
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 cmd
}

0 comments on commit c07fc52

Please sign in to comment.