Unverified Commit 249ecab7 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #59365 from ayushpateria/patch-sts

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix StatefulSet set-based selector bug **What this PR does / why we need it**: ControllerRevisions were using selectors as the labels, in case of set-based selectors, the helper function to convert selectors to labels would break. This PR uses pod labels for ControllerRevision labels instead of selectors. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #59266 **Special notes for your reviewer**: I'm trying to learn Kubernetes codebase and would be happy to make changes if anything is off. **Release note**: ```release-note Fix StatefulSet to work with set-based selectors. ```
parents 6546b699 a269491f
...@@ -56,19 +56,19 @@ func ControllerRevisionName(prefix string, hash uint32) string { ...@@ -56,19 +56,19 @@ func ControllerRevisionName(prefix string, hash uint32) string {
} }
// NewControllerRevision returns a ControllerRevision with a ControllerRef pointing to parent and indicating that // NewControllerRevision returns a ControllerRevision with a ControllerRef pointing to parent and indicating that
// parent is of parentKind. The ControllerRevision has labels matching selector, contains Data equal to data, and // parent is of parentKind. The ControllerRevision has labels matching template labels, contains Data equal to data, and
// has a Revision equal to revision. The collisionCount is used when creating the name of the ControllerRevision // has a Revision equal to revision. The collisionCount is used when creating the name of the ControllerRevision
// so the name is likely unique. If the returned error is nil, the returned ControllerRevision is valid. If the // so the name is likely unique. If the returned error is nil, the returned ControllerRevision is valid. If the
// returned error is not nil, the returned ControllerRevision is invalid for use. // returned error is not nil, the returned ControllerRevision is invalid for use.
func NewControllerRevision(parent metav1.Object, func NewControllerRevision(parent metav1.Object,
parentKind schema.GroupVersionKind, parentKind schema.GroupVersionKind,
selector labels.Selector, templateLabels map[string]string,
data runtime.RawExtension, data runtime.RawExtension,
revision int64, revision int64,
collisionCount *int32) (*apps.ControllerRevision, error) { collisionCount *int32) (*apps.ControllerRevision, error) {
labelMap, err := labels.ConvertSelectorToLabelsMap(selector.String()) labelMap := make(map[string]string)
if err != nil { for k, v := range templateLabels {
return nil, err labelMap[k] = v
} }
blockOwnerDeletion := true blockOwnerDeletion := true
isController := true isController := true
......
...@@ -312,13 +312,9 @@ func newRevision(set *apps.StatefulSet, revision int64, collisionCount *int32) ( ...@@ -312,13 +312,9 @@ func newRevision(set *apps.StatefulSet, revision int64, collisionCount *int32) (
if err != nil { if err != nil {
return nil, err return nil, err
} }
selector, err := metav1.LabelSelectorAsSelector(set.Spec.Selector)
if err != nil {
return nil, err
}
cr, err := history.NewControllerRevision(set, cr, err := history.NewControllerRevision(set,
controllerKind, controllerKind,
selector, set.Spec.Template.Labels,
runtime.RawExtension{Raw: patch}, runtime.RawExtension{Raw: patch},
revision, revision,
collisionCount) collisionCount)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment