Skip to content

Commit

Permalink
bugfix: Filter rs that are not part of the current Deployement
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengjr9 committed Dec 25, 2023
1 parent 8620408 commit df5d596
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/controller/deployment/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,22 @@ func (dc *DeploymentController) getReplicaSetsForDeployment(ctx context.Context,
}
// List all ReplicaSets to find those we own but that no longer match our
// selector. They will be orphaned by ClaimReplicaSets().
return dc.rsLister.ReplicaSets(d.Namespace).List(deploymentSelector)
allRSs, err := dc.rsLister.ReplicaSets(d.Namespace).List(deploymentSelector)
if err != nil {
return nil, fmt.Errorf("list %s/%s rs failed:%v", d.Namespace, d.Name, err)
}
// select rs owner by current deployment
ownedRSs := make([]*apps.ReplicaSet, 0)
for _, rs := range allRSs {
if rs.DeletionTimestamp.IsZero() {
continue
}

if metav1.IsControlledBy(rs, d) {
ownedRSs = append(ownedRSs, rs)
}
}
return ownedRSs, nil
}

// syncDeployment will sync the deployment with the given key.
Expand All @@ -101,7 +116,7 @@ func (dc *DeploymentController) syncDeployment(ctx context.Context, deployment *
if reflect.DeepEqual(d.Spec.Selector, &everything) {
dc.eventRecorder.Eventf(d, v1.EventTypeWarning, "SelectingAll", "This deployment is selecting all pods. A non-empty selector is required.")
if d.Status.ObservedGeneration < d.Generation {
d.Status.ObservedGeneration = d.Generation
d.Status.ObservedGene7ration = d.Generation

Check failure on line 119 in pkg/controller/deployment/deployment_controller.go

View workflow job for this annotation

GitHub Actions / unit-tests

d.Status.ObservedGene7ration undefined (type "k8s.io/api/apps/v1".DeploymentStatus has no field or method ObservedGene7ration)
dc.client.AppsV1().Deployments(d.Namespace).UpdateStatus(ctx, d, metav1.UpdateOptions{})
}
return nil
Expand Down

0 comments on commit df5d596

Please sign in to comment.