mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-18 08:09:58 +00:00
Allow for selector creation without validation
This commit is contained in:
parent
e30c0b8dcd
commit
42aee3ac5e
@ -61,6 +61,15 @@ func (ls Set) AsSelector() Selector {
|
|||||||
return SelectorFromSet(ls)
|
return SelectorFromSet(ls)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidatedAsSelector converts labels into a selector, but
|
||||||
|
// assumes that labels are already validated and thus don't
|
||||||
|
// preform any validation.
|
||||||
|
// According to our measurements this is significantly faster
|
||||||
|
// in codepaths that matter at high sccale.
|
||||||
|
func (ls Set) AsSelectorPreValidated() Selector {
|
||||||
|
return SelectorFromValidatedSet(ls)
|
||||||
|
}
|
||||||
|
|
||||||
// FormatLables convert label map into plain string
|
// FormatLables convert label map into plain string
|
||||||
func FormatLabels(labelMap map[string]string) string {
|
func FormatLabels(labelMap map[string]string) string {
|
||||||
l := Set(labelMap).String()
|
l := Set(labelMap).String()
|
||||||
|
@ -796,6 +796,22 @@ func SelectorFromSet(ls Set) Selector {
|
|||||||
return internalSelector(requirements)
|
return internalSelector(requirements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SelectorFromValidatedSet returns a Selector which will match exactly the given Set.
|
||||||
|
// A nil and empty Sets are considered equivalent to Everything().
|
||||||
|
// It assumes that Set is already validated and doesn't do any validation.
|
||||||
|
func SelectorFromValidatedSet(ls Set) Selector {
|
||||||
|
if ls == nil {
|
||||||
|
return internalSelector{}
|
||||||
|
}
|
||||||
|
var requirements internalSelector
|
||||||
|
for label, value := range ls {
|
||||||
|
requirements = append(requirements, Requirement{key: label, operator: selection.Equals, strValues: sets.NewString(value)})
|
||||||
|
}
|
||||||
|
// sort to have deterministic string representation
|
||||||
|
sort.Sort(ByKey(requirements))
|
||||||
|
return internalSelector(requirements)
|
||||||
|
}
|
||||||
|
|
||||||
// ParseToRequirements takes a string representing a selector and returns a list of
|
// ParseToRequirements takes a string representing a selector and returns a list of
|
||||||
// requirements. This function is suitable for those callers that perform additional
|
// requirements. This function is suitable for those callers that perform additional
|
||||||
// processing on selector requirements.
|
// processing on selector requirements.
|
||||||
|
Loading…
Reference in New Issue
Block a user