Merge pull request #41163 from janetkuo/deployment-cleanup

Automatic merge from submit-queue (batch tested with PRs 41517, 41494, 41163)

Deployment: filter out old RSes that are deleted or with non-zero replicas before cleanup

Fixes #36379

cc @zmerlynn @yujuhong @kargakis @kubernetes/sig-apps-bugs
This commit is contained in:
Kubernetes Submit Queue
2017-02-16 21:16:05 -08:00
committed by GitHub
5 changed files with 89 additions and 10 deletions

View File

@@ -767,15 +767,23 @@ func IsPodActive(p *v1.Pod) bool {
// FilterActiveReplicaSets returns replica sets that have (or at least ought to have) pods.
func FilterActiveReplicaSets(replicaSets []*extensions.ReplicaSet) []*extensions.ReplicaSet {
active := []*extensions.ReplicaSet{}
for i := range replicaSets {
rs := replicaSets[i]
activeFilter := func(rs *extensions.ReplicaSet) bool {
return rs != nil && *(rs.Spec.Replicas) > 0
}
return FilterReplicaSets(replicaSets, activeFilter)
}
if rs != nil && *(rs.Spec.Replicas) > 0 {
active = append(active, replicaSets[i])
type filterRS func(rs *extensions.ReplicaSet) bool
// FilterReplicaSets returns replica sets that are filtered by filterFn (all returned ones should match filterFn).
func FilterReplicaSets(RSes []*extensions.ReplicaSet, filterFn filterRS) []*extensions.ReplicaSet {
var filtered []*extensions.ReplicaSet
for i := range RSes {
if filterFn(RSes[i]) {
filtered = append(filtered, RSes[i])
}
}
return active
return filtered
}
// PodKey returns a key unique to the given pod within a cluster.