mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #83812 from oomichi/move-Initialized
Move Initialized() to e2e framework util
This commit is contained in:
commit
9aed79b585
@ -175,28 +175,6 @@ func CountRemainingPods(c clientset.Interface, namespace string) (int, int, erro
|
|||||||
return numPods, missingTimestamp, nil
|
return numPods, missingTimestamp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialized checks the state of all init containers in the pod.
|
|
||||||
func Initialized(pod *v1.Pod) (ok bool, failed bool, err error) {
|
|
||||||
allInit := true
|
|
||||||
initFailed := false
|
|
||||||
for _, s := range pod.Status.InitContainerStatuses {
|
|
||||||
switch {
|
|
||||||
case initFailed && s.State.Waiting == nil:
|
|
||||||
return allInit, initFailed, fmt.Errorf("container %s is after a failed container but isn't waiting", s.Name)
|
|
||||||
case allInit && s.State.Waiting == nil:
|
|
||||||
return allInit, initFailed, fmt.Errorf("container %s is after an initializing container but isn't waiting", s.Name)
|
|
||||||
case s.State.Terminated == nil:
|
|
||||||
allInit = false
|
|
||||||
case s.State.Terminated.ExitCode != 0:
|
|
||||||
allInit = false
|
|
||||||
initFailed = true
|
|
||||||
case !s.Ready:
|
|
||||||
return allInit, initFailed, fmt.Errorf("container %s initialized but isn't marked as ready", s.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return allInit, initFailed, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func podRunning(c clientset.Interface, podName, namespace string) wait.ConditionFunc {
|
func podRunning(c clientset.Interface, podName, namespace string) wait.ConditionFunc {
|
||||||
return func() (bool, error) {
|
return func() (bool, error) {
|
||||||
pod, err := c.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
|
pod, err := c.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
|
||||||
|
@ -675,10 +675,10 @@ func ContainerInitInvariant(older, newer runtime.Object) error {
|
|||||||
if err := initContainersInvariants(newPod); err != nil {
|
if err := initContainersInvariants(newPod); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
oldInit, _, _ := e2epod.Initialized(oldPod)
|
oldInit, _, _ := initialized(oldPod)
|
||||||
newInit, _, _ := e2epod.Initialized(newPod)
|
newInit, _, _ := initialized(newPod)
|
||||||
if oldInit && !newInit {
|
if oldInit && !newInit {
|
||||||
// TODO: we may in the future enable resetting Initialized = false if the kubelet needs to restart it
|
// TODO: we may in the future enable resetting initialized = false if the kubelet needs to restart it
|
||||||
// from scratch
|
// from scratch
|
||||||
return fmt.Errorf("pod cannot be initialized and then regress to not being initialized")
|
return fmt.Errorf("pod cannot be initialized and then regress to not being initialized")
|
||||||
}
|
}
|
||||||
@ -686,7 +686,7 @@ func ContainerInitInvariant(older, newer runtime.Object) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initContainersInvariants(pod *v1.Pod) error {
|
func initContainersInvariants(pod *v1.Pod) error {
|
||||||
allInit, initFailed, err := e2epod.Initialized(pod)
|
allInit, initFailed, err := initialized(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -2837,3 +2837,25 @@ func PrettyPrintJSON(metrics interface{}) string {
|
|||||||
}
|
}
|
||||||
return string(formatted.Bytes())
|
return string(formatted.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialized checks the state of all init containers in the pod.
|
||||||
|
func initialized(pod *v1.Pod) (ok bool, failed bool, err error) {
|
||||||
|
allInit := true
|
||||||
|
initFailed := false
|
||||||
|
for _, s := range pod.Status.InitContainerStatuses {
|
||||||
|
switch {
|
||||||
|
case initFailed && s.State.Waiting == nil:
|
||||||
|
return allInit, initFailed, fmt.Errorf("container %s is after a failed container but isn't waiting", s.Name)
|
||||||
|
case allInit && s.State.Waiting == nil:
|
||||||
|
return allInit, initFailed, fmt.Errorf("container %s is after an initializing container but isn't waiting", s.Name)
|
||||||
|
case s.State.Terminated == nil:
|
||||||
|
allInit = false
|
||||||
|
case s.State.Terminated.ExitCode != 0:
|
||||||
|
allInit = false
|
||||||
|
initFailed = true
|
||||||
|
case !s.Ready:
|
||||||
|
return allInit, initFailed, fmt.Errorf("container %s initialized but isn't marked as ready", s.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allInit, initFailed, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user