-
Notifications
You must be signed in to change notification settings - Fork 90
/
proxy.go
36 lines (29 loc) · 865 Bytes
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package k8sutil
import (
"time"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
func WaitForKotsadm(clientset *kubernetes.Clientset, namespace string, timeoutWaitingForWeb time.Duration) (string, error) {
start := time.Now()
for {
// todo, find service, not pod
pods, err := clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: "app=kotsadm"})
if err != nil {
return "", errors.Wrap(err, "failed to list pods")
}
for _, pod := range pods.Items {
if pod.Status.Phase == corev1.PodRunning {
if pod.Status.ContainerStatuses[0].Ready == true {
return pod.Name, nil
}
}
}
time.Sleep(time.Second)
if time.Now().Sub(start) > timeoutWaitingForWeb {
return "", errors.New("timeout waiting for kotsadm pod")
}
}
}