Skip to content

Commit da016fe

Browse files
authored
fix(k8s): fix k8s get json output (#1476)
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent 3b02803 commit da016fe

File tree

2 files changed

+104
-57
lines changed

2 files changed

+104
-57
lines changed

internal/namespaces/k8s/v1/custom_cluster.go

+51-55
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"net/http"
88
"reflect"
9-
"strings"
109
"time"
1110

1211
"github.com/fatih/color"
@@ -102,63 +101,60 @@ func clusterGetBuilder(c *core.Command) *core.Command {
102101
return res, err
103102
}
104103

105-
clusterMarshalled, err := human.Marshal(cluster, nil)
106-
if err != nil {
107-
return res, err
104+
type customPool struct {
105+
ID string
106+
Name string
107+
Status k8s.PoolStatus
108+
Version string
109+
NodeType string
110+
MinSize uint32
111+
Size uint32
112+
MaxSize uint32
113+
Autoscaling bool
114+
Autohealing bool
108115
}
109-
poolsMarshalled, err := human.Marshal(pools.Pools, &human.MarshalOpt{
110-
Title: "Pools",
111-
Fields: []*human.MarshalFieldOpt{
112-
{
113-
FieldName: "ID",
114-
Label: "ID",
115-
},
116-
{
117-
FieldName: "Name",
118-
Label: "Name",
119-
},
120-
{
121-
FieldName: "Status",
122-
Label: "Status",
123-
},
124-
{
125-
FieldName: "Version",
126-
Label: "Version",
127-
},
128-
{
129-
FieldName: "NodeType",
130-
Label: "Node Type",
131-
},
132-
{
133-
FieldName: "MinSize",
134-
Label: "Min Size",
135-
},
136-
{
137-
FieldName: "Size",
138-
Label: "Size",
139-
},
140-
{
141-
FieldName: "MaxSize",
142-
Label: "Max Size",
143-
},
144-
{
145-
FieldName: "Autoscaling",
146-
Label: "Autoscaling",
147-
},
148-
{
149-
FieldName: "Autohealing",
150-
Label: "Autohealing",
151-
},
152-
},
153-
})
154-
if err != nil {
155-
return res, err
116+
117+
customPools := []customPool{}
118+
119+
for _, pool := range pools.Pools {
120+
customPools = append(customPools, customPool{
121+
ID: pool.ID,
122+
Name: pool.Name,
123+
Status: pool.Status,
124+
Version: pool.Version,
125+
NodeType: pool.NodeType,
126+
MinSize: pool.MinSize,
127+
Size: pool.Size,
128+
MaxSize: pool.MaxSize,
129+
Autoscaling: pool.Autoscaling,
130+
Autohealing: pool.Autohealing,
131+
})
156132
}
157133

158-
return strings.Join([]string{
159-
clusterMarshalled,
160-
poolsMarshalled,
161-
}, "\n\n"), nil
134+
return struct {
135+
*k8s.Cluster
136+
Pools []customPool `json:"pools"`
137+
}{
138+
cluster,
139+
customPools,
140+
}, nil
141+
}
142+
143+
c.View = &core.View{
144+
Sections: []*core.ViewSection{
145+
{
146+
FieldName: "AutoscalerConfig",
147+
Title: "Autoscaler configuration",
148+
},
149+
{
150+
FieldName: "AutoUpgrade",
151+
Title: "Auto-upgrade settings",
152+
},
153+
{
154+
FieldName: "Pools",
155+
Title: "Pools",
156+
},
157+
},
162158
}
163159

164160
return c

internal/namespaces/k8s/v1/testdata/test-get-cluster-simple.golden

+53-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,58 @@ MaintenanceWindow.StartHour 0
3333
MaintenanceWindow.Day any
3434

3535
Pools:
36-
ID Name Status Version Node Type Min Size Size Max Size Autoscaling Autohealing
36+
ID NAME STATUS VERSION NODE TYPE MIN SIZE SIZE MAX SIZE AUTOSCALING AUTOHEALING
3737
c610deed-139b-4950-aff7-8e2ccd895507 default scaling 1.17.3 dev1_m 0 1 1 false false
3838
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
39-
"ID eaad7843-9a27-467f-b6d3-d45fc7f53580\nName cli-test\nStatus creating\nVersion 1.17.3\nRegion fr-par\nOrganizationID b8fdefc6-c926-4a47-af24-24f14f724d6a\nProjectID -\nCni cilium\nDescription -\nClusterURL https://eaad7843-9a27-467f-b6d3-d45fc7f53580.api.k8s.fr-par.scw.cloud:6443\nDNSWildcard *.eaad7843-9a27-467f-b6d3-d45fc7f53580.nodes.k8s.fr-par.scw.cloud\nCreatedAt few seconds ago\nUpdatedAt few seconds ago\nDashboardEnabled false\nIngress none\nUpgradeAvailable true\n\nAutoscaler configuration:\nScaleDownDisabled false\nScaleDownDelayAfterAdd 10m\nEstimator binpacking\nExpander random\nIgnoreDaemonsetsUtilization false\nBalanceSimilarNodeGroups false\nExpendablePodsPriorityCutoff -10\nScaleDownUnneededTime 10m\n\nAuto-upgrade settings:\nEnabled false\nMaintenanceWindow.StartHour 0\nMaintenanceWindow.Day any\n\nPools:\nID Name Status Version Node Type Min Size Size Max Size Autoscaling Autohealing\nc610deed-139b-4950-aff7-8e2ccd895507 default scaling 1.17.3 dev1_m 0 1 1 false false"
39+
{
40+
"id": "eaad7843-9a27-467f-b6d3-d45fc7f53580",
41+
"name": "cli-test",
42+
"status": "creating",
43+
"version": "1.17.3",
44+
"region": "fr-par",
45+
"organization_id": "b8fdefc6-c926-4a47-af24-24f14f724d6a",
46+
"project_id": "",
47+
"tags": [],
48+
"cni": "cilium",
49+
"description": "",
50+
"cluster_url": "https://eaad7843-9a27-467f-b6d3-d45fc7f53580.api.k8s.fr-par.scw.cloud:6443",
51+
"dns_wildcard": "*.eaad7843-9a27-467f-b6d3-d45fc7f53580.nodes.k8s.fr-par.scw.cloud",
52+
"created_at": "1970-01-01T00:00:00.0Z",
53+
"updated_at": "1970-01-01T00:00:00.0Z",
54+
"autoscaler_config": {
55+
"scale_down_disabled": false,
56+
"scale_down_delay_after_add": "10m",
57+
"estimator": "binpacking",
58+
"expander": "random",
59+
"ignore_daemonsets_utilization": false,
60+
"balance_similar_node_groups": false,
61+
"expendable_pods_priority_cutoff": -10,
62+
"scale_down_unneeded_time": "10m"
63+
},
64+
"dashboard_enabled": false,
65+
"ingress": "none",
66+
"auto_upgrade": {
67+
"enabled": false,
68+
"maintenance_window": {
69+
"start_hour": 0,
70+
"day": "any"
71+
}
72+
},
73+
"upgrade_available": true,
74+
"feature_gates": [],
75+
"admission_plugins": [],
76+
"pools": [
77+
{
78+
"ID": "c610deed-139b-4950-aff7-8e2ccd895507",
79+
"Name": "default",
80+
"Status": "scaling",
81+
"Version": "1.17.3",
82+
"NodeType": "dev1_m",
83+
"MinSize": 0,
84+
"Size": 1,
85+
"MaxSize": 1,
86+
"Autoscaling": false,
87+
"Autohealing": false
88+
}
89+
]
90+
}

0 commit comments

Comments
 (0)