mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
fix-todo
This commit is contained in:
parent
00c1ec5201
commit
65b59474dc
@ -824,7 +824,7 @@ func WaitForPodCondition(c clientset.Interface, ns, podName, desc string, timeou
|
|||||||
}
|
}
|
||||||
// log now so that current pod info is reported before calling `condition()`
|
// log now so that current pod info is reported before calling `condition()`
|
||||||
Logf("Pod %q: Phase=%q, Reason=%q, readiness=%t. Elapsed: %v",
|
Logf("Pod %q: Phase=%q, Reason=%q, readiness=%t. Elapsed: %v",
|
||||||
podName, pod.Status.Phase, pod.Status.Reason, testutil.PodReady(pod), time.Since(start))
|
podName, pod.Status.Phase, pod.Status.Reason, podutil.IsPodReady(pod), time.Since(start))
|
||||||
if done, err := condition(pod); done {
|
if done, err := condition(pod); done {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
Logf("Pod %q satisfied condition %q", podName, desc)
|
Logf("Pod %q satisfied condition %q", podName, desc)
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContainerFailures struct {
|
type ContainerFailures struct {
|
||||||
@ -36,7 +37,7 @@ func PodRunningReady(p *v1.Pod) (bool, error) {
|
|||||||
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodRunning, p.Status.Phase)
|
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodRunning, p.Status.Phase)
|
||||||
}
|
}
|
||||||
// Check the ready condition is true.
|
// Check the ready condition is true.
|
||||||
if !PodReady(p) {
|
if !podutil.IsPodReady(p) {
|
||||||
return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v",
|
return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v",
|
||||||
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionTrue, p.Status.Conditions)
|
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionTrue, p.Status.Conditions)
|
||||||
}
|
}
|
||||||
@ -62,21 +63,20 @@ func FailedContainers(pod *v1.Pod) map[string]ContainerFailures {
|
|||||||
statuses := pod.Status.ContainerStatuses
|
statuses := pod.Status.ContainerStatuses
|
||||||
if len(statuses) == 0 {
|
if len(statuses) == 0 {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
for _, status := range statuses {
|
for _, status := range statuses {
|
||||||
if status.State.Terminated != nil {
|
if status.State.Terminated != nil {
|
||||||
states[status.ContainerID] = ContainerFailures{status: status.State.Terminated}
|
states[status.ContainerID] = ContainerFailures{status: status.State.Terminated}
|
||||||
} else if status.LastTerminationState.Terminated != nil {
|
} else if status.LastTerminationState.Terminated != nil {
|
||||||
states[status.ContainerID] = ContainerFailures{status: status.LastTerminationState.Terminated}
|
states[status.ContainerID] = ContainerFailures{status: status.LastTerminationState.Terminated}
|
||||||
}
|
}
|
||||||
if status.RestartCount > 0 {
|
if status.RestartCount > 0 {
|
||||||
var ok bool
|
var ok bool
|
||||||
if state, ok = states[status.ContainerID]; !ok {
|
if state, ok = states[status.ContainerID]; !ok {
|
||||||
state = ContainerFailures{}
|
state = ContainerFailures{}
|
||||||
}
|
|
||||||
state.Restarts = int(status.RestartCount)
|
|
||||||
states[status.ContainerID] = state
|
|
||||||
}
|
}
|
||||||
|
state.Restarts = int(status.RestartCount)
|
||||||
|
states[status.ContainerID] = state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,20 +103,9 @@ func TerminatedContainers(pod *v1.Pod) map[string]string {
|
|||||||
// PodNotReady checks whether pod p's has a ready condition of status false.
|
// PodNotReady checks whether pod p's has a ready condition of status false.
|
||||||
func PodNotReady(p *v1.Pod) (bool, error) {
|
func PodNotReady(p *v1.Pod) (bool, error) {
|
||||||
// Check the ready condition is false.
|
// Check the ready condition is false.
|
||||||
if PodReady(p) {
|
if podutil.IsPodReady(p) {
|
||||||
return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v",
|
return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v",
|
||||||
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionFalse, p.Status.Conditions)
|
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionFalse, p.Status.Conditions)
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// podReady returns whether pod has a condition of Ready with a status of true.
|
|
||||||
// TODO: should be replaced with podutil.IsPodReady
|
|
||||||
func PodReady(pod *v1.Pod) bool {
|
|
||||||
for _, cond := range pod.Status.Conditions {
|
|
||||||
if cond.Type == v1.PodReady && cond.Status == v1.ConditionTrue {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user