-
Notifications
You must be signed in to change notification settings - Fork 13
/
pod_readiness_module.go
50 lines (42 loc) · 1.48 KB
/
pod_readiness_module.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
package pods
import (
"fmt"
"strings"
"time"
"github.com/alipay/container-observability-service/pkg/reason/modules"
"github.com/alipay/container-observability-service/pkg/reason/share"
"github.com/alipay/container-observability-service/pkg/reason/utils"
"github.com/alipay/container-observability-service/pkg/shares"
utils2 "github.com/alipay/container-observability-service/pkg/utils"
v1 "k8s.io/api/core/v1"
)
func init() {
modules.ShareModuleFactory.Register(share.POD_READINESS, func() modules.DeliveryModule {
return modules.NewDAGDeliveryModule(share.POD_READINESS, PodReadinessReason)
})
}
func PodReadinessReason(auditEvents []*shares.AuditEvent, beginTime *time.Time, endTime *time.Time) (result string, hasError bool) {
pod := utils.GetPodYamlFromHyperEvents(auditEvents, endTime)
if pod == nil {
return "", false
}
defer utils2.IgnorePanic("analyze_pod_readiness ")
conditionMap := make(map[string]string)
rs := "PodNotReady"
for _, ct := range pod.Status.Conditions {
conditionMap[string(ct.Type)] = string(ct.Status)
}
if cr, ok := conditionMap[string(v1.ContainersReady)]; ok && cr != string(v1.ConditionTrue) {
return "", false
}
//如果有readinessGates
for _, rg := range pod.Spec.ReadinessGates {
if _, ok := conditionMap[string(rg.ConditionType)]; !ok || strings.EqualFold(conditionMap[string(rg.ConditionType)], "false") {
rs = fmt.Sprintf("%s_NotReady", string(rg.ConditionType))
}
}
if rs != "PodNotReady" {
return rs, true
}
return "", false
}