Merge pull request #303 from rancher/feature/lb-in-cluster-list

[FEATURE] clusterList: add bool for loadbalancer
pull/305/head
Thorsten Klein 4 years ago committed by GitHub
commit 46b0c53c43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      cmd/cluster/clusterList.go
  2. 10
      pkg/types/types.go

@ -103,7 +103,7 @@ func PrintClusters(clusters []*k3d.Cluster, flags clusterFlags) {
defer tabwriter.Flush()
if !flags.noHeader {
headers := []string{"NAME", "SERVERS", "AGENTS"} // TODO: getCluster: add status column
headers := []string{"NAME", "SERVERS", "AGENTS", "LOADBALANCER"} // TODO: getCluster: add status column
if flags.token {
headers = append(headers, "TOKEN")
}
@ -118,11 +118,12 @@ func PrintClusters(clusters []*k3d.Cluster, flags clusterFlags) {
for _, cluster := range clusters {
serverCount := cluster.ServerCount()
agentCount := cluster.AgentCount()
hasLB := cluster.HasLoadBalancer()
if flags.token {
fmt.Fprintf(tabwriter, "%s\t%d\t%d\t%s\n", cluster.Name, serverCount, agentCount, cluster.Token)
fmt.Fprintf(tabwriter, "%s\t%d\t%d\t%t\t%s\n", cluster.Name, serverCount, agentCount, hasLB, cluster.Token)
} else {
fmt.Fprintf(tabwriter, "%s\t%d\t%d\n", cluster.Name, serverCount, agentCount)
fmt.Fprintf(tabwriter, "%s\t%d\t%d\t%t\n", cluster.Name, serverCount, agentCount, hasLB)
}
}
}

@ -203,6 +203,16 @@ func (c *Cluster) AgentCount() int {
return agentCount
}
// HasLoadBalancer returns true if cluster has a loadbalancer node
func (c *Cluster) HasLoadBalancer() bool {
for _, node := range c.Nodes {
if node.Role == LoadBalancerRole {
return true
}
}
return false
}
// Node describes a k3d node
type Node struct {
Name string `yaml:"name" json:"name,omitempty"`

Loading…
Cancel
Save