Skip to content
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

Merged
merged 2 commits into from
Jul 18, 2023
Merged

Fix defaulting of Replicas spec #228

merged 2 commits into from
Jul 18, 2023

Conversation

kajinamit
Copy link
Contributor

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.

@openshift-ci openshift-ci bot requested review from stuggi and viroel July 12, 2023 04:02
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.
Copy link
Contributor

@abays abays left a 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"`
Copy link
Contributor

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?

Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@ASBishop ASBishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 18, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit b145557 into openstack-k8s-operators:main Jul 18, 2023
2 checks passed
@kajinamit kajinamit deleted the replicas-type branch July 19, 2023 01:39
ASBishop pushed a commit to ASBishop/cinder-operator that referenced this pull request Mar 11, 2024
…lint-to-0.3.0

Bump operator-lint to 0.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants