github.com/oam-dev/cluster-gateway@v1.9.0/pkg/apis/cluster/v1alpha1/printer.go (about) 1 package v1alpha1 2 3 import ( 4 "strconv" 5 6 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 7 "k8s.io/apimachinery/pkg/runtime" 8 ) 9 10 var ( 11 definitions = []metav1.TableColumnDefinition{ 12 {Name: "Name", Type: "string", Format: "name", Description: "the name of the cluster"}, 13 {Name: "Provider", Type: "string", Description: "the cluster provider type"}, 14 {Name: "Credential-Type", Type: "string", Description: "the credential type"}, 15 {Name: "Endpoint-Type", Type: "string", Description: "the endpoint type"}, 16 {Name: "Healthy", Type: "string", Description: "the healthiness of the gateway"}, 17 } 18 ) 19 20 func printClusterGateway(in *ClusterGateway) *metav1.Table { 21 return &metav1.Table{ 22 ColumnDefinitions: definitions, 23 Rows: []metav1.TableRow{printClusterGatewayRow(in)}, 24 } 25 } 26 27 func printClusterGatewayList(in *ClusterGatewayList) *metav1.Table { 28 t := &metav1.Table{ 29 ColumnDefinitions: definitions, 30 } 31 for _, c := range in.Items { 32 t.Rows = append(t.Rows, printClusterGatewayRow(&c)) 33 } 34 return t 35 } 36 37 func printClusterGatewayRow(c *ClusterGateway) metav1.TableRow { 38 name := c.Name 39 provideType := c.Spec.Provider 40 credType := "<none>" 41 if c.Spec.Access.Credential != nil { 42 credType = string(c.Spec.Access.Credential.Type) 43 } 44 epType := string(c.Spec.Access.Endpoint.Type) 45 row := metav1.TableRow{ 46 Object: runtime.RawExtension{Object: c}, 47 } 48 row.Cells = append(row.Cells, name, provideType, credType, epType, strconv.FormatBool(c.Status.Healthy)) 49 return row 50 }