Skip to content

Commit f1e70cb

Browse files
authored
fix: deployer pod state update (#431)
Pod status won't be updated correctly due to timestampe check. The pod creation time won't change once it's set although the pod status can change. Therefore, checking creation time to check whether or not to decide status update prevents the correct status update. The modified code updates the status regardless of timestamp.
1 parent c7acbbb commit f1e70cb

File tree

1 file changed

+23
-16
lines changed
  • cmd/deployer/app/deployer

1 file changed

+23
-16
lines changed

cmd/deployer/app/deployer/k8s.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (deployer *K8sDeployer) GetMonitoredPodStatuses() (map[string]TaskHealthDet
180180
} else if len(out.Items) == 0 {
181181
pod.Status = v1.PodStatus{Phase: v1.PodUnknown}
182182
pod.UnknownCount++
183+
zap.S().Debugf("Items are empty")
183184
} else {
184185
if len(out.Items) > 1 {
185186
sort.Slice(out.Items, func(i, j int) bool {
@@ -191,22 +192,28 @@ func (deployer *K8sDeployer) GetMonitoredPodStatuses() (map[string]TaskHealthDet
191192

192193
lastPod := out.Items[0]
193194

194-
podCreationTime := lastPod.ObjectMeta.CreationTimestamp.Time
195-
196-
if podCreationTime.After(pod.CreationTime) {
197-
pod.CreationTime = podCreationTime
198-
199-
if lastPod.Status.Phase == v1.PodPending || lastPod.Status.Phase == v1.PodRunning {
200-
pod.Status = lastPod.Status
201-
// reset unknown count
202-
pod.UnknownCount = 0
203-
} else if lastPod.Status.Phase == v1.PodSucceeded {
204-
deployer.DeleteTaskFromMonitoring(pod.TaskID)
205-
} else if lastPod.Status.Phase == v1.PodUnknown {
206-
pod.UnknownCount++
207-
} else {
208-
pod.Status = lastPod.Status
209-
}
195+
pod.CreationTime = lastPod.ObjectMeta.CreationTimestamp.Time
196+
197+
switch lastPod.Status.Phase {
198+
case v1.PodPending:
199+
fallthrough
200+
201+
case v1.PodRunning:
202+
pod.Status = lastPod.Status
203+
// reset unknown count
204+
pod.UnknownCount = 0
205+
206+
case v1.PodSucceeded:
207+
deployer.DeleteTaskFromMonitoring(pod.TaskID)
208+
209+
case v1.PodUnknown:
210+
pod.UnknownCount++
211+
212+
case v1.PodFailed:
213+
fallthrough
214+
215+
default:
216+
pod.Status = lastPod.Status
210217
}
211218
}
212219

0 commit comments

Comments
 (0)