mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +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"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
"k8s.io/kubernetes/pkg/admission"
|
"k8s.io/kubernetes/pkg/admission"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
apierrors "k8s.io/kubernetes/pkg/api/errors"
|
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)
|
affinity, err := api.GetAffinityFromPodAnnotations(pod.Annotations)
|
||||||
if err != nil {
|
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 {
|
if affinity.PodAntiAffinity != nil {
|
||||||
var podAntiAffinityTerms []api.PodAffinityTerm
|
var podAntiAffinityTerms []api.PodAffinityTerm
|
||||||
|
@ -200,6 +200,16 @@ func TestInterPodAffinityAdmission(t *testing.T) {
|
|||||||
},
|
},
|
||||||
errorExpected: true,
|
errorExpected: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
affinity: map[string]string{
|
||||||
|
api.AffinityAnnotationKey: `
|
||||||
|
{"podAntiAffinity": {
|
||||||
|
"thisIsAInvalidAffinity": [{}
|
||||||
|
}}`,
|
||||||
|
},
|
||||||
|
// however, we should not got error here
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
pod.ObjectMeta.Annotations = test.affinity
|
pod.ObjectMeta.Annotations = test.affinity
|
||||||
|
Loading…
Reference in New Issue
Block a user