From 6577f6afb8503687d32a40d0bfaba887cd40de02 Mon Sep 17 00:00:00 2001 From: Roman Berezkin Date: Wed, 15 Jul 2026 17:30:59 +0300 Subject: [PATCH 1/4] Add CLI version section to status report Print the running d8 CLI version at the top of `d8 status`. Signed-off-by: Roman Berezkin --- internal/status/cmd/status.go | 2 + .../status/objects/cliversion/cliversion.go | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 internal/status/objects/cliversion/cliversion.go diff --git a/internal/status/cmd/status.go b/internal/status/cmd/status.go index 2813ea1f..958b870b 100644 --- a/internal/status/cmd/status.go +++ b/internal/status/cmd/status.go @@ -27,6 +27,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/kubectl/pkg/util/templates" + "github.com/deckhouse/deckhouse-cli/internal/status/objects/cliversion" "github.com/deckhouse/deckhouse-cli/internal/status/objects/clusteralerts" cnimodules "github.com/deckhouse/deckhouse-cli/internal/status/objects/cni_modules" deckhouseedition "github.com/deckhouse/deckhouse-cli/internal/status/objects/edition" @@ -89,6 +90,7 @@ func executeAll(ctx context.Context, restConfig *rest.Config, kubeCl kubernetes. } return []statusresult.StatusResult{ + cliversion.Status(), masters.Status(ctx, kubeCl), deckhousepods.Status(ctx, kubeCl), deckhousereleases.Status(ctx, dynamicClient), diff --git a/internal/status/objects/cliversion/cliversion.go b/internal/status/objects/cliversion/cliversion.go new file mode 100644 index 00000000..28e1e9b5 --- /dev/null +++ b/internal/status/objects/cliversion/cliversion.go @@ -0,0 +1,48 @@ +/* +Copyright 2025 Flant JSC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cliversion + +import ( + "fmt" + "strings" + + "github.com/fatih/color" + + "github.com/deckhouse/deckhouse-cli/internal/status/tools/statusresult" + "github.com/deckhouse/deckhouse-cli/internal/version" +) + +// Status reports the version of the running d8 CLI binary. +// This is a property of the local binary, so no cluster access is needed. +func Status() statusresult.StatusResult { + return statusresult.StatusResult{ + Title: "Deckhouse CLI Version", + Level: 0, + Output: formatCLIVersion(version.Version), + } +} + +// Format returns a readable view of the CLI version for CLI display. +func formatCLIVersion(v string) string { + yellow := color.New(color.FgYellow).SprintFunc() + + var sb strings.Builder + sb.WriteString(yellow("┌ Deckhouse CLI Version:\n")) + fmt.Fprintf(&sb, "%s %s\n", yellow("└"), v) + + return sb.String() +} From 87d02108bb96dec7863c554e62fd87de174503d4 Mon Sep 17 00:00:00 2001 From: Roman Berezkin Date: Wed, 15 Jul 2026 18:39:20 +0300 Subject: [PATCH 2/4] Add test for CLI version status section Signed-off-by: Roman Berezkin --- .../objects/cliversion/cliversion_test.go | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 internal/status/objects/cliversion/cliversion_test.go diff --git a/internal/status/objects/cliversion/cliversion_test.go b/internal/status/objects/cliversion/cliversion_test.go new file mode 100644 index 00000000..ae5b1e43 --- /dev/null +++ b/internal/status/objects/cliversion/cliversion_test.go @@ -0,0 +1,50 @@ +/* +Copyright 2026 Flant JSC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cliversion + +import ( + "strings" + "testing" + + "github.com/deckhouse/deckhouse-cli/internal/version" +) + +func TestFormatCLIVersion(t *testing.T) { + output := formatCLIVersion("v0.32.0") + + for _, want := range []string{"┌ Deckhouse CLI Version:", "└ v0.32.0"} { + if !strings.Contains(output, want) { + t.Errorf("formatCLIVersion output missing %q:\n%s", want, output) + } + } +} + +func TestStatusReportsInjectedVersion(t *testing.T) { + orig := version.Version + t.Cleanup(func() { version.Version = orig }) + + version.Version = "v9.9.9-test" + result := Status() + + if result.Title != "Deckhouse CLI Version" { + t.Errorf("Title = %q, want %q", result.Title, "Deckhouse CLI Version") + } + + if !strings.Contains(result.Output, "v9.9.9-test") { + t.Errorf("output missing injected version:\n%s", result.Output) + } +} From 0a77998fa582b2c91a1a9180925256475191a79c Mon Sep 17 00:00:00 2001 From: Roman Berezkin Date: Thu, 16 Jul 2026 03:51:05 +0300 Subject: [PATCH 3/4] Fix copyright year Signed-off-by: Roman Berezkin --- internal/status/objects/cliversion/cliversion.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/status/objects/cliversion/cliversion.go b/internal/status/objects/cliversion/cliversion.go index 28e1e9b5..a79e0100 100644 --- a/internal/status/objects/cliversion/cliversion.go +++ b/internal/status/objects/cliversion/cliversion.go @@ -1,5 +1,5 @@ /* -Copyright 2025 Flant JSC +Copyright 2026 Flant JSC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From dd2aa6ed2d1de36a399732cba36540c904738293 Mon Sep 17 00:00:00 2001 From: Roman Berezkin Date: Mon, 20 Jul 2026 10:54:40 +0300 Subject: [PATCH 4/4] Show CLI version as a byline above the status report - `cliBanner` prints a faint "Generated by Deckhouse CLI " line right above the report header. - The version describes the local binary, not cluster state, so it sits outside the status sections as report metadata. - `TestCLIBanner` checks the byline contains the label and the version. Signed-off-by: Roman Berezkin --- internal/status/cmd/status.go | 14 ++++-- internal/status/cmd/status_test.go | 32 ++++++++++++ .../status/objects/cliversion/cliversion.go | 48 ------------------ .../objects/cliversion/cliversion_test.go | 50 ------------------- 4 files changed, 43 insertions(+), 101 deletions(-) create mode 100644 internal/status/cmd/status_test.go delete mode 100644 internal/status/objects/cliversion/cliversion.go delete mode 100644 internal/status/objects/cliversion/cliversion_test.go diff --git a/internal/status/cmd/status.go b/internal/status/cmd/status.go index 958b870b..4362067a 100644 --- a/internal/status/cmd/status.go +++ b/internal/status/cmd/status.go @@ -27,7 +27,6 @@ import ( "k8s.io/client-go/rest" "k8s.io/kubectl/pkg/util/templates" - "github.com/deckhouse/deckhouse-cli/internal/status/objects/cliversion" "github.com/deckhouse/deckhouse-cli/internal/status/objects/clusteralerts" cnimodules "github.com/deckhouse/deckhouse-cli/internal/status/objects/cni_modules" deckhouseedition "github.com/deckhouse/deckhouse-cli/internal/status/objects/edition" @@ -39,6 +38,7 @@ import ( deckhousesettings "github.com/deckhouse/deckhouse-cli/internal/status/objects/settings" "github.com/deckhouse/deckhouse-cli/internal/status/tools/statusresult" "github.com/deckhouse/deckhouse-cli/internal/utilk8s" + "github.com/deckhouse/deckhouse-cli/internal/version" ) var statusLong = templates.LongDesc(` @@ -69,7 +69,9 @@ func runStatus(cmd *cobra.Command, _ []string) error { return fmt.Errorf("failed to setup Kubernetes client: %w", err) } - color.Cyan("\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓") + fmt.Println() + fmt.Println(cliBanner(version.Version)) + color.Cyan("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓") color.Cyan("┃ Cluster Status Report ┃") color.Cyan("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n") @@ -81,6 +83,13 @@ func runStatus(cmd *cobra.Command, _ []string) error { return nil } +// cliBanner returns the byline shown above the report header, +// marking which d8 CLI version generated the report. +func cliBanner(v string) string { + faint := color.New(color.Faint).SprintFunc() + return fmt.Sprintf("%s %s", faint("Generated by Deckhouse CLI"), v) +} + func executeAll(ctx context.Context, restConfig *rest.Config, kubeCl kubernetes.Interface) []statusresult.StatusResult { dynamicClient, err := dynamic.NewForConfig(restConfig) if err != nil { @@ -90,7 +99,6 @@ func executeAll(ctx context.Context, restConfig *rest.Config, kubeCl kubernetes. } return []statusresult.StatusResult{ - cliversion.Status(), masters.Status(ctx, kubeCl), deckhousepods.Status(ctx, kubeCl), deckhousereleases.Status(ctx, dynamicClient), diff --git a/internal/status/cmd/status_test.go b/internal/status/cmd/status_test.go new file mode 100644 index 00000000..0afccca4 --- /dev/null +++ b/internal/status/cmd/status_test.go @@ -0,0 +1,32 @@ +/* +Copyright 2026 Flant JSC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package status + +import ( + "strings" + "testing" +) + +func TestCLIBanner(t *testing.T) { + output := cliBanner("v9.9.9-test") + + for _, want := range []string{"Generated by Deckhouse CLI", "v9.9.9-test"} { + if !strings.Contains(output, want) { + t.Errorf("cliBanner output missing %q:\n%s", want, output) + } + } +} diff --git a/internal/status/objects/cliversion/cliversion.go b/internal/status/objects/cliversion/cliversion.go deleted file mode 100644 index a79e0100..00000000 --- a/internal/status/objects/cliversion/cliversion.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2026 Flant JSC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cliversion - -import ( - "fmt" - "strings" - - "github.com/fatih/color" - - "github.com/deckhouse/deckhouse-cli/internal/status/tools/statusresult" - "github.com/deckhouse/deckhouse-cli/internal/version" -) - -// Status reports the version of the running d8 CLI binary. -// This is a property of the local binary, so no cluster access is needed. -func Status() statusresult.StatusResult { - return statusresult.StatusResult{ - Title: "Deckhouse CLI Version", - Level: 0, - Output: formatCLIVersion(version.Version), - } -} - -// Format returns a readable view of the CLI version for CLI display. -func formatCLIVersion(v string) string { - yellow := color.New(color.FgYellow).SprintFunc() - - var sb strings.Builder - sb.WriteString(yellow("┌ Deckhouse CLI Version:\n")) - fmt.Fprintf(&sb, "%s %s\n", yellow("└"), v) - - return sb.String() -} diff --git a/internal/status/objects/cliversion/cliversion_test.go b/internal/status/objects/cliversion/cliversion_test.go deleted file mode 100644 index ae5b1e43..00000000 --- a/internal/status/objects/cliversion/cliversion_test.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2026 Flant JSC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cliversion - -import ( - "strings" - "testing" - - "github.com/deckhouse/deckhouse-cli/internal/version" -) - -func TestFormatCLIVersion(t *testing.T) { - output := formatCLIVersion("v0.32.0") - - for _, want := range []string{"┌ Deckhouse CLI Version:", "└ v0.32.0"} { - if !strings.Contains(output, want) { - t.Errorf("formatCLIVersion output missing %q:\n%s", want, output) - } - } -} - -func TestStatusReportsInjectedVersion(t *testing.T) { - orig := version.Version - t.Cleanup(func() { version.Version = orig }) - - version.Version = "v9.9.9-test" - result := Status() - - if result.Title != "Deckhouse CLI Version" { - t.Errorf("Title = %q, want %q", result.Title, "Deckhouse CLI Version") - } - - if !strings.Contains(result.Output, "v9.9.9-test") { - t.Errorf("output missing injected version:\n%s", result.Output) - } -}