mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #16261 from zhengguoyong/update_condition
Auto commit by PR queue bot
This commit is contained in:
commit
081b21687e
@ -2833,7 +2833,7 @@ func readyPodCondition(isPodReady bool, reason, message string) []api.PodConditi
|
||||
}
|
||||
|
||||
// getPodReadyCondition returns ready condition if all containers in a pod are ready, else it returns an unready condition.
|
||||
func getPodReadyCondition(spec *api.PodSpec, containerStatuses []api.ContainerStatus) []api.PodCondition {
|
||||
func getPodReadyCondition(spec *api.PodSpec, containerStatuses []api.ContainerStatus, podPhase api.PodPhase) []api.PodCondition {
|
||||
// Find if all containers are ready or not.
|
||||
if containerStatuses == nil {
|
||||
return readyPodCondition(false, "UnknownContainerStatuses", "")
|
||||
@ -2849,6 +2849,12 @@ func getPodReadyCondition(spec *api.PodSpec, containerStatuses []api.ContainerSt
|
||||
unknownContainers = append(unknownContainers, container.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// In case of unexist unknowContainers, If pod has derminated successed and it has unreadyContainers, just return PodCompleted
|
||||
if podPhase == api.PodSucceeded && len(unknownContainers) == 0 {
|
||||
return readyPodCondition(false, fmt.Sprint("PodCompleted"), "")
|
||||
}
|
||||
|
||||
unreadyMessages := []string{}
|
||||
if len(unknownContainers) > 0 {
|
||||
unreadyMessages = append(unreadyMessages, fmt.Sprintf("containers with unknown status: %s", unknownContainers))
|
||||
@ -2910,7 +2916,7 @@ func (kl *Kubelet) generatePodStatus(pod *api.Pod) (api.PodStatus, error) {
|
||||
podStatus.Phase = GetPhase(spec, podStatus.ContainerStatuses)
|
||||
kl.probeManager.UpdatePodStatus(pod.UID, podStatus)
|
||||
|
||||
podStatus.Conditions = append(podStatus.Conditions, getPodReadyCondition(spec, podStatus.ContainerStatuses)...)
|
||||
podStatus.Conditions = append(podStatus.Conditions, getPodReadyCondition(spec, podStatus.ContainerStatuses, podStatus.Phase)...)
|
||||
|
||||
if !kl.standaloneMode {
|
||||
hostIP, err := kl.GetHostIP()
|
||||
|
@ -1933,16 +1933,19 @@ func TestGetPodReadyCondition(t *testing.T) {
|
||||
tests := []struct {
|
||||
spec *api.PodSpec
|
||||
containerStatuses []api.ContainerStatus
|
||||
podPhase api.PodPhase
|
||||
expected []api.PodCondition
|
||||
}{
|
||||
{
|
||||
spec: nil,
|
||||
containerStatuses: nil,
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "UnknownContainerStatuses", ""),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{},
|
||||
containerStatuses: []api.ContainerStatus{},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionTrue, "", ""),
|
||||
},
|
||||
{
|
||||
@ -1952,6 +1955,7 @@ func TestGetPodReadyCondition(t *testing.T) {
|
||||
},
|
||||
},
|
||||
containerStatuses: []api.ContainerStatus{},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "ContainersNotReady", "containers with unknown status: [1234]"),
|
||||
},
|
||||
{
|
||||
@ -1965,6 +1969,7 @@ func TestGetPodReadyCondition(t *testing.T) {
|
||||
getReadyStatus("1234"),
|
||||
getReadyStatus("5678"),
|
||||
},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionTrue, "", ""),
|
||||
},
|
||||
{
|
||||
@ -1977,6 +1982,7 @@ func TestGetPodReadyCondition(t *testing.T) {
|
||||
containerStatuses: []api.ContainerStatus{
|
||||
getReadyStatus("1234"),
|
||||
},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "ContainersNotReady", "containers with unknown status: [5678]"),
|
||||
},
|
||||
{
|
||||
@ -1990,12 +1996,25 @@ func TestGetPodReadyCondition(t *testing.T) {
|
||||
getReadyStatus("1234"),
|
||||
getNotReadyStatus("5678"),
|
||||
},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "ContainersNotReady", "containers with unready status: [5678]"),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Name: "1234"},
|
||||
},
|
||||
},
|
||||
containerStatuses: []api.ContainerStatus{
|
||||
getNotReadyStatus("1234"),
|
||||
},
|
||||
podPhase: api.PodSucceeded,
|
||||
expected: getReadyCondition(api.ConditionFalse, "PodCompleted", ""),
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
condition := getPodReadyCondition(test.spec, test.containerStatuses)
|
||||
condition := getPodReadyCondition(test.spec, test.containerStatuses, test.podPhase)
|
||||
if !reflect.DeepEqual(condition, test.expected) {
|
||||
t.Errorf("On test case %v, expected:\n%+v\ngot\n%+v\n", i, test.expected, condition)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user