mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Avoid unnecessary map allocation
This commit is contained in:
parent
40e1aa6b25
commit
422121f93a
@ -192,13 +192,12 @@ func NodeNameTriggerFunc(obj runtime.Object) []storage.MatchValue {
|
||||
// PodToSelectableFields returns a field set that represents the object
|
||||
// TODO: fields are not labels, and the validation rules for them do not apply.
|
||||
func PodToSelectableFields(pod *api.Pod) fields.Set {
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&pod.ObjectMeta, true)
|
||||
podSpecificFieldsSet := fields.Set{
|
||||
"spec.nodeName": pod.Spec.NodeName,
|
||||
"spec.restartPolicy": string(pod.Spec.RestartPolicy),
|
||||
"status.phase": string(pod.Status.Phase),
|
||||
}
|
||||
return generic.MergeFieldsSets(objectMetaFieldsSet, podSpecificFieldsSet)
|
||||
return generic.AddObjectMetaFieldsSet(podSpecificFieldsSet, &pod.ObjectMeta, true)
|
||||
}
|
||||
|
||||
// ResourceGetter is an interface for retrieving resources by ResourceLocation.
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
)
|
||||
|
||||
// ObjectMetaFieldsSet returns a fields that represents the ObjectMeta.
|
||||
// ObjectMetaFieldsSet returns a fields that represent the ObjectMeta.
|
||||
func ObjectMetaFieldsSet(objectMeta *api.ObjectMeta, hasNamespaceField bool) fields.Set {
|
||||
if !hasNamespaceField {
|
||||
return fields.Set{
|
||||
@ -34,6 +34,15 @@ func ObjectMetaFieldsSet(objectMeta *api.ObjectMeta, hasNamespaceField bool) fie
|
||||
}
|
||||
}
|
||||
|
||||
// AdObjectMetaField add fields that represent the ObjectMeta to source.
|
||||
func AddObjectMetaFieldsSet(source fields.Set, objectMeta *api.ObjectMeta, hasNamespaceField bool) fields.Set {
|
||||
source["metadata.name"] = objectMeta.Name
|
||||
if hasNamespaceField {
|
||||
source["metadata.namespace"] = objectMeta.Namespace
|
||||
}
|
||||
return source
|
||||
}
|
||||
|
||||
// MergeFieldsSets merges a fields'set from fragment into the source.
|
||||
func MergeFieldsSets(source fields.Set, fragment fields.Set) fields.Set {
|
||||
for k, value := range fragment {
|
||||
|
Loading…
Reference in New Issue
Block a user