Skip to content

Commit 6bc0768

Browse files
authored
Merge pull request kubernetes#127744 from carlory/fix-126662
Tighten validation on the qosClass field of pod status
2 parents 1890157 + 9cb7d58 commit 6bc0768

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

pkg/apis/core/validation/validation.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5382,6 +5382,9 @@ func ValidatePodStatusUpdate(newPod, oldPod *core.Pod, opts PodValidationOptions
53825382
}
53835383
}
53845384

5385+
// Pod QoS is immutable
5386+
allErrs = append(allErrs, ValidateImmutableField(newPod.Status.QOSClass, oldPod.Status.QOSClass, fldPath.Child("qosClass"))...)
5387+
53855388
// If pod should not restart, make sure the status update does not transition
53865389
// any terminated containers to a non-terminated state.
53875390
allErrs = append(allErrs, ValidateContainerStateTransition(newPod.Status.ContainerStatuses, oldPod.Status.ContainerStatuses, fldPath.Child("containerStatuses"), oldPod.Spec.RestartPolicy)...)

pkg/apis/core/validation/validation_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14454,6 +14454,32 @@ func TestValidatePodStatusUpdate(t *testing.T) {
1445414454
),
1445514455
"",
1445614456
"restartable init container can restart if RestartPolicyAlways",
14457+
}, {
14458+
*podtest.MakePod("foo",
14459+
podtest.SetStatus(core.PodStatus{
14460+
QOSClass: core.PodQOSBurstable,
14461+
}),
14462+
),
14463+
*podtest.MakePod("foo",
14464+
podtest.SetStatus(core.PodStatus{
14465+
QOSClass: core.PodQOSGuaranteed,
14466+
}),
14467+
),
14468+
"tatus.qosClass: Invalid value: \"Burstable\": field is immutable",
14469+
"qosClass can not be changed",
14470+
}, {
14471+
*podtest.MakePod("foo",
14472+
podtest.SetStatus(core.PodStatus{
14473+
QOSClass: core.PodQOSBurstable,
14474+
}),
14475+
),
14476+
*podtest.MakePod("foo",
14477+
podtest.SetStatus(core.PodStatus{
14478+
QOSClass: core.PodQOSBurstable,
14479+
}),
14480+
),
14481+
"",
14482+
"qosClass no change",
1445714483
},
1445814484
}
1445914485

pkg/registry/core/pod/strategy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ func (podStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
226226
// don't allow the pods/status endpoint to touch owner references since old kubelets corrupt them in a way
227227
// that breaks garbage collection
228228
newPod.OwnerReferences = oldPod.OwnerReferences
229+
// the Pod QoS is immutable and populated at creation time by the kube-apiserver.
230+
// we need to backfill it for backward compatibility because the old kubelet dropped this field when the pod was rejected.
231+
if newPod.Status.QOSClass == "" {
232+
newPod.Status.QOSClass = oldPod.Status.QOSClass
233+
}
229234
}
230235

231236
func (podStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {

0 commit comments

Comments
 (0)