From 0fbcb9d92034f39ac25158bab00cedef650fc498 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Fri, 20 Jun 2025 16:28:18 +0100 Subject: [PATCH] add the version command Signed-off-by: Rui Lopes --- .goreleaser.yaml | 4 ++++ kubectl-linstor.go | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 6c7d9c6..b087817 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -21,6 +21,10 @@ builds: - amd64 - arm64 - s390x + ldflags: + - -s + - -w + - -X main.version={{ .Version }} archives: - format: tar.gz diff --git a/kubectl-linstor.go b/kubectl-linstor.go index 33ec62e..8bbcb51 100644 --- a/kubectl-linstor.go +++ b/kubectl-linstor.go @@ -182,6 +182,14 @@ func getControllerPodNamespacedName(ctx context.Context) (string, string, error) return "", "", fmt.Errorf("could not find a managed LINSTOR Controller resource") } +func isVersion(args ...string) bool { + if len(args) != 1 { + return false + } + + return args[0] == "version" +} + func isSosReportDownload(args ...string) bool { if len(args) < 2 { return false @@ -308,7 +316,16 @@ func rawExec(ctx context.Context, kubectlArgs []string, args ...string) { os.Exit(cmd.ProcessState.ExitCode()) } +var version = "0.0.0" + func main() { + cmdArgs := os.Args[1:] + + if isVersion(cmdArgs...) { + fmt.Println(version) + return + } + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() @@ -324,7 +341,6 @@ func main() { } toExecArgs = append(toExecArgs, fmt.Sprintf("pod/%s", podName), "--") - cmdArgs := os.Args[1:] switch { case isSosReportDownload(cmdArgs...): doSosReportDownload(ctx, namespace, podName, toExecArgs, cmdArgs...)