Skip to content

Commit 5150ed9

Browse files
papa-hexuanhexuansysulq
authored
fix: filter invalid pod status and ip (#129)
* 过滤非Running状态 * 过滤非正常状态和ip的pod * remove succeeded status Co-authored-by: hexuan <hexuan@douyu.tv> Co-authored-by: 大可 <hnlq.sysu@gmail.com>
1 parent 6d10abf commit 5150ed9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

internal/pkg/service/k8s/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ const (
1313
podItem = "/api/v1/namespaces/%s/pods/%s"
1414
podLog = "/api/v1/namespaces/%s/pods/%s/log"
1515
)
16+
17+
var AllowPodStatus = map[string]bool{
18+
"Running": true,
19+
}

internal/pkg/service/k8s/pod.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ func (i *syncPod) commonCheck(in *v1.Pod) error {
129129
return errors.New("exclude Suffix " + suffix)
130130
}
131131
}
132+
// 检查状态
133+
if !AllowPodStatus[string(in.Status.Phase)] {
134+
return errors.New("pass status " + string(in.Status.Phase))
135+
}
136+
// 检查容器ip
137+
if strings.TrimSpace(in.Status.PodIP) == "" {
138+
return errors.New("pass nil pod ip ")
139+
}
132140
return nil
133141
}
134142
func (i *syncPod) add(obj interface{}) {
@@ -147,6 +155,7 @@ func (i *syncPod) add(obj interface{}) {
147155
xlog.String("step", "add-print"),
148156
xlog.String("zoneCode", i.zoneCode),
149157
xlog.String("podName", in.Name),
158+
xlog.String("status", string(in.Status.Phase)),
150159
xlog.Any("lab", in.Labels))
151160

152161
err = i.mysqlCreateOrUpdate(i.zoneCode, obj.(*v1.Pod))

0 commit comments

Comments
 (0)