kube-scheduler: compatibility with ServerSideApply

avoid moving Pods that have been assumed back to the scheduling queue in
case they have annotations modified with ServerSideApply, which causes
Pod.ObjectMeta.ManagedFields to be modified automatically
This commit is contained in:
Fabio Kung 2020-04-22 12:02:40 -07:00
parent b19de7f9b6
commit d341a5b9d3
2 changed files with 82 additions and 0 deletions

View File

@ -335,6 +335,9 @@ func (sched *Scheduler) skipPodUpdate(pod *v1.Pod) bool {
// Annotations must be excluded for the reasons described in
// https://github.com/kubernetes/kubernetes/issues/52914.
p.Annotations = nil
// Same as above, when annotations are modified with ServerSideApply,
// ManagedFields may also change and must be excluded
p.ManagedFields = nil
return p
}
assumedPodCopy, podCopy := f(assumedPod), f(pod)

View File

@ -80,6 +80,85 @@ func TestSkipPodUpdate(t *testing.T) {
},
expected: true,
},
{
name: "with ServerSideApply changes on Annotations",
pod: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-0",
Annotations: map[string]string{"a": "b"},
ResourceVersion: "0",
ManagedFields: []metav1.ManagedFieldsEntry{
{
Manager: "some-actor",
Operation: metav1.ManagedFieldsOperationApply,
APIVersion: "v1",
FieldsType: "FieldsV1",
FieldsV1: &metav1.FieldsV1{
Raw: []byte(`
"f:metadata": {
"f:annotations": {
"f:a: {}
}
}
`),
},
},
},
},
Spec: v1.PodSpec{
NodeName: "node-0",
},
},
isAssumedPodFunc: func(*v1.Pod) bool {
return true
},
getPodFunc: func(*v1.Pod) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-0",
Annotations: map[string]string{"a": "c", "d": "e"},
ResourceVersion: "1",
ManagedFields: []metav1.ManagedFieldsEntry{
{
Manager: "some-actor",
Operation: metav1.ManagedFieldsOperationApply,
APIVersion: "v1",
FieldsType: "FieldsV1",
FieldsV1: &metav1.FieldsV1{
Raw: []byte(`
"f:metadata": {
"f:annotations": {
"f:a: {}
"f:d: {}
}
}
`),
},
},
{
Manager: "some-actor",
Operation: metav1.ManagedFieldsOperationApply,
APIVersion: "v1",
FieldsType: "FieldsV1",
FieldsV1: &metav1.FieldsV1{
Raw: []byte(`
"f:metadata": {
"f:annotations": {
"f:a: {}
}
}
`),
},
},
},
},
Spec: v1.PodSpec{
NodeName: "node-1",
},
}
},
expected: true,
},
{
name: "with changes on Labels",
pod: &v1.Pod{