mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Add declarative default for RC.Spec.Replicas
Remove manual default: ``` $ git diff diff --git a/pkg/apis/core/v1/defaults.go b/pkg/apis/core/v1/defaults.go index e66de8bb432..1dd28dd35fb 100644 --- a/pkg/apis/core/v1/defaults.go +++ b/pkg/apis/core/v1/defaults.go @@ -60,10 +60,6 @@ func SetDefaults_ReplicationController(obj *v1.ReplicationController) { obj.Labels = labels } } - if obj.Spec.Replicas == nil { - obj.Spec.Replicas = new(int32) - *obj.Spec.Replicas = 1 - } } func SetDefaults_Volume(obj *v1.Volume) { if ptr.AllPtrFieldsNil(&obj.VolumeSource) { ``` The test fails: ``` $ go test ./pkg/apis/core/v1 | grep -v gate | grep -v SetEmulationVersion --- FAIL: TestSetDefaultReplicationControllerReplicas (0.00s) defaults_test.go:1608: expected: 1 replicas, got: 0 FAIL FAIL k8s.io/kubernetes/pkg/apis/core/v1 0.269s FAIL ``` Declare the default, update codegen and re-run the test: ``` $ git diff diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index 406ab56a002..7e5136fe9f6 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -5101,6 +5101,7 @@ type ReplicationControllerSpec struct { // Defaults to 1. // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller // +optional + // +default=1 // +k8s:minimum=0 Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"` $ ./hack/update-codegen.sh default +++ [1219 08:58:43] Generating defaulter code for 102 targets $ git diff diff --git a/pkg/apis/core/v1/zz_generated.defaults.go b/pkg/apis/core/v1/zz_generated.defaults.go index 3b6eb4f0a93..567c49053aa 100644 --- a/pkg/apis/core/v1/zz_generated.defaults.go +++ b/pkg/apis/core/v1/zz_generated.defaults.go @@ -878,6 +878,10 @@ func SetObjectDefaults_PodTemplateList(in *corev1.PodTemplateList) { func SetObjectDefaults_ReplicationController(in *corev1.ReplicationController) { SetDefaults_ReplicationController(in) + if in.Spec.Replicas == nil { + var ptrVar1 int32 = 1 + in.Spec.Replicas = &ptrVar1 + } if in.Spec.Template != nil { SetDefaults_PodSpec(&in.Spec.Template.Spec) for i := range in.Spec.Template.Spec.Volumes { $ go test ./pkg/apis/core/v1 | grep -v gate | grep -v SetEmulationVersion ok k8s.io/kubernetes/pkg/apis/core/v1 (cached) ```
This commit is contained in:
parent
e08bbf254c
commit
21b3da7e5a
1
api/openapi-spec/v3/api__v1_openapi.json
generated
1
api/openapi-spec/v3/api__v1_openapi.json
generated
@ -6528,6 +6528,7 @@
|
||||
"type": "integer"
|
||||
},
|
||||
"replicas": {
|
||||
"default": 1,
|
||||
"description": "Replicas is the number of desired replicas. This is a pointer to distinguish between explicit zero and unspecified. Defaults to 1. More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller",
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
|
@ -60,10 +60,7 @@ func SetDefaults_ReplicationController(obj *v1.ReplicationController) {
|
||||
obj.Labels = labels
|
||||
}
|
||||
}
|
||||
if obj.Spec.Replicas == nil {
|
||||
obj.Spec.Replicas = new(int32)
|
||||
*obj.Spec.Replicas = 1
|
||||
}
|
||||
// obj.Spec.Replicas is defaulted declaratively
|
||||
}
|
||||
func SetDefaults_Volume(obj *v1.Volume) {
|
||||
if ptr.AllPtrFieldsNil(&obj.VolumeSource) {
|
||||
|
4
pkg/apis/core/v1/zz_generated.defaults.go
generated
4
pkg/apis/core/v1/zz_generated.defaults.go
generated
@ -878,6 +878,10 @@ func SetObjectDefaults_PodTemplateList(in *corev1.PodTemplateList) {
|
||||
|
||||
func SetObjectDefaults_ReplicationController(in *corev1.ReplicationController) {
|
||||
SetDefaults_ReplicationController(in)
|
||||
if in.Spec.Replicas == nil {
|
||||
var ptrVar1 int32 = 1
|
||||
in.Spec.Replicas = &ptrVar1
|
||||
}
|
||||
if in.Spec.Template != nil {
|
||||
SetDefaults_PodSpec(&in.Spec.Template.Spec)
|
||||
for i := range in.Spec.Template.Spec.Volumes {
|
||||
|
1
pkg/generated/openapi/zz_generated.openapi.go
generated
1
pkg/generated/openapi/zz_generated.openapi.go
generated
@ -30098,6 +30098,7 @@ func schema_k8sio_api_core_v1_ReplicationControllerSpec(ref common.ReferenceCall
|
||||
"replicas": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Replicas is the number of desired replicas. This is a pointer to distinguish between explicit zero and unspecified. Defaults to 1. More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller",
|
||||
Default: 1,
|
||||
Type: []string{"integer"},
|
||||
Format: "int32",
|
||||
},
|
||||
|
@ -5085,6 +5085,7 @@ message ReplicationControllerSpec {
|
||||
// Defaults to 1.
|
||||
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
|
||||
// +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
|
||||
// +default=1
|
||||
// +k8s:minimum=0
|
||||
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
|
||||
|
||||
|
@ -7649,6 +7649,7 @@ var schemaYAML = typed.YAMLObject(`types:
|
||||
- name: replicas
|
||||
type:
|
||||
scalar: numeric
|
||||
default: 1
|
||||
- name: selector
|
||||
type:
|
||||
map:
|
||||
|
Loading…
Reference in New Issue
Block a user