mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
Fix StatefulSet set selector bug
This commit is contained in:
parent
d8928efc8a
commit
8de89d9f74
@ -18,6 +18,7 @@ package history
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"sort"
|
||||
@ -56,7 +57,7 @@ func ControllerRevisionName(prefix string, hash uint32) string {
|
||||
}
|
||||
|
||||
// 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 pod, contains Data equal to data, and
|
||||
// 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
|
||||
// returned error is not nil, the returned ControllerRevision is invalid for use.
|
||||
@ -66,10 +67,7 @@ func NewControllerRevision(parent metav1.Object,
|
||||
data runtime.RawExtension,
|
||||
revision int64,
|
||||
collisionCount *int32) (*apps.ControllerRevision, error) {
|
||||
labelMap, err := labels.ConvertSelectorToLabelsMap(selector.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
labelMap := getPodLabelsFromData(data)
|
||||
blockOwnerDeletion := true
|
||||
isController := true
|
||||
cr := &apps.ControllerRevision{
|
||||
@ -454,3 +452,31 @@ func (fh *fakeHistory) ReleaseControllerRevision(parent metav1.Object, revision
|
||||
}
|
||||
return clone, fh.indexer.Update(clone)
|
||||
}
|
||||
|
||||
func getPodLabelsFromData(data runtime.RawExtension) map[string]string {
|
||||
var dat map[string]interface{}
|
||||
labelMap := make(map[string]string)
|
||||
if err := json.Unmarshal(data.Raw, &dat); err != nil {
|
||||
return labelMap
|
||||
}
|
||||
spec, ok := dat["spec"].(map[string]interface{})
|
||||
if !ok {
|
||||
return labelMap
|
||||
}
|
||||
template, ok := spec["template"].(map[string]interface{})
|
||||
if !ok {
|
||||
return labelMap
|
||||
}
|
||||
metadata, ok := template["metadata"].(map[string]interface{})
|
||||
if !ok {
|
||||
return labelMap
|
||||
}
|
||||
labels, ok := metadata["labels"].(map[string]interface{})
|
||||
if !ok {
|
||||
return labelMap
|
||||
}
|
||||
for key, value := range labels {
|
||||
labelMap[key] = value.(string)
|
||||
}
|
||||
return labelMap
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user