Skip to content

Commit

Permalink
Instead of adding our own label, reuse Statefulset selector
Browse files Browse the repository at this point in the history
This removes the need for the mostly redundant "name" label.

Signed-off-by: György Krajcsovits <[email protected]>
  • Loading branch information
krajorama committed Sep 5, 2022
1 parent f4b3ab0 commit e174379
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,16 @@ func (c *RolloutController) podsNotMatchingUpdateRevision(sts *v1.StatefulSet) (
return nil, errors.New("updateRevision is empty")
}

// Get any pods whose revision doesn't match the StatefulSet's updateRevision
// Create selector for all the pods selected by the Statefulset
podsSelector, err := metav1.LabelSelectorAsSelector(sts.Spec.Selector)
if err != nil {
panic(err)
}

// Filter pods whose revision doesn't match the StatefulSet's updateRevision
// and so it means they still need to be updated.
podsSelector := labels.NewSelector().Add(
podsSelector.Add(
mustNewLabelsRequirement(v1.ControllerRevisionHashLabelKey, selection.NotEquals, []string{updateRev}),
mustNewLabelsRequirement("name", selection.Equals, []string{sts.Spec.Template.Labels["name"]}),
)

pods, err := c.listPods(podsSelector)
Expand Down

0 comments on commit e174379

Please sign in to comment.