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

Cherry-pick #34456 in release-1.4 #38385

Merged
merged 1 commit into from Dec 8, 2016
Merged
Show file tree
Hide file tree
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
8 changes: 1 addition & 7 deletions pkg/controller/deployment/rolling_test.go
Expand Up @@ -390,7 +390,6 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
oldReplicas int
scaleExpected bool
expectedOldReplicas int
errorExpected bool
}{
{
deploymentReplicas: 10,
Expand All @@ -399,7 +398,6 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
oldReplicas: 10,
scaleExpected: true,
expectedOldReplicas: 9,
errorExpected: false,
},
{
deploymentReplicas: 10,
Expand All @@ -408,31 +406,27 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
oldReplicas: 10,
scaleExpected: true,
expectedOldReplicas: 8,
errorExpected: false,
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
readyPods: 8,
oldReplicas: 10,
scaleExpected: false,
errorExpected: false,
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
readyPods: 10,
oldReplicas: 0,
scaleExpected: false,
errorExpected: true,
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
readyPods: 1,
oldReplicas: 10,
scaleExpected: false,
errorExpected: false,
},
}

Expand Down Expand Up @@ -472,7 +466,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
eventRecorder: &record.FakeRecorder{},
}
scaled, err := controller.scaleDownOldReplicaSetsForRollingUpdate(allRSs, oldRSs, &deployment)
if !test.errorExpected && err != nil {
if err != nil {
t.Errorf("unexpected error: %v", err)
continue
}
Expand Down
17 changes: 5 additions & 12 deletions pkg/controller/deployment/util/deployment_util.go
Expand Up @@ -610,7 +610,7 @@ func GetAvailablePodsForReplicaSets(c clientset.Interface, deployment *extension
// CountAvailablePodsForReplicaSets returns the number of available pods corresponding to the given pod list and replica sets.
// Note that the input pod list should be the pods targeted by the deployment of input replica sets.
func CountAvailablePodsForReplicaSets(podList *api.PodList, rss []*extensions.ReplicaSet, minReadySeconds int32) (int32, error) {
rsPods, err := filterPodsMatchingReplicaSets(rss, podList, minReadySeconds)
rsPods, err := filterPodsMatchingReplicaSets(rss, podList)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -663,8 +663,8 @@ func IsPodAvailable(pod *api.Pod, minReadySeconds int32, now time.Time) bool {
}

// filterPodsMatchingReplicaSets filters the given pod list and only return the ones targeted by the input replicasets
func filterPodsMatchingReplicaSets(replicaSets []*extensions.ReplicaSet, podList *api.PodList, minReadySeconds int32) ([]api.Pod, error) {
allRSPods := []api.Pod{}
func filterPodsMatchingReplicaSets(replicaSets []*extensions.ReplicaSet, podList *api.PodList) ([]api.Pod, error) {
rsPods := []api.Pod{}
for _, rs := range replicaSets {
matchingFunc, err := rsutil.MatchingPodsFunc(rs)
if err != nil {
Expand All @@ -673,16 +673,9 @@ func filterPodsMatchingReplicaSets(replicaSets []*extensions.ReplicaSet, podList
if matchingFunc == nil {
continue
}
rsPods := podutil.Filter(podList, matchingFunc)
avaPodsCount := countAvailablePods(rsPods, minReadySeconds)
if avaPodsCount > rs.Spec.Replicas {
msg := fmt.Sprintf("Found %s/%s with %d available pods, more than its spec replicas %d", rs.Namespace, rs.Name, avaPodsCount, rs.Spec.Replicas)
glog.Errorf("ERROR: %s", msg)
return nil, fmt.Errorf(msg)
}
allRSPods = append(allRSPods, podutil.Filter(podList, matchingFunc)...)
rsPods = append(rsPods, podutil.Filter(podList, matchingFunc)...)
}
return allRSPods, nil
return rsPods, nil
}

// Revision returns the revision number of the input replica set
Expand Down