Skip to content

Commit

Permalink
feat(k8s): add support for showing pools in get cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed Jul 30, 2020
1 parent 2d4a8a2 commit a4a7117
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 232 deletions.
1 change: 1 addition & 0 deletions internal/namespaces/k8s/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func GetCommands() *core.Commands {

cmds.MustFind("k8s", "cluster", "list-available-versions").Override(clusterAvailableVersionsListBuilder)
cmds.MustFind("k8s", "cluster", "create").Override(clusterCreateBuilder)
cmds.MustFind("k8s", "cluster", "get").Override(clusterGetBuilder)
cmds.MustFind("k8s", "cluster", "update").Override(clusterUpdateBuilder)
cmds.MustFind("k8s", "cluster", "upgrade").Override(clusterUpgradeBuilder)
cmds.MustFind("k8s", "cluster", "delete").Override(clusterDeleteBuilder)
Expand Down
80 changes: 80 additions & 0 deletions internal/namespaces/k8s/v1/custom_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"reflect"
"strings"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -84,6 +85,85 @@ func clusterCreateBuilder(c *core.Command) *core.Command {
return c
}

func clusterGetBuilder(c *core.Command) *core.Command {
c.Interceptor = func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
res, err := runner(ctx, argsI)
if err != nil {
return nil, err
}
cluster := res.(*k8s.Cluster)

args := argsI.(*k8s.GetClusterRequest)
pools, err := k8s.NewAPI(core.ExtractClient(ctx)).ListPools(&k8s.ListPoolsRequest{
Region: args.Region,
ClusterID: args.ClusterID,
})
if err != nil {
return res, err
}

clusterMarshalled, err := human.Marshal(cluster, nil)
if err != nil {
return res, err
}
poolsMarshalled, err := human.Marshal(pools.Pools, &human.MarshalOpt{
Title: "Pools",
Fields: []*human.MarshalFieldOpt{
{
FieldName: "ID",
Label: "ID",
},
{
FieldName: "Name",
Label: "Name",
},
{
FieldName: "Status",
Label: "Status",
},
{
FieldName: "Version",
Label: "Version",
},
{
FieldName: "NodeType",
Label: "Node Type",
},
{
FieldName: "MinSize",
Label: "Min Size",
},
{
FieldName: "Size",
Label: "Size",
},
{
FieldName: "MaxSize",
Label: "Max Size",
},
{
FieldName: "Autoscaling",
Label: "Autoscaling",
},
{
FieldName: "Autohealing",
Label: "Autohealing",
},
},
})
if err != nil {
return res, err
}

return strings.Join([]string{
clusterMarshalled,
poolsMarshalled,
}, "\n\n"), nil
}

return c
}

func clusterDeleteBuilder(c *core.Command) *core.Command {
c.WaitFunc = waitForClusterFunc(clusterActionDelete)
return c
Expand Down
Loading

0 comments on commit a4a7117

Please sign in to comment.