-
Notifications
You must be signed in to change notification settings - Fork 90
/
proxy.go
38 lines (31 loc) · 980 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
37
38
package k8sutil
import (
"context"
"time"
"github.com/pkg/errors"
kotsadmtypes "github.com/replicatedhq/kots/pkg/kotsadm/types"
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(context.TODO(), 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 "", &kotsadmtypes.ErrorTimeout{Message: "timeout waiting for kotsadm pod"}
}
}
}