-
Notifications
You must be signed in to change notification settings - Fork 90
/
proxy.go
47 lines (38 loc) · 1.11 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
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"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
func WaitForKotsadm(namespace string, timeoutWaitingForWeb time.Duration) (string, error) {
cfg, err := config.GetConfig()
if err != nil {
return "", errors.Wrap(err, "failed to get cluster config")
}
clientset, err := kubernetes.NewForConfig(cfg)
if err != nil {
return "", errors.Wrap(err, "failed to create kubernetes clientset")
}
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")
}
}
}