Skip to content

Commit 431a4ed

Browse files
zhengjr9AiRanthem
authored andcommitted
bugfix: Filter rs that are not part of the current Deployement (openkruise#191)
Signed-off-by: zhengjr <zhengjiarui_pro@163.com> (cherry picked from commit 1e84129) Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com>
1 parent b72837d commit 431a4ed

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/controller/deployment/deployment_controller.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,22 @@ func (dc *DeploymentController) getReplicaSetsForDeployment(ctx context.Context,
8181
}
8282
// List all ReplicaSets to find those we own but that no longer match our
8383
// selector. They will be orphaned by ClaimReplicaSets().
84-
return dc.rsLister.ReplicaSets(d.Namespace).List(deploymentSelector)
84+
allRSs, err := dc.rsLister.ReplicaSets(d.Namespace).List(deploymentSelector)
85+
if err != nil {
86+
return nil, fmt.Errorf("list %s/%s rs failed:%v", d.Namespace, d.Name, err)
87+
}
88+
// select rs owner by current deployment
89+
ownedRSs := make([]*apps.ReplicaSet, 0)
90+
for _, rs := range allRSs {
91+
if !rs.DeletionTimestamp.IsZero() {
92+
continue
93+
}
94+
95+
if metav1.IsControlledBy(rs, d) {
96+
ownedRSs = append(ownedRSs, rs)
97+
}
98+
}
99+
return ownedRSs, nil
85100
}
86101

87102
// syncDeployment will sync the deployment with the given key.

0 commit comments

Comments
 (0)