Add more columns for cluster
Signed-off-by: whitewindmills <jayfantasyhjh@gmail.com>
This commit is contained in:
parent
625d8a5b77
commit
c3b854de62
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package internalversion
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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, ",")
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
@ -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"}}},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue