Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 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
6 changes: 6 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ func TestRolloutController_ReconcileShouldDeleteMetricsForDecommissionedRolloutG
}

func mockStatefulSet(name string, overrides ...func(sts *v1.StatefulSet)) *v1.StatefulSet {
labelSelector := metav1.LabelSelector{
MatchLabels: map[string]string{
"name": name,
},
};
sts := &v1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -387,6 +392,7 @@ func mockStatefulSet(name string, overrides ...func(sts *v1.StatefulSet)) *v1.St
},
},
},
Selector: &labelSelector,
},
Status: v1.StatefulSetStatus{
Replicas: 3,
Expand Down