From e1743794299792cb2b3a4fca7f5b20af76a5cb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Mon, 5 Sep 2022 13:22:05 +0200 Subject: [PATCH] Instead of adding our own label, reuse Statefulset selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes the need for the mostly redundant "name" label. Signed-off-by: György Krajcsovits --- pkg/controller/controller.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index c6f5fb0d3..a49b27a87 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -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)