-
Notifications
You must be signed in to change notification settings - Fork 0
/
validations.go
59 lines (53 loc) · 1.41 KB
/
validations.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
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
api "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"net/http"
)
func CheckPods(namespace string, client *kubernetes.Clientset) {
options := v1.ListOptions{}
pods, err := client.CoreV1().Pods(namespace).List(options)
if err != nil {
KError(err)
}
KInfo("checking", namespace, ":", len(pods.Items), "pods found")
for _, pod := range pods.Items {
if pod.Status.Phase != api.PodRunning && pod.Status.Phase != api.PodSucceeded {
KFail(pod.Name, "not working")
return
}
}
KPass(namespace, "pod status: OK")
}
func CheckEndpoints(namespace string, client *kubernetes.Clientset) {
options := v1.ListOptions{}
svcs, err := client.CoreV1().Endpoints(namespace).List(options)
if err != nil {
KError(err)
}
KInfo("checking", namespace, ":", len(svcs.Items), "endpoints found")
for _, svc := range svcs.Items {
for _, ep := range svc.Subsets {
if len(ep.NotReadyAddresses) > 0 {
KFail(svc.Name, "has endpoint not ready")
return
}
}
}
KPass(namespace, "endpoints status: OK")
}
func PingPath(path string) {
var client http.Client
req, _ := http.NewRequest("GET", uri+path, nil)
resp, err := client.Do(req)
if err != nil {
KFail("trying to reach", uri+path, err)
return
}
if resp.StatusCode > 399 {
KFail(uri+path, "fail with response", resp.StatusCode)
} else {
KPass(uri+path, "pass with response", resp.StatusCode)
}
}