Skip to content

Commit 012a90e

Browse files
authored
Merge pull request #46 from supermeng/master
Make state of pod clearer
2 parents 9537566 + 5dd6155 commit 012a90e

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

engine/pod.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (pc *podController) Deploy(cluster cluster.Cluster) {
8787
id, err := pc.createContainer(cluster, filters, i)
8888
if err != nil {
8989
log.Warnf("%s Cannot create container, error=%q, spec=%+v", pc, err, cSpec)
90-
pc.pod.State = RunStateFail
90+
pc.pod.State = RunStateError
9191
pc.pod.LastError = fmt.Sprintf("Cannot create container, %s", err)
9292
return
9393
}
@@ -187,7 +187,7 @@ func (pc *podController) Stop(cluster cluster.Cluster) {
187187
for i, container := range pc.pod.Containers {
188188
if err := cluster.StopContainer(container.Id, pc.spec.GetKillTimeout()); err != nil {
189189
log.Warnf("%s Cannot stop the container %s, %s", pc, container.Id, err)
190-
pc.pod.State = RunStateFail
190+
pc.pod.State = RunStateError
191191
pc.pod.LastError = fmt.Sprintf("Cannot stop container, %s", err)
192192
} else {
193193
pc.refreshContainer(cluster, i)
@@ -212,7 +212,7 @@ func (pc *podController) Start(cluster cluster.Cluster) {
212212
pc.refreshContainer(cluster, i)
213213
} else {
214214
log.Warnf("%s Cannot start the container %s, %s", pc, container.Id, err)
215-
pc.pod.State = RunStateFail
215+
pc.pod.State = RunStateError
216216
pc.pod.LastError = fmt.Sprintf("Cannot start container, %s", err)
217217
}
218218
}
@@ -231,7 +231,7 @@ func (pc *podController) Restart(cluster cluster.Cluster) {
231231
for i, container := range pc.pod.Containers {
232232
if err := cluster.RestartContainer(container.Id, pc.spec.GetKillTimeout()); err != nil {
233233
log.Warnf("%s Cannot restart the container %s, %s", pc, container.Id, err)
234-
pc.pod.State = RunStateFail
234+
pc.pod.State = RunStateError
235235
pc.pod.LastError = fmt.Sprintf("Cannot restart container, %s", err)
236236
} else {
237237
pc.refreshContainer(cluster, i)
@@ -285,7 +285,7 @@ func (pc *podController) startContainer(cluster cluster.Cluster, id string) erro
285285
log.Warnf("%s Cannot release IP %s, %s", pc, id, err)
286286
}
287287
}
288-
pc.pod.State = RunStateFail
288+
pc.pod.State = RunStateError
289289
pc.pod.LastError = fmt.Sprintf("Cannot start container, %s", err)
290290
return err
291291
}
@@ -329,7 +329,7 @@ func (pc *podController) refreshContainer(kluster cluster.Cluster, index int) {
329329
pc.pod.LastError = fmt.Sprintf("Missing container %q, %s", id, err)
330330
} else {
331331
log.Warnf("%s Failed to inspect container %s, %s", pc, id, err)
332-
pc.pod.State = RunStateFail
332+
pc.pod.State = RunStateError
333333
pc.pod.LastError = fmt.Sprintf("Cannot inspect the container, %s", err)
334334
}
335335
} else {

engine/podgroup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ func (pgCtrl *podGroupController) Refresh(force bool) {
297297
if pgCtrl.IsRemoved() || pgCtrl.IsPending() {
298298
return
299299
}
300+
pgCtrl.emitOperationEvent(OperationStart)
300301
pgCtrl.DisableRefresh()
301302
defer func() {
302303
pgCtrl.opsChan <- pgOperOver{}

engine/podgroup_ops.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (op pgOperRefreshInstance) Do(pgCtrl *podGroupController, c cluster.Cluster
253253
runtime = podCtrl.pod.ImRuntime
254254
consistent = false
255255
}
256-
} else if runtime.State == RunStateExit {
256+
} else if runtime.State == RunStateExit || runtime.State == RunStateFail {
257257
if !pgCtrl.engine.config.Maintenance && podCtrl.pod.NeedRestart(op.spec.RestartPolicy) {
258258
if podCtrl.pod.RestartEnoughTimes() {
259259
ntfController.Send(NewNotifySpec(podCtrl.spec.Namespace, podCtrl.spec.Name,
@@ -583,18 +583,18 @@ func (op pgOperChangeState) Do(pgCtrl *podGroupController, c cluster.Cluster, st
583583
switch op.op {
584584
case "start":
585585
podCtrl.Start(c)
586-
if podCtrl.pod.State != RunStateFail {
586+
if podCtrl.pod.State != RunStateError {
587587
podCtrl.pod.ChangeTargetState(ExpectStateRun)
588588
}
589589
case "stop":
590590
podCtrl.Stop(c)
591-
if podCtrl.pod.State != RunStateFail {
591+
if podCtrl.pod.State != RunStateError {
592592
podCtrl.pod.ChangeTargetState(ExpectStateStop)
593593
}
594594
case "restart":
595595
pgCtrl.waitLastPodHealth(op.instance)
596596
podCtrl.Restart(c)
597-
if podCtrl.pod.State != RunStateFail {
597+
if podCtrl.pod.State != RunStateError {
598598
podCtrl.pod.ChangeTargetState(ExpectStateRun)
599599
}
600600
}

engine/runtimes.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ type PGOpState int32
1414
var RestartMaxCount int
1515

1616
const (
17-
RunStatePending = iota
18-
RunStateDrift
19-
RunStateSuccess
20-
RunStateExit
21-
RunStateFail
22-
RunStateInconsistent
23-
RunStateMissing
24-
RunStateRemoved
25-
RunStatePaused
17+
RunStatePending = iota // waiting for operation
18+
RunStateDrift // drifting from one node to another
19+
RunStateSuccess // ok
20+
RunStateExit // exited
21+
RunStateFail // start failed with error
22+
RunStateInconsistent // container's state is different between deployd and swarm
23+
RunStateMissing // container is missing and need create it. happened when node down .etc
24+
RunStateRemoved // removed
25+
RunStatePaused // paused
26+
RunStateError // call docker interface with error
2627
)
2728

2829
const (
@@ -68,6 +69,8 @@ func (rs RunState) String() string {
6869
return "RunStateRemoved"
6970
case RunStatePaused:
7071
return "RunStatePaused"
72+
case RunStateError:
73+
return "RunStateError"
7174
default:
7275
return "Unknown RunState"
7376
}

0 commit comments

Comments
 (0)