Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace controller presence checking logic #36924

Merged
merged 1 commit into from
Nov 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 24 additions & 25 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,6 @@ func errorBadPodsStates(badPods []api.Pod, desiredPods int, ns, desiredState str
return errStr + buf.String()
}

// check if a Pod is controlled by a Replication Controller in the List
func hasReplicationControllersForPod(rcs *api.ReplicationControllerList, pod api.Pod) bool {
for _, rc := range rcs.Items {
selector := labels.SelectorFromSet(rc.Spec.Selector)
if selector.Matches(labels.Set(pod.ObjectMeta.Labels)) {
return true
}
}
return false
}

// WaitForPodsSuccess waits till all labels matching the given selector enter
// the Success state. The caller is expected to only invoke this method once the
// pods have been created.
Expand Down Expand Up @@ -490,9 +479,9 @@ func WaitForPodsSuccess(c clientset.Interface, ns string, successPodLabels map[s

// WaitForPodsRunningReady waits up to timeout to ensure that all pods in
// namespace ns are either running and ready, or failed but controlled by a
// replication controller. Also, it ensures that at least minPods are running
// and ready. It has separate behavior from other 'wait for' pods functions in
// that it requires the list of pods on every iteration. This is useful, for
// controller. Also, it ensures that at least minPods are running and
// ready. It has separate behavior from other 'wait for' pods functions in
// that it requests the list of pods on every iteration. This is useful, for
// example, in cluster startup, because the number of pods increases while
// waiting.
// If ignoreLabels is not empty, pods matching this selector are ignored and
Expand All @@ -517,25 +506,38 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods int32, ti
}()

if wait.PollImmediate(Poll, timeout, func() (bool, error) {
// We get the new list of pods and replication controllers in every
// iteration because more pods come online during startup and we want to
// ensure they are also checked.
// We get the new list of pods, replication controllers, and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nittiest of nits: the comment for WaitForPodsRunningReady could also use this touch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitted

// replica sets in every iteration because more pods come
// online during startup and we want to ensure they are also
// checked.
replicas, replicaOk := int32(0), int32(0)

rcList, err := c.Core().ReplicationControllers(ns).List(api.ListOptions{})
if err != nil {
Logf("Error getting replication controllers in namespace '%s': %v", ns, err)
return false, nil
}
replicas := int32(0)
for _, rc := range rcList.Items {
replicas += rc.Spec.Replicas
replicaOk += rc.Status.ReadyReplicas
}

rsList, err := c.Extensions().ReplicaSets(ns).List(api.ListOptions{})
if err != nil {
Logf("Error getting replication sets in namespace %q: %v", ns, err)
return false, nil
}
for _, rs := range rsList.Items {
replicas += rs.Spec.Replicas
replicaOk += rs.Status.ReadyReplicas
}

podList, err := c.Core().Pods(ns).List(api.ListOptions{})
if err != nil {
Logf("Error getting pods in namespace '%s': %v", ns, err)
return false, nil
}
nOk, replicaOk := int32(0), int32(0)
nOk := int32(0)
badPods = []api.Pod{}
desiredPods = len(podList.Items)
for _, pod := range podList.Items {
Expand All @@ -545,18 +547,15 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods int32, ti
}
if res, err := testutils.PodRunningReady(&pod); res && err == nil {
nOk++
if hasReplicationControllersForPod(rcList, pod) {
replicaOk++
}
} else {
if pod.Status.Phase != api.PodFailed {
Logf("The status of Pod %s is %s (Ready = false), waiting for it to be either Running (with Ready = true) or Failed", pod.ObjectMeta.Name, pod.Status.Phase)
badPods = append(badPods, pod)
} else if !hasReplicationControllersForPod(rcList, pod) {
Logf("Pod %s is Failed, but it's not controlled by a ReplicationController", pod.ObjectMeta.Name)
} else if _, ok := pod.Annotations[api.CreatedByAnnotation]; !ok {
Logf("Pod %s is Failed, but it's not controlled by a controller", pod.ObjectMeta.Name)
badPods = append(badPods, pod)
}
//ignore failed pods that are controlled by a replication controller
//ignore failed pods that are controlled by some controller
}
}

Expand Down