Merge pull request #27690 from resouer/fix-affinity

Automatic merge from submit-queue

Omit invalid affinity error in admission

Fixes #27645  cc @smarterclayton 

Not sure if this is too aggressive, but user should expect failure if they disable validation after all.
This commit is contained in:
k8s-merge-robot 2016-06-28 02:24:22 -07:00 committed by GitHub
commit b6f966f8f5
2 changed files with 13 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/api"
apierrors "k8s.io/kubernetes/pkg/api/errors"
@ -59,7 +60,8 @@ func (p *plugin) Admit(attributes admission.Attributes) (err error) {
}
affinity, err := api.GetAffinityFromPodAnnotations(pod.Annotations)
if err != nil {
return err
glog.V(5).Infof("Invalid Affinity detected, but we will leave handling of this to validation phase")
return nil
}
if affinity.PodAntiAffinity != nil {
var podAntiAffinityTerms []api.PodAffinityTerm

View File

@ -200,6 +200,16 @@ func TestInterPodAffinityAdmission(t *testing.T) {
},
errorExpected: true,
},
{
affinity: map[string]string{
api.AffinityAnnotationKey: `
{"podAntiAffinity": {
"thisIsAInvalidAffinity": [{}
}}`,
},
// however, we should not got error here
errorExpected: false,
},
}
for _, test := range tests {
pod.ObjectMeta.Annotations = test.affinity