mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
fix ambiguous comments of priorityClass update validation
This commit is contained in:
parent
3ffdfbe286
commit
ffe4ae23f3
@ -49,14 +49,15 @@ func ValidatePriorityClass(pc *scheduling.PriorityClass) field.ErrorList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ValidatePriorityClassUpdate tests if required fields in the PriorityClass are
|
// ValidatePriorityClassUpdate tests if required fields in the PriorityClass are
|
||||||
// set and are valid. PriorityClass does not allow updating Name, and Value.
|
// set and are valid. PriorityClass does not allow updating name, value, and preemptionPolicy.
|
||||||
func ValidatePriorityClassUpdate(pc, oldPc *scheduling.PriorityClass) field.ErrorList {
|
func ValidatePriorityClassUpdate(pc, oldPc *scheduling.PriorityClass) field.ErrorList {
|
||||||
|
// name is immutable and is checked by the ObjectMeta validator.
|
||||||
allErrs := apivalidation.ValidateObjectMetaUpdate(&pc.ObjectMeta, &oldPc.ObjectMeta, field.NewPath("metadata"))
|
allErrs := apivalidation.ValidateObjectMetaUpdate(&pc.ObjectMeta, &oldPc.ObjectMeta, field.NewPath("metadata"))
|
||||||
// Name is immutable and is checked by the ObjectMeta validator.
|
// value is immutable.
|
||||||
if pc.Value != oldPc.Value {
|
if pc.Value != oldPc.Value {
|
||||||
allErrs = append(allErrs, field.Forbidden(field.NewPath("Value"), "may not be changed in an update."))
|
allErrs = append(allErrs, field.Forbidden(field.NewPath("value"), "may not be changed in an update."))
|
||||||
}
|
}
|
||||||
// PreemptionPolicy is immutable and is checked by the ObjectMeta validator.
|
// preemptionPolicy is immutable.
|
||||||
allErrs = append(allErrs, apivalidation.ValidateImmutableField(pc.PreemptionPolicy, oldPc.PreemptionPolicy, field.NewPath("preemptionPolicy"))...)
|
allErrs = append(allErrs, apivalidation.ValidateImmutableField(pc.PreemptionPolicy, oldPc.PreemptionPolicy, field.NewPath("preemptionPolicy"))...)
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/core"
|
||||||
"k8s.io/kubernetes/pkg/apis/scheduling"
|
"k8s.io/kubernetes/pkg/apis/scheduling"
|
||||||
schedulingapiv1 "k8s.io/kubernetes/pkg/apis/scheduling/v1"
|
schedulingapiv1 "k8s.io/kubernetes/pkg/apis/scheduling/v1"
|
||||||
)
|
)
|
||||||
@ -81,29 +82,37 @@ func TestValidatePriorityClass(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestValidatePriorityClassUpdate(t *testing.T) {
|
func TestValidatePriorityClassUpdate(t *testing.T) {
|
||||||
|
preemptLowerPriority := core.PreemptLowerPriority
|
||||||
|
preemptNever := core.PreemptNever
|
||||||
|
|
||||||
old := scheduling.PriorityClass{
|
old := scheduling.PriorityClass{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "1"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "1"},
|
||||||
Value: 100,
|
Value: 100,
|
||||||
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
}
|
}
|
||||||
successCases := map[string]scheduling.PriorityClass{
|
successCases := map[string]scheduling.PriorityClass{
|
||||||
"no change": {
|
"no change": {
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
||||||
Value: 100,
|
Value: 100,
|
||||||
Description: "Used for the highest priority pods.",
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
|
Description: "Used for the highest priority pods.",
|
||||||
},
|
},
|
||||||
"change description": {
|
"change description": {
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
||||||
Value: 100,
|
Value: 100,
|
||||||
Description: "A different description.",
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
|
Description: "A different description.",
|
||||||
},
|
},
|
||||||
"remove description": {
|
"remove description": {
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
||||||
Value: 100,
|
Value: 100,
|
||||||
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
},
|
},
|
||||||
"change globalDefault": {
|
"change globalDefault": {
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
||||||
Value: 100,
|
Value: 100,
|
||||||
GlobalDefault: true,
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
|
GlobalDefault: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,31 +128,43 @@ func TestValidatePriorityClassUpdate(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
"add namespace": {
|
"add namespace": {
|
||||||
P: scheduling.PriorityClass{
|
P: scheduling.PriorityClass{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "foo", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "foo", ResourceVersion: "2"},
|
||||||
Value: 100,
|
Value: 100,
|
||||||
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
},
|
},
|
||||||
T: field.ErrorTypeInvalid,
|
T: field.ErrorTypeInvalid,
|
||||||
},
|
},
|
||||||
"change name": {
|
"change name": {
|
||||||
P: scheduling.PriorityClass{
|
P: scheduling.PriorityClass{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier2", Namespace: "", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier2", Namespace: "", ResourceVersion: "2"},
|
||||||
Value: 100,
|
Value: 100,
|
||||||
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
},
|
},
|
||||||
T: field.ErrorTypeInvalid,
|
T: field.ErrorTypeInvalid,
|
||||||
},
|
},
|
||||||
"remove value": {
|
"remove value": {
|
||||||
P: scheduling.PriorityClass{
|
P: scheduling.PriorityClass{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
||||||
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
},
|
},
|
||||||
T: field.ErrorTypeForbidden,
|
T: field.ErrorTypeForbidden,
|
||||||
},
|
},
|
||||||
"change value": {
|
"change value": {
|
||||||
P: scheduling.PriorityClass{
|
P: scheduling.PriorityClass{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
||||||
Value: 101,
|
Value: 101,
|
||||||
|
PreemptionPolicy: &preemptLowerPriority,
|
||||||
},
|
},
|
||||||
T: field.ErrorTypeForbidden,
|
T: field.ErrorTypeForbidden,
|
||||||
},
|
},
|
||||||
|
"change preemptionPolicy": {
|
||||||
|
P: scheduling.PriorityClass{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "2"},
|
||||||
|
Value: 100,
|
||||||
|
PreemptionPolicy: &preemptNever,
|
||||||
|
},
|
||||||
|
T: field.ErrorTypeInvalid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range errorCases {
|
for k, v := range errorCases {
|
||||||
|
Loading…
Reference in New Issue
Block a user