printLoadBalancers blocks until all Services of type LoadBalancer have been deployed, printing it's details as it becomes available. Will panic if given something other than services
(client *kubecli.Client, services []KubeObject, localkube bool)
| 458 | // printLoadBalancers blocks until all Services of type LoadBalancer have been deployed, printing it's details as it becomes available. |
| 459 | // Will panic if given something other than services |
| 460 | func printLoadBalancers(client *kubecli.Client, services []KubeObject, localkube bool) { |
| 461 | if len(services) == 0 { |
| 462 | return |
| 463 | } |
| 464 | |
| 465 | first := true |
| 466 | completed := map[string]bool{} |
| 467 | |
| 468 | // checks when we've seen every service |
| 469 | done := func() bool { |
| 470 | for _, svcObj := range services { |
| 471 | s := svcObj.(*kube.Service) |
| 472 | if s.Spec.Type == kube.ServiceTypeLoadBalancer && !completed[s.Name] { |
| 473 | return false |
| 474 | } |
| 475 | } |
| 476 | return true |
| 477 | } |
| 478 | |
| 479 | for { |
| 480 | if done() { |
| 481 | return |
| 482 | } |
| 483 | |
| 484 | if first { |
| 485 | fmt.Println("Waiting for load balancer deployment...") |
| 486 | first = false |
| 487 | } |
| 488 | |
| 489 | for _, svcObj := range services { |
| 490 | s := svcObj.(*kube.Service) |
| 491 | if s.Spec.Type == kube.ServiceTypeLoadBalancer && !completed[s.Name] { |
| 492 | clusterVers, err := client.Services(s.Namespace).Get(s.Name) |
| 493 | if err != nil { |
| 494 | fmt.Printf("Error getting service `%s`: %v\n", s.Name, err) |
| 495 | } |
| 496 | |
| 497 | if localkube { |
| 498 | completed[s.Name] = true |
| 499 | for _, port := range clusterVers.Spec.Ports { |
| 500 | fmt.Printf("'%s/%s' - %s available on localkube host port:\t %d\n", s.Namespace, s.Name, port.Name, port.NodePort) |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | loadBalancers := clusterVers.Status.LoadBalancer.Ingress |
| 505 | for _, lb := range loadBalancers { |
| 506 | completed[s.Name] = true |
| 507 | |
| 508 | host := lb.Hostname |
| 509 | if len(lb.IP) != 0 { |
| 510 | if len(host) == 0 { |
| 511 | host = lb.IP |
| 512 | } else { |
| 513 | host += fmt.Sprintf(" (%s)", lb.IP) |
| 514 | } |
| 515 | } |
| 516 | fmt.Printf("Service '%s/%s' available at: \t%s\n", s.Namespace, s.Name, host) |
| 517 | } |