Skip to content

Commit

Permalink
Include support for same namespace affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn committed Jan 26, 2022
1 parent b6157d6 commit d59991e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/controllers/selection/antiaffinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ type AntiAffinity struct{}
// Validate that the affinity terms are supported
func (a *AntiAffinity) Validate(pod *v1.Pod) (errs *apis.FieldError) {
for i, term := range a.termsFor(pod) {
errs = errs.Also(a.validateTerm(term).ViaIndex(i))
errs = errs.Also(a.validateTerm(pod, term).ViaIndex(i))
}
return errs
}

func (a *AntiAffinity) validateTerm(term v1.PodAffinityTerm) (errs *apis.FieldError) {
func (a *AntiAffinity) validateTerm(pod *v1.Pod, term v1.PodAffinityTerm) (errs *apis.FieldError) {
if term.NamespaceSelector != nil {
errs = errs.Also(apis.ErrDisallowedFields("namespaceSelector"))
}
if len(term.Namespaces) != 0 {
errs = errs.Also(apis.ErrDisallowedFields("namespaces"))
for i, namespace := range term.Namespaces {
if namespace != pod.Namespace {
errs = errs.Also(apis.ErrInvalidArrayValue(fmt.Sprintf("%s, cross namespace affinity is not supported", namespace), "namespaces", i))
}
}
if !AllowedAntiAffinityKeys.Has(term.TopologyKey) {
errs = errs.Also(apis.ErrInvalidKeyName(fmt.Sprintf("%s not in %v", term.TopologyKey, AllowedAntiAffinityKeys.UnsortedList()), "topologyKey"))
Expand Down

0 comments on commit d59991e

Please sign in to comment.