Log pods of RS when deployment e2e test fails
This commit is contained in:
		@@ -179,7 +179,7 @@ func GetReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Returns the number of available pods corresponding to the given replica sets.
 | 
					// Returns the number of available pods corresponding to the given replica sets.
 | 
				
			||||||
func GetAvailablePodsForReplicaSets(c clientset.Interface, rss []*extensions.ReplicaSet, minReadySeconds int) (int, error) {
 | 
					func GetAvailablePodsForReplicaSets(c clientset.Interface, rss []*extensions.ReplicaSet, minReadySeconds int) (int, error) {
 | 
				
			||||||
	allPods, err := getPodsForReplicaSets(c, rss)
 | 
						allPods, err := GetPodsForReplicaSets(c, rss)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return 0, err
 | 
							return 0, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -189,7 +189,17 @@ func GetAvailablePodsForReplicaSets(c clientset.Interface, rss []*extensions.Rep
 | 
				
			|||||||
func getReadyPodsCount(pods []api.Pod, minReadySeconds int) int {
 | 
					func getReadyPodsCount(pods []api.Pod, minReadySeconds int) int {
 | 
				
			||||||
	readyPodCount := 0
 | 
						readyPodCount := 0
 | 
				
			||||||
	for _, pod := range pods {
 | 
						for _, pod := range pods {
 | 
				
			||||||
		if api.IsPodReady(&pod) {
 | 
							if IsPodAvailable(&pod, minReadySeconds) {
 | 
				
			||||||
 | 
								readyPodCount++
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return readyPodCount
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func IsPodAvailable(pod *api.Pod, minReadySeconds int) bool {
 | 
				
			||||||
 | 
						if !api.IsPodReady(pod) {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	// Check if we've passed minReadySeconds since LastTransitionTime
 | 
						// Check if we've passed minReadySeconds since LastTransitionTime
 | 
				
			||||||
	// If so, this pod is ready
 | 
						// If so, this pod is ready
 | 
				
			||||||
	for _, c := range pod.Status.Conditions {
 | 
						for _, c := range pod.Status.Conditions {
 | 
				
			||||||
@@ -200,17 +210,14 @@ func getReadyPodsCount(pods []api.Pod, minReadySeconds int) int {
 | 
				
			|||||||
			// 2. LastTransitionTime (is set) + minReadySeconds (>0) < current time
 | 
								// 2. LastTransitionTime (is set) + minReadySeconds (>0) < current time
 | 
				
			||||||
			minReadySecondsDuration := time.Duration(minReadySeconds) * time.Second
 | 
								minReadySecondsDuration := time.Duration(minReadySeconds) * time.Second
 | 
				
			||||||
			if minReadySeconds <= 0 || !c.LastTransitionTime.IsZero() && c.LastTransitionTime.Add(minReadySecondsDuration).Before(time.Now()) {
 | 
								if minReadySeconds <= 0 || !c.LastTransitionTime.IsZero() && c.LastTransitionTime.Add(minReadySecondsDuration).Before(time.Now()) {
 | 
				
			||||||
						readyPodCount++
 | 
									return true
 | 
				
			||||||
						break
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		}
 | 
						return false
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return readyPodCount
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getPodsForReplicaSets(c clientset.Interface, replicaSets []*extensions.ReplicaSet) ([]api.Pod, error) {
 | 
					func GetPodsForReplicaSets(c clientset.Interface, replicaSets []*extensions.ReplicaSet) ([]api.Pod, error) {
 | 
				
			||||||
	allPods := []api.Pod{}
 | 
						allPods := []api.Pod{}
 | 
				
			||||||
	for _, rs := range replicaSets {
 | 
						for _, rs := range replicaSets {
 | 
				
			||||||
		selector, err := unversioned.LabelSelectorAsSelector(rs.Spec.Selector)
 | 
							selector, err := unversioned.LabelSelectorAsSelector(rs.Spec.Selector)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2128,6 +2128,7 @@ func waitForDeploymentStatus(c clientset.Interface, ns, deploymentName string, d
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		if totalAvailable < minAvailable {
 | 
							if totalAvailable < minAvailable {
 | 
				
			||||||
			logReplicaSetsOfDeployment(deploymentName, oldRSs, newRS)
 | 
								logReplicaSetsOfDeployment(deploymentName, oldRSs, newRS)
 | 
				
			||||||
 | 
								logPodsOfReplicaSets(c, allRSs, minReadySeconds)
 | 
				
			||||||
			return false, fmt.Errorf("total pods available: %d, less than the min required: %d", totalAvailable, minAvailable)
 | 
								return false, fmt.Errorf("total pods available: %d, less than the min required: %d", totalAvailable, minAvailable)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2170,6 +2171,19 @@ func logReplicaSetsOfDeployment(deploymentName string, oldRSs []*extensions.Repl
 | 
				
			|||||||
	Logf("New ReplicaSet of deployment %s: %+v", deploymentName, newRS)
 | 
						Logf("New ReplicaSet of deployment %s: %+v", deploymentName, newRS)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func logPodsOfReplicaSets(c clientset.Interface, rss []*extensions.ReplicaSet, minReadySeconds int) {
 | 
				
			||||||
 | 
						allPods, err := deploymentutil.GetPodsForReplicaSets(c, rss)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							for _, pod := range allPods {
 | 
				
			||||||
 | 
								availability := "not available"
 | 
				
			||||||
 | 
								if deploymentutil.IsPodAvailable(&pod, minReadySeconds) {
 | 
				
			||||||
 | 
									availability = "available"
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								Logf("Pod %s is %s: %+v", pod.Name, availability, pod)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Waits for the number of events on the given object to reach a desired count.
 | 
					// Waits for the number of events on the given object to reach a desired count.
 | 
				
			||||||
func waitForEvents(c *client.Client, ns string, objOrRef runtime.Object, desiredEventsCount int) error {
 | 
					func waitForEvents(c *client.Client, ns string, objOrRef runtime.Object, desiredEventsCount int) error {
 | 
				
			||||||
	return wait.Poll(poll, 5*time.Minute, func() (bool, error) {
 | 
						return wait.Poll(poll, 5*time.Minute, func() (bool, error) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user