Skip to content

Commit

Permalink
fix(k8s): better rendering of list-available-types for cluster resour…
Browse files Browse the repository at this point in the history
…ce (#3599)
  • Loading branch information
jremy42 authored Jan 22, 2024
1 parent 40964fe commit 4d5f7f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/namespaces/k8s/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func GetCommands() *core.Commands {
human.RegisterMarshalerFunc(k8s.ClusterStatus(""), human.EnumMarshalFunc(clusterStatusMarshalSpecs))
human.RegisterMarshalerFunc(k8s.PoolStatus(""), human.EnumMarshalFunc(poolStatusMarshalSpecs))
human.RegisterMarshalerFunc(k8s.NodeStatus(""), human.EnumMarshalFunc(nodeStatusMarshalSpecs))
human.RegisterMarshalerFunc(k8s.ListClusterAvailableTypesResponse{}, clusterAvailableTypesListMarshalerFunc)

cmds.MustFind("k8s", "cluster", "list-available-versions").Override(clusterAvailableVersionsListBuilder)
cmds.MustFind("k8s", "cluster", "create").Override(clusterCreateBuilder)
Expand All @@ -37,7 +38,6 @@ func GetCommands() *core.Commands {
cmds.MustFind("k8s", "cluster", "upgrade").Override(clusterUpgradeBuilder)
cmds.MustFind("k8s", "cluster", "delete").Override(clusterDeleteBuilder)
cmds.MustFind("k8s", "cluster", "migrate-to-private-network").Override(clusterMigrateToPrivateNetworkBuilder)

cmds.MustFind("k8s", "pool", "create").Override(poolCreateBuilder)
cmds.MustFind("k8s", "pool", "update").Override(poolUpdateBuilder)
cmds.MustFind("k8s", "pool", "upgrade").Override(poolUpgradeBuilder)
Expand Down
24 changes: 22 additions & 2 deletions internal/namespaces/k8s/v1/custom_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const (
)

func clusterMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
type tmp k8s.Cluster
cluster := tmp(i.(k8s.Cluster))
type humanCluster k8s.Cluster
cluster := humanCluster(i.(k8s.Cluster))

// Sections
opt.Sections = []*human.MarshalSection{
Expand All @@ -71,6 +71,26 @@ func clusterMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error)
return str, nil
}

func clusterAvailableTypesListMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
type humanResponse k8s.ListClusterAvailableTypesResponse
types := humanResponse(i.(k8s.ListClusterAvailableTypesResponse))

// Sections
opt.Sections = []*human.MarshalSection{
{
FieldName: "ClusterTypes",
Title: "Cluster Types",
},
}

str, err := human.Marshal(types, opt)
if err != nil {
return "", err
}

return str, nil
}

func clusterAvailableVersionsListBuilder(c *core.Command) *core.Command {
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
originalRes, err := runner(ctx, argsI)
Expand Down

0 comments on commit 4d5f7f9

Please sign in to comment.