mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
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:
commit
b6f966f8f5
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user