Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(k8s): add support for showing pools in get cluster #1311

Merged
merged 2 commits into from
Jul 31, 2020
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
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