From 702fe31221ef1732a12576936fd24800339c164b Mon Sep 17 00:00:00 2001 From: tanshanshan Date: Wed, 28 Dec 2016 09:48:52 +0800 Subject: [PATCH] fix checking empty --- staging/src/k8s.io/apimachinery/pkg/labels/selector.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/labels/selector.go b/staging/src/k8s.io/apimachinery/pkg/labels/selector.go index 501d018707c..8b35795817c 100644 --- a/staging/src/k8s.io/apimachinery/pkg/labels/selector.go +++ b/staging/src/k8s.io/apimachinery/pkg/labels/selector.go @@ -793,7 +793,7 @@ func validateLabelValue(v string) error { // SelectorFromSet returns a Selector which will match exactly the given Set. A // nil and empty Sets are considered equivalent to Everything(). func SelectorFromSet(ls Set) Selector { - if ls == nil { + if ls == nil || len(ls) == 0 { return internalSelector{} } var requirements internalSelector @@ -807,14 +807,14 @@ func SelectorFromSet(ls Set) Selector { } // sort to have deterministic string representation sort.Sort(ByKey(requirements)) - return internalSelector(requirements) + return 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 { + if ls == nil || len(ls) == 0 { return internalSelector{} } var requirements internalSelector @@ -823,7 +823,7 @@ func SelectorFromValidatedSet(ls Set) Selector { } // sort to have deterministic string representation sort.Sort(ByKey(requirements)) - return internalSelector(requirements) + return requirements } // ParseToRequirements takes a string representing a selector and returns a list of