mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-01-27 18:19:28 +00:00
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)
```
Kubernetes's OpenAPI Specification
This folder contains an OpenAPI specification for Kubernetes API.
Vendor Extensions
Kubernetes extends OpenAPI using these extensions. Note the version that extensions have been added.
x-kubernetes-group-version-kind
Operations and Definitions may have x-kubernetes-group-version-kind if they
are associated with a kubernetes resource.
For example:
"paths": {
...
"/api/v1/namespaces/{namespace}/pods/{name}": {
...
"get": {
...
"x-kubernetes-group-version-kind": {
"group": "",
"version": "v1",
"kind": "Pod"
}
}
}
}
x-kubernetes-action
Operations and Definitions may have x-kubernetes-action if they
are associated with a kubernetes resource.
Action can be one of get, list, put, patch, post, delete, deletecollection, watch, watchlist, proxy, or connect.
For example:
"paths": {
...
"/api/v1/namespaces/{namespace}/pods/{name}": {
...
"get": {
...
"x-kubernetes-action": "list"
}
}
}
x-kubernetes-patch-strategy and x-kubernetes-patch-merge-key
Some of the definitions may have these extensions. For more information about PatchStrategy and PatchMergeKey see strategic-merge-patch.