From 8fda1c716b41b2756251b4800ead7e1f12669eb1 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 17 Mar 2017 00:32:07 -0400 Subject: [PATCH] Remove 'all namespaces' meaning of empty list in PodAffinityTerm --- pkg/api/types.go | 4 +--- pkg/api/v1/types.go | 6 ++---- .../scheduler/algorithm/priorities/util/topologies.go | 9 ++++----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index 40a2101987a..112aa847783 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -1886,9 +1886,7 @@ type PodAffinityTerm struct { // +optional LabelSelector *metav1.LabelSelector // namespaces specifies which namespaces the labelSelector applies to (matches against); - // nil list means "this pod's namespace," empty list means "all namespaces" - // The json tag here is not "omitempty" since we need to distinguish nil and empty. - // See https://golang.org/pkg/encoding/json/#Marshal for more details. + // null or empty list means "this pod's namespace" Namespaces []string // This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching // the labelSelector in the specified namespaces, where co-located is defined as running on a node diff --git a/pkg/api/v1/types.go b/pkg/api/v1/types.go index 86e508f57a0..e073e1074b7 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -2102,10 +2102,8 @@ type PodAffinityTerm struct { // +optional LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty" protobuf:"bytes,1,opt,name=labelSelector"` // namespaces specifies which namespaces the labelSelector applies to (matches against); - // nil list means "this pod's namespace," empty list means "all namespaces" - // The json tag here is not "omitempty" since we need to distinguish nil and empty. - // See https://golang.org/pkg/encoding/json/#Marshal for more details. - Namespaces []string `json:"namespaces" protobuf:"bytes,2,rep,name=namespaces"` + // null or empty list means "this pod's namespace" + Namespaces []string `json:"namespaces,omitempty" protobuf:"bytes,2,rep,name=namespaces"` // This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching // the labelSelector in the specified namespaces, where co-located is defined as running on a node // whose value of the label with key topologyKey matches that of any node on which any of the diff --git a/plugin/pkg/scheduler/algorithm/priorities/util/topologies.go b/plugin/pkg/scheduler/algorithm/priorities/util/topologies.go index 568e9253886..3615a7bc2f5 100644 --- a/plugin/pkg/scheduler/algorithm/priorities/util/topologies.go +++ b/plugin/pkg/scheduler/algorithm/priorities/util/topologies.go @@ -26,13 +26,12 @@ import ( // GetNamespacesFromPodAffinityTerm returns a set of names // according to the namespaces indicated in podAffinityTerm. -// 1. If the namespaces is nil considers the given pod's namespace -// 2. If the namespaces is empty list then considers all the namespaces +// If namespaces is empty it considers the given pod's namespace. func GetNamespacesFromPodAffinityTerm(pod *v1.Pod, podAffinityTerm *v1.PodAffinityTerm) sets.String { names := sets.String{} - if podAffinityTerm.Namespaces == nil { + if len(podAffinityTerm.Namespaces) == 0 { names.Insert(pod.Namespace) - } else if len(podAffinityTerm.Namespaces) != 0 { + } else { names.Insert(podAffinityTerm.Namespaces...) } return names @@ -41,7 +40,7 @@ func GetNamespacesFromPodAffinityTerm(pod *v1.Pod, podAffinityTerm *v1.PodAffini // PodMatchesTermsNamespaceAndSelector returns true if the given // matches the namespace and selector defined by `s . func PodMatchesTermsNamespaceAndSelector(pod *v1.Pod, namespaces sets.String, selector labels.Selector) bool { - if len(namespaces) != 0 && !namespaces.Has(pod.Namespace) { + if !namespaces.Has(pod.Namespace) { return false }