-
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
Fix defaulting of Replicas spec #228
Conversation
Currently the default values are ignored because these specs are set to 0 by webhook. Update the type from int32 to *int32 to avoid that behavior and ensure the expected default values are used. This also ensures Replicas spec takes values >= 0.
Now default container images are set by webhook, thus we don't have to set these image names explicitly.
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.
Tested this with install yamls
make cinder_kuttl
and it passed
+1 from me
// Replicas - Cinder API Replicas | ||
Replicas int32 `json:"replicas"` | ||
Replicas *int32 `json:"replicas"` |
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 gather the defaulting webhook will zero these fields
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 remain nil
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.
@@ -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 comment
The 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 comment
The 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 StatefulSet
, Deployment
, etc, have an *int32
as the data type for that field.
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.
Ah, thanks for explaining this as a doc error. You've saved me from an eternity of staring into the abyss.
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ASBishop, kajinamit The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
b145557
into
openstack-k8s-operators:main
…lint-to-0.3.0 Bump operator-lint to 0.3.0
Currently the default values are ignored because these specs are set to 0 by webhook. Update the type from
int32
to*int32
to avoid that behavior and ensure the expected default values are used.This also ensures Replicas spec takes values >= 0.