-
Notifications
You must be signed in to change notification settings - Fork 371
/
readiness_checks.go
54 lines (47 loc) · 1.43 KB
/
readiness_checks.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
package common
import (
"errors"
v1 "github.com/openshift/api/route/v1"
v12 "k8s.io/api/apps/v1"
netv1 "k8s.io/api/networking/v1"
)
const (
ConditionStatusSuccess = "True"
)
func IsRouteReady(route *v1.Route) bool {
if route == nil {
return false
}
// A route has a an array of Ingress where each have an array of conditions
for _, ingress := range route.Status.Ingress {
for _, condition := range ingress.Conditions {
// A successful route will have the admitted condition type as true
if condition.Type == v1.RouteAdmitted && condition.Status != ConditionStatusSuccess {
return false
}
}
}
return true
}
func IsIngressReady(ingress *netv1.Ingress) bool {
if ingress == nil {
return false
}
return len(ingress.Status.LoadBalancer.Ingress) > 0
}
func IsDeploymentReady(deployment *v12.Deployment) (bool, error) {
if deployment == nil {
return false, nil
}
// A deployment has an array of conditions
for _, condition := range deployment.Status.Conditions {
// One failure condition exists, if this exists, return the Reason
if condition.Type == v12.DeploymentReplicaFailure {
return false, errors.New(condition.Reason)
// A successful deployment will have the progressing condition type as true
} else if condition.Type == v12.DeploymentProgressing && condition.Status != ConditionStatusSuccess {
return false, nil
}
}
return deployment.Status.ReadyReplicas == deployment.Status.Replicas, nil
}