Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the CLI version string to the default package #2362

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GOLANGCILINT_VERSION = $(shell golangci-lint version --format short 2>/dev/null)
$(TARGET):
$(GO_BUILD) $(if $(GO_TAGS),-tags $(GO_TAGS)) \
-ldflags "$(STRIP_DEBUG) \
-X 'github.com/cilium/cilium-cli/cli.Version=${VERSION}'" \
-X 'github.com/cilium/cilium-cli/defaults.CLIVersion=${VERSION}'" \
-o $(TARGET) \
./cmd/cilium

Expand Down
7 changes: 0 additions & 7 deletions cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ import (
"github.com/cilium/cilium-cli/sysdump"
)

// The following variables are set at compile time via LDFLAGS.
var (
// Version is the software version.
Version string
)

// NewDefaultCiliumCommand returns a new "cilium" cli cobra command without any additional hooks.
func NewDefaultCiliumCommand() *cobra.Command {
return NewCiliumCommand(&NopHooks{})
}

// NewCiliumCommand returns a new "cilium" cli cobra command registering all the additional input hooks.
func NewCiliumCommand(hooks Hooks) *cobra.Command {
cmd.SetVersion(Version)
return cmd.NewCiliumCommand(hooks)
}

Expand Down
5 changes: 5 additions & 0 deletions defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,9 @@ var (
"inbound_other", // XfrmInError
"inbound_state_invalid", // XfrmInStateInvalid
}

// The following variables are set at compile time via LDFLAGS.

// CLIVersion is the software version of the Cilium CLI.
CLIVersion string
)
8 changes: 0 additions & 8 deletions internal/cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ var (
namespace string

k8sClient *k8s.Client

// version is the version string of the cilium-cli itself
version string
)

// SetVersion sets the version string for the cilium command
func SetVersion(v string) {
version = v
}

func NewCiliumCommand(hooks Hooks) *cobra.Command {
cmd := &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func RunE(hooks Hooks) func(cmd *cobra.Command, args []string) error {
}

// Instantiate the test harness.
cc, err := check.NewConnectivityTest(k8sClient, params, version)
cc, err := check.NewConnectivityTest(k8sClient, params, defaults.CLIVersion)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func newCmdUninstallWithHelm() *cobra.Command {
TestNamespace: params.TestNamespace,
FlowValidation: check.FlowValidationModeDisabled,
Writer: os.Stdout,
}, version)
}, defaults.CLIVersion)
if err != nil {
fmt.Printf("⚠ ️ Failed to initialize connectivity test uninstaller: %s\n", err)
} else {
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/cmd/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/klog/v2"

"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/sysdump"
)

Expand All @@ -36,7 +37,7 @@ func newCmdSysdump(hooks sysdump.Hooks) *cobra.Command {
// Silence klog to avoid displaying "throttling" messages - those are expected.
klog.SetOutput(io.Discard)
// Collect the sysdump.
collector, err := sysdump.NewCollector(k8sClient, sysdumpOptions, time.Now(), version)
collector, err := sysdump.NewCollector(k8sClient, sysdumpOptions, time.Now(), defaults.CLIVersion)
if err != nil {
return fmt.Errorf("failed to create sysdump collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newCmdVersion() *cobra.Command {
Short: "Display detailed version information",
Long: `Displays information about the version of this software.`,
RunE: func(_ *cobra.Command, _ []string) error {
fmt.Printf("cilium-cli: %s compiled with %v on %v/%v\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("cilium-cli: %s compiled with %v on %v/%v\n", defaults.CLIVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("cilium image (default): %s\n", defaults.Version)
fmt.Printf("cilium image (stable): %s\n", getLatestStableVersion())
if clientOnly {
Expand Down
Loading