mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-02-13 15:59:57 -05:00
feat(dra): add k8s:maxLength on NetworkData.InterfaceName
This commit is contained in:
parent
2b4495f66a
commit
6fa8cb4a99
11 changed files with 75 additions and 3 deletions
22
pkg/apis/resource/v1/zz_generated.validations.go
generated
22
pkg/apis/resource/v1/zz_generated.validations.go
generated
|
|
@ -152,6 +152,8 @@ func Validate_AllocatedDeviceStatus(ctx context.Context, op operation.Operation,
|
|||
if earlyReturn {
|
||||
return // do not proceed
|
||||
}
|
||||
// call the type's validation function
|
||||
errs = append(errs, Validate_NetworkDeviceData(ctx, op, fldPath, obj, oldObj)...)
|
||||
return
|
||||
}(fldPath.Child("networkData"), obj.NetworkData, safe.Field(oldObj, func(oldObj *resourcev1.AllocatedDeviceStatus) *resourcev1.NetworkDeviceData {
|
||||
return oldObj.NetworkData
|
||||
|
|
@ -1042,6 +1044,26 @@ func Validate_ExactDeviceRequest(ctx context.Context, op operation.Operation, fl
|
|||
return errs
|
||||
}
|
||||
|
||||
// Validate_NetworkDeviceData validates an instance of NetworkDeviceData according
|
||||
// to declarative validation rules in the API schema.
|
||||
func Validate_NetworkDeviceData(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *resourcev1.NetworkDeviceData) (errs field.ErrorList) {
|
||||
// field resourcev1.NetworkDeviceData.InterfaceName
|
||||
errs = append(errs,
|
||||
func(fldPath *field.Path, obj, oldObj *string) (errs field.ErrorList) {
|
||||
// don't revalidate unchanged data
|
||||
if op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
|
||||
return nil
|
||||
}
|
||||
// call field-attached validations
|
||||
errs = append(errs, validate.MaxLength(ctx, op, fldPath, obj, oldObj, 256)...)
|
||||
return
|
||||
}(fldPath.Child("interfaceName"), &obj.InterfaceName, safe.Field(oldObj, func(oldObj *resourcev1.NetworkDeviceData) *string { return &oldObj.InterfaceName }))...)
|
||||
|
||||
// field resourcev1.NetworkDeviceData.IPs has no validation
|
||||
// field resourcev1.NetworkDeviceData.HardwareAddress has no validation
|
||||
return errs
|
||||
}
|
||||
|
||||
// Validate_OpaqueDeviceConfiguration validates an instance of OpaqueDeviceConfiguration according
|
||||
// to declarative validation rules in the API schema.
|
||||
func Validate_OpaqueDeviceConfiguration(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *resourcev1.OpaqueDeviceConfiguration) (errs field.ErrorList) {
|
||||
|
|
|
|||
|
|
@ -152,6 +152,8 @@ func Validate_AllocatedDeviceStatus(ctx context.Context, op operation.Operation,
|
|||
if earlyReturn {
|
||||
return // do not proceed
|
||||
}
|
||||
// call the type's validation function
|
||||
errs = append(errs, Validate_NetworkDeviceData(ctx, op, fldPath, obj, oldObj)...)
|
||||
return
|
||||
}(fldPath.Child("networkData"), obj.NetworkData, safe.Field(oldObj, func(oldObj *resourcev1beta1.AllocatedDeviceStatus) *resourcev1beta1.NetworkDeviceData {
|
||||
return oldObj.NetworkData
|
||||
|
|
@ -1067,6 +1069,26 @@ func Validate_DeviceTolerationOperator(ctx context.Context, op operation.Operati
|
|||
return errs
|
||||
}
|
||||
|
||||
// Validate_NetworkDeviceData validates an instance of NetworkDeviceData according
|
||||
// to declarative validation rules in the API schema.
|
||||
func Validate_NetworkDeviceData(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *resourcev1beta1.NetworkDeviceData) (errs field.ErrorList) {
|
||||
// field resourcev1beta1.NetworkDeviceData.InterfaceName
|
||||
errs = append(errs,
|
||||
func(fldPath *field.Path, obj, oldObj *string) (errs field.ErrorList) {
|
||||
// don't revalidate unchanged data
|
||||
if op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
|
||||
return nil
|
||||
}
|
||||
// call field-attached validations
|
||||
errs = append(errs, validate.MaxLength(ctx, op, fldPath, obj, oldObj, 256)...)
|
||||
return
|
||||
}(fldPath.Child("interfaceName"), &obj.InterfaceName, safe.Field(oldObj, func(oldObj *resourcev1beta1.NetworkDeviceData) *string { return &oldObj.InterfaceName }))...)
|
||||
|
||||
// field resourcev1beta1.NetworkDeviceData.IPs has no validation
|
||||
// field resourcev1beta1.NetworkDeviceData.HardwareAddress has no validation
|
||||
return errs
|
||||
}
|
||||
|
||||
// Validate_OpaqueDeviceConfiguration validates an instance of OpaqueDeviceConfiguration according
|
||||
// to declarative validation rules in the API schema.
|
||||
func Validate_OpaqueDeviceConfiguration(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *resourcev1beta1.OpaqueDeviceConfiguration) (errs field.ErrorList) {
|
||||
|
|
|
|||
|
|
@ -152,6 +152,8 @@ func Validate_AllocatedDeviceStatus(ctx context.Context, op operation.Operation,
|
|||
if earlyReturn {
|
||||
return // do not proceed
|
||||
}
|
||||
// call the type's validation function
|
||||
errs = append(errs, Validate_NetworkDeviceData(ctx, op, fldPath, obj, oldObj)...)
|
||||
return
|
||||
}(fldPath.Child("networkData"), obj.NetworkData, safe.Field(oldObj, func(oldObj *resourcev1beta2.AllocatedDeviceStatus) *resourcev1beta2.NetworkDeviceData {
|
||||
return oldObj.NetworkData
|
||||
|
|
@ -1068,6 +1070,26 @@ func Validate_ExactDeviceRequest(ctx context.Context, op operation.Operation, fl
|
|||
return errs
|
||||
}
|
||||
|
||||
// Validate_NetworkDeviceData validates an instance of NetworkDeviceData according
|
||||
// to declarative validation rules in the API schema.
|
||||
func Validate_NetworkDeviceData(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *resourcev1beta2.NetworkDeviceData) (errs field.ErrorList) {
|
||||
// field resourcev1beta2.NetworkDeviceData.InterfaceName
|
||||
errs = append(errs,
|
||||
func(fldPath *field.Path, obj, oldObj *string) (errs field.ErrorList) {
|
||||
// don't revalidate unchanged data
|
||||
if op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
|
||||
return nil
|
||||
}
|
||||
// call field-attached validations
|
||||
errs = append(errs, validate.MaxLength(ctx, op, fldPath, obj, oldObj, 256)...)
|
||||
return
|
||||
}(fldPath.Child("interfaceName"), &obj.InterfaceName, safe.Field(oldObj, func(oldObj *resourcev1beta2.NetworkDeviceData) *string { return &oldObj.InterfaceName }))...)
|
||||
|
||||
// field resourcev1beta2.NetworkDeviceData.IPs has no validation
|
||||
// field resourcev1beta2.NetworkDeviceData.HardwareAddress has no validation
|
||||
return errs
|
||||
}
|
||||
|
||||
// Validate_OpaqueDeviceConfiguration validates an instance of OpaqueDeviceConfiguration according
|
||||
// to declarative validation rules in the API schema.
|
||||
func Validate_OpaqueDeviceConfiguration(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *resourcev1beta2.OpaqueDeviceConfiguration) (errs field.ErrorList) {
|
||||
|
|
|
|||
|
|
@ -1279,7 +1279,7 @@ func validateNetworkDeviceData(networkDeviceData *resource.NetworkDeviceData, fl
|
|||
}
|
||||
|
||||
if len(networkDeviceData.InterfaceName) > resource.NetworkDeviceDataInterfaceNameMaxLength {
|
||||
allErrs = append(allErrs, field.TooLong(fldPath.Child("interfaceName"), "" /* unused */, resource.NetworkDeviceDataInterfaceNameMaxLength))
|
||||
allErrs = append(allErrs, field.TooLong(fldPath.Child("interfaceName"), "" /* unused */, resource.NetworkDeviceDataInterfaceNameMaxLength).WithOrigin("maxLength").MarkCoveredByDeclarative())
|
||||
}
|
||||
|
||||
if len(networkDeviceData.HardwareAddress) > resource.NetworkDeviceDataHardwareAddressMaxLength {
|
||||
|
|
|
|||
|
|
@ -1398,7 +1398,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
|||
},
|
||||
"invalid-network-device-status": {
|
||||
wantFailures: field.ErrorList{
|
||||
field.TooLong(field.NewPath("status", "devices").Index(0).Child("networkData", "interfaceName"), "", resource.NetworkDeviceDataInterfaceNameMaxLength),
|
||||
field.TooLong(field.NewPath("status", "devices").Index(0).Child("networkData", "interfaceName"), "", resource.NetworkDeviceDataInterfaceNameMaxLength).MarkCoveredByDeclarative(),
|
||||
field.TooLong(field.NewPath("status", "devices").Index(0).Child("networkData", "hardwareAddress"), "", resource.NetworkDeviceDataHardwareAddressMaxLength),
|
||||
field.Invalid(field.NewPath("status", "devices").Index(0).Child("networkData", "ips").Index(0), "300.9.8.0/24", "must be a valid address in CIDR form, (e.g. 10.9.8.7/24 or 2001:db8::1/64)"),
|
||||
field.Invalid(field.NewPath("status", "devices").Index(0).Child("networkData", "ips").Index(1), "010.009.008.000/24", "must be in canonical form (\"10.9.8.0/24\")"),
|
||||
|
|
@ -1561,7 +1561,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
|||
},
|
||||
"invalid-network-device-status-disabled-feature-gate": {
|
||||
wantFailures: field.ErrorList{
|
||||
field.TooLong(field.NewPath("status", "devices").Index(0).Child("networkData", "interfaceName"), "", resource.NetworkDeviceDataInterfaceNameMaxLength),
|
||||
field.TooLong(field.NewPath("status", "devices").Index(0).Child("networkData", "interfaceName"), "", resource.NetworkDeviceDataInterfaceNameMaxLength).MarkCoveredByDeclarative(),
|
||||
field.TooLong(field.NewPath("status", "devices").Index(0).Child("networkData", "hardwareAddress"), "", resource.NetworkDeviceDataHardwareAddressMaxLength),
|
||||
field.Invalid(field.NewPath("status", "devices").Index(0).Child("networkData", "ips").Index(0), "300.9.8.0/24", "must be a valid address in CIDR form, (e.g. 10.9.8.7/24 or 2001:db8::1/64)"),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1266,6 +1266,7 @@ message NetworkDeviceData {
|
|||
// Must not be longer than 256 characters.
|
||||
//
|
||||
// +optional
|
||||
// +k8s:maxLength=256
|
||||
optional string interfaceName = 1;
|
||||
|
||||
// IPs lists the network addresses assigned to the device's network interface.
|
||||
|
|
|
|||
|
|
@ -1920,6 +1920,7 @@ type NetworkDeviceData struct {
|
|||
// Must not be longer than 256 characters.
|
||||
//
|
||||
// +optional
|
||||
// +k8s:maxLength=256
|
||||
InterfaceName string `json:"interfaceName,omitempty" protobuf:"bytes,1,opt,name=interfaceName"`
|
||||
|
||||
// IPs lists the network addresses assigned to the device's network interface.
|
||||
|
|
|
|||
|
|
@ -1278,6 +1278,7 @@ message NetworkDeviceData {
|
|||
// Must not be longer than 256 characters.
|
||||
//
|
||||
// +optional
|
||||
// +k8s:maxLength=256
|
||||
optional string interfaceName = 1;
|
||||
|
||||
// IPs lists the network addresses assigned to the device's network interface.
|
||||
|
|
|
|||
|
|
@ -1928,6 +1928,7 @@ type NetworkDeviceData struct {
|
|||
// Must not be longer than 256 characters.
|
||||
//
|
||||
// +optional
|
||||
// +k8s:maxLength=256
|
||||
InterfaceName string `json:"interfaceName,omitempty" protobuf:"bytes,1,opt,name=interfaceName"`
|
||||
|
||||
// IPs lists the network addresses assigned to the device's network interface.
|
||||
|
|
|
|||
|
|
@ -1266,6 +1266,7 @@ message NetworkDeviceData {
|
|||
// Must not be longer than 256 characters.
|
||||
//
|
||||
// +optional
|
||||
// +k8s:maxLength=256
|
||||
optional string interfaceName = 1;
|
||||
|
||||
// IPs lists the network addresses assigned to the device's network interface.
|
||||
|
|
|
|||
|
|
@ -1920,6 +1920,7 @@ type NetworkDeviceData struct {
|
|||
// Must not be longer than 256 characters.
|
||||
//
|
||||
// +optional
|
||||
// +k8s:maxLength=256
|
||||
InterfaceName string `json:"interfaceName,omitempty" protobuf:"bytes,1,opt,name=interfaceName"`
|
||||
|
||||
// IPs lists the network addresses assigned to the device's network interface.
|
||||
|
|
|
|||
Loading…
Reference in a new issue