Skip to content

Commit

Permalink
Merge pull request #5164 from whitewindmills/update-cluster-printcolumns
Browse files Browse the repository at this point in the history
Add more columns for cluster
  • Loading branch information
karmada-bot committed Jul 10, 2024
2 parents 15df251 + c3b854d commit ae45a5a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
31 changes: 29 additions & 2 deletions pkg/printers/internalversion/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package internalversion

import (
"strings"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -35,7 +36,11 @@ func AddHandlers(h printers.PrintHandler) {
{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: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
{Name: "APIEndpoint", Type: "string", Priority: 1, Description: "The API endpoint of the member cluster."},
{Name: "Zones", Type: "string", Priority: 1, Description: "Zones represents the failure zones(also called availability zones) of the member cluster. The zones are presented as a slice to support the case that cluster runs across multiple failure zones."},
{Name: "Region", Type: "string", Priority: 1, Description: "Region represents the region of the member cluster locate in."},
{Name: "Provider", Type: "string", Priority: 1, Description: "Provider represents the cloud provider name of the member cluster."},
{Name: "API-Endpoint", Type: "string", Priority: 1, Description: "The API endpoint of the member cluster."},
{Name: "Proxy-URL", Type: "string", Priority: 1, Description: "ProxyURL is the proxy URL for the cluster."},
}
// ignore errors because we enable errcheck golangci-lint.
_ = h.TableHandler(clusterColumnDefinitions, printClusterList)
Expand Down Expand Up @@ -74,7 +79,13 @@ func printCluster(cluster *clusterapis.Cluster, options printers.GenerateOptions
ready,
translateTimestampSince(cluster.CreationTimestamp))
if options.Wide {
row.Cells = append(row.Cells, cluster.Spec.APIEndpoint)
row.Cells = append(
row.Cells,
translateZones(cluster.Spec.Zones),
translateOptionalStringField(cluster.Spec.Region),
translateOptionalStringField(cluster.Spec.Provider),
cluster.Spec.APIEndpoint,
translateOptionalStringField(cluster.Spec.ProxyURL))
}
return []metav1.TableRow{row}, nil
}
Expand All @@ -88,3 +99,19 @@ func translateTimestampSince(timestamp metav1.Time) string {

return duration.HumanDuration(time.Since(timestamp.Time))
}

func translateOptionalStringField(field string) string {
if len(field) == 0 {
return "<none>"
}

return field
}

func translateZones(zones []string) string {
if len(zones) == 0 {
return "<none>"
}

return strings.Join(zones, ",")
}
9 changes: 8 additions & 1 deletion pkg/printers/internalversion/printers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func TestPrintCluster(t *testing.T) {
Spec: clusterapis.ClusterSpec{
SyncMode: clusterapis.Push,
APIEndpoint: "https://kubernetes.default.svc.cluster.local:6443",
ProxyURL: "https://anp-server.default.svc.cluster.local:443",
Zones: []string{"foo", "bar"},
},
Status: clusterapis.ClusterStatus{
KubernetesVersion: "1.24.2",
Expand All @@ -65,7 +67,12 @@ func TestPrintCluster(t *testing.T) {
},
},
printers.GenerateOptions{Wide: true},
[]metav1.TableRow{{Cells: []interface{}{"test2", "1.24.2", clusterapis.ClusterSyncMode("Push"), "True", "<unknown>", "https://kubernetes.default.svc.cluster.local:6443"}}},
[]metav1.TableRow{{Cells: []interface{}{"test2", "1.24.2", clusterapis.ClusterSyncMode("Push"), "True", "<unknown>",
"foo,bar",
"<none>",
"<none>",
"https://kubernetes.default.svc.cluster.local:6443",
"https://anp-server.default.svc.cluster.local:443"}}},
},
}

Expand Down

0 comments on commit ae45a5a

Please sign in to comment.