Merge pull request #1672 from duanmengkk/master
improved the output of 'kubectl get cluster -o wide'
This commit is contained in:
commit
d4234428df
|
@ -19,6 +19,7 @@ func AddHandlers(h printers.PrintHandler) {
|
||||||
{Name: "Mode", Type: "string", Description: "SyncMode describes how a cluster sync resources from karmada control plane."},
|
{Name: "Mode", Type: "string", Description: "SyncMode describes how a cluster sync resources from karmada control plane."},
|
||||||
{Name: "Ready", Type: "string", Description: "The aggregate readiness state of this cluster for accepting workloads."},
|
{Name: "Ready", Type: "string", Description: "The aggregate readiness state of this cluster for accepting workloads."},
|
||||||
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||||
|
{Name: "APIEndpoint", Type: "string", Priority: 1, Description: "The API endpoint of the member cluster."},
|
||||||
}
|
}
|
||||||
// ignore errors because we enable errcheck golangci-lint.
|
// ignore errors because we enable errcheck golangci-lint.
|
||||||
_ = h.TableHandler(clusterColumnDefinitions, printClusterList)
|
_ = h.TableHandler(clusterColumnDefinitions, printClusterList)
|
||||||
|
@ -56,6 +57,9 @@ func printCluster(cluster *clusterapis.Cluster, options printers.GenerateOptions
|
||||||
cluster.Spec.SyncMode,
|
cluster.Spec.SyncMode,
|
||||||
ready,
|
ready,
|
||||||
translateTimestampSince(cluster.CreationTimestamp))
|
translateTimestampSince(cluster.CreationTimestamp))
|
||||||
|
if options.Wide {
|
||||||
|
row.Cells = append(row.Cells, cluster.Spec.APIEndpoint)
|
||||||
|
}
|
||||||
return []metav1.TableRow{row}, nil
|
return []metav1.TableRow{row}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,9 @@ import (
|
||||||
|
|
||||||
func TestPrintCluster(t *testing.T) {
|
func TestPrintCluster(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
cluster clusterapis.Cluster
|
cluster clusterapis.Cluster
|
||||||
expect []metav1.TableRow
|
generateOptions printers.GenerateOptions
|
||||||
|
expect []metav1.TableRow
|
||||||
}{
|
}{
|
||||||
// Test name, kubernetes version, sync mode, cluster ready status,
|
// Test name, kubernetes version, sync mode, cluster ready status,
|
||||||
{
|
{
|
||||||
|
@ -30,12 +31,30 @@ func TestPrintCluster(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
printers.GenerateOptions{Wide: false},
|
||||||
[]metav1.TableRow{{Cells: []interface{}{"test1", "1.21.7", clusterapis.ClusterSyncMode("Push"), "True", "<unknown>"}}},
|
[]metav1.TableRow{{Cells: []interface{}{"test1", "1.21.7", clusterapis.ClusterSyncMode("Push"), "True", "<unknown>"}}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
clusterapis.Cluster{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "test2"},
|
||||||
|
Spec: clusterapis.ClusterSpec{
|
||||||
|
SyncMode: clusterapis.Push,
|
||||||
|
APIEndpoint: "https://kubernetes.default.svc.cluster.local:6443",
|
||||||
|
},
|
||||||
|
Status: clusterapis.ClusterStatus{
|
||||||
|
KubernetesVersion: "1.21.7",
|
||||||
|
Conditions: []metav1.Condition{
|
||||||
|
{Type: clusterapis.ClusterConditionReady, Status: metav1.ConditionTrue},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
printers.GenerateOptions{Wide: true},
|
||||||
|
[]metav1.TableRow{{Cells: []interface{}{"test2", "1.21.7", clusterapis.ClusterSyncMode("Push"), "True", "<unknown>", "https://kubernetes.default.svc.cluster.local:6443"}}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
rows, err := printCluster(&test.cluster, printers.GenerateOptions{})
|
rows, err := printCluster(&test.cluster, test.generateOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue