-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix defaulting of Replicas spec #228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -868,6 +868,7 @@ spec: | |
replicas: | ||
default: 1 | ||
format: int32 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,6 +842,7 @@ spec: | |
replicas: | ||
default: 1 | ||
format: int32 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,6 +842,7 @@ spec: | |
replicas: | ||
default: 1 | ||
format: int32 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -843,6 +843,7 @@ spec: | |
default: 1 | ||
format: int32 | ||
maximum: 1 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -868,6 +868,7 @@ spec: | |
replicas: | ||
default: 1 | ||
format: int32 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,6 +842,7 @@ spec: | |
replicas: | ||
default: 1 | ||
format: int32 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,6 +842,7 @@ spec: | |
replicas: | ||
default: 1 | ||
format: int32 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -843,6 +843,7 @@ spec: | |
default: 1 | ||
format: int32 | ||
maximum: 1 | ||
minimum: 0 | ||
type: integer | ||
resources: | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ func Deployment( | |
Selector: &metav1.LabelSelector{ | ||
MatchLabels: labels, | ||
}, | ||
Replicas: &instance.Spec.Replicas, | ||
Replicas: instance.Spec.Replicas, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part confuses me (even the original code). According to the StatefulSetSpec, the Replicas field is an int32 (not a pointer), so I don't know how we can mix pointers and pointer references. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For whatever reason, that documentation is not accurate. If you look at the code in an interactive IDE, the imported libraries for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thanks for explaining this as a doc error. You've saved me from an eternity of staring into the abyss. |
||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: annotations, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an old school C programmer in the distant past, I'm struggling to understand how this works. I gather the defaulting webhook will zero these fields, yielding the equivalent of a NULL pointer. Then the kubebuilder annotation will result in the replicas field being updated to point (because it's a pointer) to the default value, meaning the pointer is updated. Somehow kubebuilder knows how to set default values by reference AND by value (two different use cases).
Is my understanding anything close to correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the defaulting webhook sets the pointers to the zero-value of
nil
or if it just ignores them completely and thus they would remainnil
as they would presumably already be. But anyhow, then when they subsequently reach the kubebuilder logic, that logic indeed knows how to set the default value whether it's by reference or by value. So your understanding is correct.