Skip to content
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
19 changes: 19 additions & 0 deletions internal/cmd/ske/cluster/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/goccy/go-yaml"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -131,11 +132,15 @@ func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) e
if cluster.HasStatus() {
table.AddRow("STATE", utils.PtrString(cluster.Status.Aggregated))
table.AddSeparator()
if clusterErrs := cluster.Status.GetErrors(); len(clusterErrs) != 0 {
handleClusterErrors(clusterErrs, &table)
}
}
if cluster.Kubernetes != nil {
table.AddRow("VERSION", utils.PtrString(cluster.Kubernetes.Version))
table.AddSeparator()
}

table.AddRow("ACL", acl)
err := table.Display(p)
if err != nil {
Expand All @@ -145,3 +150,17 @@ func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) e
return nil
}
}

func handleClusterErrors(clusterErrs []ske.ClusterError, table *tables.Table) {
errs := make([]string, 0, len(clusterErrs))
for _, e := range clusterErrs {
b := new(strings.Builder)
fmt.Fprint(b, e.GetCode())
if msg, ok := e.GetMessageOk(); ok {
fmt.Fprintf(b, ": %s", msg)
}
errs = append(errs, b.String())
}
table.AddRow("ERRORS", strings.Join(errs, "\n"))
table.AddSeparator()
}
179 changes: 179 additions & 0 deletions internal/cmd/ske/cluster/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -234,6 +235,184 @@ func TestOutputResult(t *testing.T) {
},
wantErr: false,
},
{
name: "cluster with single error",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{
{
Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"),
Message: utils.Ptr("Network configuration not found"),
},
},
},
},
},
wantErr: false,
},
{
name: "cluster with multiple errors",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{
{
Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"),
Message: utils.Ptr("Network configuration not found"),
},
{
Code: utils.Ptr("SKE_NODE_MACHINE_TYPE_NOT_FOUND"),
Message: utils.Ptr("Specified machine type unavailable"),
},
{
Code: utils.Ptr("SKE_FETCHING_ERRORS_NOT_POSSIBLE"),
Message: utils.Ptr("Fetching errors not possible"),
},
},
},
},
},
wantErr: false,
},
{
name: "cluster with error but no message",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{
{
Code: utils.Ptr("SKE_FETCHING_ERRORS_NOT_POSSIBLE"),
},
},
},
},
},
wantErr: false,
},
{
name: "cluster with nil errors",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Status: &ske.ClusterStatus{
Errors: nil,
},
},
},
wantErr: false,
},
{
name: "cluster with empty errors array",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{},
},
},
},
wantErr: false,
},
{
name: "cluster without status",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
},
},
wantErr: false,
},
{
name: "JSON output format with errors",
args: args{
outputFormat: print.JSONOutputFormat,
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{
{
Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"),
Message: utils.Ptr("Network configuration not found"),
},
},
},
},
},
wantErr: false,
},
{
name: "YAML output format with errors",
args: args{
outputFormat: print.YAMLOutputFormat,
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{
{
Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"),
Message: utils.Ptr("Network configuration not found"),
},
},
},
},
},
wantErr: false,
},
{
name: "cluster with kubernetes info and errors",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Kubernetes: &ske.Kubernetes{
Version: utils.Ptr("1.28.0"),
},
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{
{
Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"),
Message: utils.Ptr("Network configuration not found"),
},
},
},
},
},
wantErr: false,
},
{
name: "cluster with extensions and errors",
args: args{
outputFormat: "",
cluster: &ske.Cluster{
Name: utils.Ptr("test-cluster"),
Extensions: &ske.Extension{
Acl: &ske.ACL{
AllowedCidrs: &[]string{"10.0.0.0/8"},
Enabled: utils.Ptr(true),
},
},
Status: &ske.ClusterStatus{
Errors: &[]ske.ClusterError{
{
Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"),
Message: utils.Ptr("Network configuration not found"),
},
},
},
},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(&params.CmdParams{Printer: p})
Expand Down
Loading