mirror of https://github.com/k3s-io/k3s
Merge pull request #52688 from tanshanshan/new-test-pr
Automatic merge from submit-queue (batch tested with PRs 53350, 52688, 53531, 52515). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. PodReady should be replaced with podutil.IsPodReady **What this PR does / why we need it**: PodReady should be replaced with podutil.IsPodReady. Thanks. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note ```pull/6/head
commit
edd6c8e4af
|
@ -825,7 +825,7 @@ func WaitForPodCondition(c clientset.Interface, ns, podName, desc string, timeou
|
|||
}
|
||||
// log now so that current pod info is reported before calling `condition()`
|
||||
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 err == nil {
|
||||
Logf("Pod %q satisfied condition %q", podName, desc)
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
// 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",
|
||||
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
|
||||
if len(statuses) == 0 {
|
||||
return nil
|
||||
} else {
|
||||
for _, status := range statuses {
|
||||
if status.State.Terminated != nil {
|
||||
states[status.ContainerID] = ContainerFailures{status: status.State.Terminated}
|
||||
} else if status.LastTerminationState.Terminated != nil {
|
||||
states[status.ContainerID] = ContainerFailures{status: status.LastTerminationState.Terminated}
|
||||
}
|
||||
if status.RestartCount > 0 {
|
||||
var ok bool
|
||||
if state, ok = states[status.ContainerID]; !ok {
|
||||
state = ContainerFailures{}
|
||||
}
|
||||
state.Restarts = int(status.RestartCount)
|
||||
states[status.ContainerID] = state
|
||||
}
|
||||
for _, status := range statuses {
|
||||
if status.State.Terminated != nil {
|
||||
states[status.ContainerID] = ContainerFailures{status: status.State.Terminated}
|
||||
} else if status.LastTerminationState.Terminated != nil {
|
||||
states[status.ContainerID] = ContainerFailures{status: status.LastTerminationState.Terminated}
|
||||
}
|
||||
if status.RestartCount > 0 {
|
||||
var ok bool
|
||||
if state, ok = states[status.ContainerID]; !ok {
|
||||
state = ContainerFailures{}
|
||||
}
|
||||
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.
|
||||
func PodNotReady(p *v1.Pod) (bool, error) {
|
||||
// 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",
|
||||
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionFalse, p.Status.Conditions)
|
||||
}
|
||||
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