mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Declaratively validate RC.Spec.Replicas optionality
The existing test run both declarative and manual validation and it still passes.
This commit is contained in:
parent
21b3da7e5a
commit
0f4786536f
5
pkg/apis/core/v1/zz_generated.validations.go
generated
5
pkg/apis/core/v1/zz_generated.validations.go
generated
@ -89,6 +89,11 @@ func Validate_ReplicationControllerSpec(ctx context.Context, op operation.Operat
|
||||
// field corev1.ReplicationControllerSpec.Replicas
|
||||
errs = append(errs,
|
||||
func(fldPath *field.Path, obj, oldObj *int32) (errs field.ErrorList) {
|
||||
// optional fields with default values are effectively required
|
||||
if e := validate.RequiredPointer(ctx, op, fldPath, obj, oldObj); len(e) != 0 {
|
||||
errs = append(errs, e...)
|
||||
return // do not proceed
|
||||
}
|
||||
errs = append(errs, validate.Minimum(ctx, op, fldPath, obj, oldObj, 0)...)
|
||||
return
|
||||
}(fldPath.Child("replicas"), obj.Replicas, safe.Field(oldObj, func(oldObj *corev1.ReplicationControllerSpec) *int32 { return oldObj.Replicas }))...)
|
||||
|
@ -6322,7 +6322,7 @@ func ValidateReplicationControllerSpec(spec, oldSpec *core.ReplicationController
|
||||
allErrs = append(allErrs, ValidateNonnegativeField(int64(spec.MinReadySeconds), fldPath.Child("minReadySeconds"))...)
|
||||
allErrs = append(allErrs, ValidateNonEmptySelector(spec.Selector, fldPath.Child("selector"))...)
|
||||
if spec.Replicas == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("replicas"), ""))
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("replicas"), "").MarkCoveredByDeclarative())
|
||||
} else {
|
||||
allErrs = append(allErrs, ValidateNonnegativeField(int64(*spec.Replicas), fldPath.Child("replicas")).MarkCoveredByDeclarative()...)
|
||||
}
|
||||
|
@ -5085,6 +5085,7 @@ message ReplicationControllerSpec {
|
||||
// Defaults to 1.
|
||||
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
|
||||
// +optional
|
||||
// +k8s:optional
|
||||
// +default=1
|
||||
// +k8s:minimum=0
|
||||
optional int32 replicas = 1;
|
||||
|
@ -5107,6 +5107,7 @@ type ReplicationControllerSpec struct {
|
||||
// Defaults to 1.
|
||||
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
|
||||
// +optional
|
||||
// +k8s:optional
|
||||
// +default=1
|
||||
// +k8s:minimum=0
|
||||
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
|
||||
|
Loading…
Reference in New Issue
Block a user