mirror of
https://github.com/containers/podman.git
synced 2025-05-21 09:05:56 +08:00
Add a Degraded state to pods
Make a distinction between pods that are completely running (all containers running) and those that have some containers going, but not all, by introducing an intermediate state between Stopped and Running called Degraded. A Degraded pod has at least one, but not all, containers running; a Running pod has all containers running. First step to a solution for #7213. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -10,9 +10,12 @@ const (
|
|||||||
PodStateExited = "Exited"
|
PodStateExited = "Exited"
|
||||||
// PodStatePaused indicates the pod has been paused
|
// PodStatePaused indicates the pod has been paused
|
||||||
PodStatePaused = "Paused"
|
PodStatePaused = "Paused"
|
||||||
// PodStateRunning indicates that one or more of the containers in
|
// PodStateRunning indicates that all of the containers in the pod are
|
||||||
// the pod is running
|
// running.
|
||||||
PodStateRunning = "Running"
|
PodStateRunning = "Running"
|
||||||
|
// PodStateDegraded indicates that at least one, but not all, of the
|
||||||
|
// containers in the pod are running.
|
||||||
|
PodStateDegraded = "Degraded"
|
||||||
// PodStateStopped indicates all of the containers belonging to the pod
|
// PodStateStopped indicates all of the containers belonging to the pod
|
||||||
// are stopped.
|
// are stopped.
|
||||||
PodStateStopped = "Stopped"
|
PodStateStopped = "Stopped"
|
||||||
|
@ -506,7 +506,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
|
|||||||
})
|
})
|
||||||
ctrStatuses[c.ID()] = c.state.State
|
ctrStatuses[c.ID()] = c.state.State
|
||||||
}
|
}
|
||||||
podState, err := CreatePodStatusResults(ctrStatuses)
|
podState, err := createPodStatusResults(ctrStatuses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,10 @@ func (p *Pod) GetPodStatus() (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return define.PodStateErrored, err
|
return define.PodStateErrored, err
|
||||||
}
|
}
|
||||||
return CreatePodStatusResults(ctrStatuses)
|
return createPodStatusResults(ctrStatuses)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreatePodStatusResults(ctrStatuses map[string]define.ContainerStatus) (string, error) {
|
func createPodStatusResults(ctrStatuses map[string]define.ContainerStatus) (string, error) {
|
||||||
ctrNum := len(ctrStatuses)
|
ctrNum := len(ctrStatuses)
|
||||||
if ctrNum == 0 {
|
if ctrNum == 0 {
|
||||||
return define.PodStateCreated, nil
|
return define.PodStateCreated, nil
|
||||||
@ -43,8 +43,10 @@ func CreatePodStatusResults(ctrStatuses map[string]define.ContainerStatus) (stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case statuses[define.PodStateRunning] > 0:
|
case statuses[define.PodStateRunning] == ctrNum:
|
||||||
return define.PodStateRunning, nil
|
return define.PodStateRunning, nil
|
||||||
|
case statuses[define.PodStateRunning] > 0:
|
||||||
|
return define.PodStateDegraded, nil
|
||||||
case statuses[define.PodStatePaused] == ctrNum:
|
case statuses[define.PodStatePaused] == ctrNum:
|
||||||
return define.PodStatePaused, nil
|
return define.PodStatePaused, nil
|
||||||
case statuses[define.PodStateStopped] == ctrNum:
|
case statuses[define.PodStateStopped] == ctrNum:
|
||||||
|
@ -428,4 +428,34 @@ entrypoint ["/fromimage"]
|
|||||||
Expect(check.ExitCode()).To(Equal(0))
|
Expect(check.ExitCode()).To(Equal(0))
|
||||||
Expect(check.OutputToString()).To(Equal("[port_handler=slirp4netns]"))
|
Expect(check.OutputToString()).To(Equal("[port_handler=slirp4netns]"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman pod status test", func() {
|
||||||
|
podName := "testpod"
|
||||||
|
create := podmanTest.Podman([]string{"pod", "create", "--name", podName})
|
||||||
|
create.WaitWithDefaultTimeout()
|
||||||
|
Expect(create.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
status1 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName})
|
||||||
|
status1.WaitWithDefaultTimeout()
|
||||||
|
Expect(status1.ExitCode()).To(Equal(0))
|
||||||
|
Expect(strings.Contains(status1.OutputToString(), "Created")).To(BeTrue())
|
||||||
|
|
||||||
|
ctr1 := podmanTest.Podman([]string{"run", "--pod", podName, "-d", ALPINE, "top"})
|
||||||
|
ctr1.WaitWithDefaultTimeout()
|
||||||
|
Expect(ctr1.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
status2 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName})
|
||||||
|
status2.WaitWithDefaultTimeout()
|
||||||
|
Expect(status2.ExitCode()).To(Equal(0))
|
||||||
|
Expect(strings.Contains(status2.OutputToString(), "Running")).To(BeTrue())
|
||||||
|
|
||||||
|
ctr2 := podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||||
|
ctr2.WaitWithDefaultTimeout()
|
||||||
|
Expect(ctr2.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
status3 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName})
|
||||||
|
status3.WaitWithDefaultTimeout()
|
||||||
|
Expect(status3.ExitCode()).To(Equal(0))
|
||||||
|
Expect(strings.Contains(status3.OutputToString(), "Degraded")).To(BeTrue())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user