mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Add declarative validation tests for EndpointSlice addressType immutability
This commit is contained in:
@@ -101,6 +101,10 @@ func Validate_EndpointSlice(ctx context.Context, op operation.Operation, fldPath
|
||||
}
|
||||
// call field-attached validations
|
||||
earlyReturn := false
|
||||
if e := validate.Immutable(ctx, op, fldPath, obj, oldObj); len(e) != 0 {
|
||||
errs = append(errs, e...)
|
||||
earlyReturn = true
|
||||
}
|
||||
if e := validate.RequiredValue(ctx, op, fldPath, obj, oldObj); len(e) != 0 {
|
||||
errs = append(errs, e...)
|
||||
earlyReturn = true
|
||||
|
||||
@@ -100,6 +100,10 @@ func Validate_EndpointSlice(ctx context.Context, op operation.Operation, fldPath
|
||||
}
|
||||
// call field-attached validations
|
||||
earlyReturn := false
|
||||
if e := validate.Immutable(ctx, op, fldPath, obj, oldObj); len(e) != 0 {
|
||||
errs = append(errs, e...)
|
||||
earlyReturn = true
|
||||
}
|
||||
if e := validate.RequiredValue(ctx, op, fldPath, obj, oldObj); len(e) != 0 {
|
||||
errs = append(errs, e...)
|
||||
earlyReturn = true
|
||||
|
||||
@@ -86,7 +86,7 @@ func ValidateEndpointSliceCreate(endpointSlice *discovery.EndpointSlice) field.E
|
||||
// ValidateEndpointSliceUpdate validates an EndpointSlice when it is updated.
|
||||
func ValidateEndpointSliceUpdate(newEndpointSlice, oldEndpointSlice *discovery.EndpointSlice) field.ErrorList {
|
||||
allErrs := ValidateEndpointSlice(newEndpointSlice, oldEndpointSlice)
|
||||
allErrs = append(allErrs, apivalidation.ValidateImmutableField(newEndpointSlice.AddressType, oldEndpointSlice.AddressType, field.NewPath("addressType"))...)
|
||||
allErrs = append(allErrs, apivalidation.ValidateImmutableField(newEndpointSlice.AddressType, oldEndpointSlice.AddressType, field.NewPath("addressType")).WithOrigin("immutable").MarkCoveredByDeclarative()...)
|
||||
|
||||
return allErrs
|
||||
}
|
||||
|
||||
@@ -122,6 +122,13 @@ func testDeclarativeValidateUpdate(t *testing.T, apiVersion string) {
|
||||
field.TooMany(field.NewPath("endpoints").Index(0).Child("addresses"), 101, 100).WithOrigin("maxItems"),
|
||||
},
|
||||
},
|
||||
"invalid update addressType immutable": {
|
||||
oldObj: mkValidEndpointSlice(),
|
||||
updateObj: mkValidEndpointSlice(tweakAddressType(discovery.AddressTypeIPv6)),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("addressType"), discovery.AddressTypeIPv6, "field is immutable").WithOrigin("immutable"),
|
||||
},
|
||||
},
|
||||
}
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
@@ -186,6 +186,7 @@ message EndpointSlice {
|
||||
// the "FQDN" type.
|
||||
// +required
|
||||
// +k8s:required
|
||||
// +k8s:immutable
|
||||
optional string addressType = 4;
|
||||
|
||||
// endpoints is a list of unique endpoints in this slice. Each slice may
|
||||
|
||||
@@ -50,6 +50,7 @@ type EndpointSlice struct {
|
||||
// the "FQDN" type.
|
||||
// +required
|
||||
// +k8s:required
|
||||
// +k8s:immutable
|
||||
AddressType AddressType `json:"addressType" protobuf:"bytes,4,rep,name=addressType"`
|
||||
|
||||
// endpoints is a list of unique endpoints in this slice. Each slice may
|
||||
|
||||
@@ -172,6 +172,7 @@ message EndpointSlice {
|
||||
// * FQDN: Represents a Fully Qualified Domain Name.
|
||||
// +required
|
||||
// +k8s:required
|
||||
// +k8s:immutable
|
||||
optional string addressType = 4;
|
||||
|
||||
// endpoints is a list of unique endpoints in this slice. Each slice may
|
||||
|
||||
@@ -47,6 +47,7 @@ type EndpointSlice struct {
|
||||
// * FQDN: Represents a Fully Qualified Domain Name.
|
||||
// +required
|
||||
// +k8s:required
|
||||
// +k8s:immutable
|
||||
AddressType AddressType `json:"addressType" protobuf:"bytes,4,rep,name=addressType"`
|
||||
|
||||
// endpoints is a list of unique endpoints in this slice. Each slice may
|
||||
|
||||
Reference in New Issue
Block a user