Skip to content

⚠️ Stop using deprecated replica counters in controllers #12149

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

Conversation

fabriziopandini
Copy link
Member

What this PR does / why we need it:
As defined in https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md, stop using Deprecated replica counters in controllers.
Use new replica counters instead

Which issue(s) this PR fixes:
Rif #11947

/area cluster
/area machinedeployment
/area machineset
/area machine

@k8s-ci-robot k8s-ci-robot added area/cluster Issues or PRs related to clusters area/machinedeployment Issues or PRs related to machinedeployments area/machineset Issues or PRs related to machinesets area/machine Issues or PRs related to machine lifecycle management cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 5, 2025
@k8s-ci-robot k8s-ci-robot requested review from elmiko and JoelSpeed May 5, 2025 19:34
@fabriziopandini fabriziopandini changed the title ⚠️ Stop using deprecated counters in controllers ⚠️ Stop using deprecated replica counters in controllers May 5, 2025
@fabriziopandini fabriziopandini mentioned this pull request May 5, 2025
72 tasks
@cprivitere cprivitere mentioned this pull request May 5, 2025
40 tasks
@fabriziopandini fabriziopandini force-pushed the stop-using-deprecated-replica-counters-in-controllers branch from 46ae46b to 62d3e53 Compare May 6, 2025 08:23
Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

this makes sense to me, i just have one question.

func (i *Int32) Set(obj *unstructured.Unstructured, value int64) error {
if err := unstructured.SetNestedField(obj.UnstructuredContent(), value, i.path...); err != nil {
func (i *Int32) Set(obj *unstructured.Unstructured, value int32) error {
if err := unstructured.SetNestedField(obj.UnstructuredContent(), int64(value), i.path...); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this conversion to int64 correct?

i only ask because of my lack of familiarity with this function, and i had noted all the other conversions from int64 -> int32.

Copy link
Member Author

Choose a reason for hiding this comment

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

this conversion is required because SetNestedField only handles int64 values, so we are up-converting before calling this method

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh, got it. i thought it might be something like that but when i looked at the SetNestedField function decl i thought it took an interface{} there. thanks!

Copy link
Member

Choose a reason for hiding this comment

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

It takes an interface{} but uses DeepCopyJSONValue internally

// DeepCopyJSONValue deep copies the passed value, assuming it is a valid JSON representation i.e. only contains
// types produced by json.Unmarshal() and also int64.
// bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil

func (i *Int32) Set(obj *unstructured.Unstructured, value int64) error {
if err := unstructured.SetNestedField(obj.UnstructuredContent(), value, i.path...); err != nil {
func (i *Int32) Set(obj *unstructured.Unstructured, value int32) error {
if err := unstructured.SetNestedField(obj.UnstructuredContent(), int64(value), i.path...); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

It takes an interface{} but uses DeepCopyJSONValue internally

// DeepCopyJSONValue deep copies the passed value, assuming it is a valid JSON representation i.e. only contains
// types produced by json.Unmarshal() and also int64.
// bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil

@@ -540,7 +539,7 @@ func calculateStatus(allMSs []*clusterv1.MachineSet, newMS *clusterv1.MachineSet
V1Beta1: &clusterv1.MachineDeploymentV1Beta1DeprecatedStatus{
Conditions: conditions,
UpdatedReplicas: mdutil.GetActualReplicaCountForMachineSets([]*clusterv1.MachineSet{newMS}),
Copy link
Member

Choose a reason for hiding this comment

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

l.554 Q: Should we really still use v1beta1 counters to calculate .status.phase?

Copy link
Member

@sbueringer sbueringer May 8, 2025

Choose a reason for hiding this comment

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

Would be great if we can make the phase and conditions line up (e.g. for scaling, not sure if more)

Copy link
Member Author

Choose a reason for hiding this comment

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

No we should not.

Is that ok if I will address this in a follow up PR, I have point in my todo list to look into old UpdateStatus funcs (e.g. calculateV1Beta1Status in MD,MS - reconcileV1Beta1Status ) and move out everything not deprecated, like .status.phase.

Copy link
Member

Choose a reason for hiding this comment

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

Absolutely fine to address in a follow-up, just noticed it here during review

@fabriziopandini fabriziopandini added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 8, 2025
@k8s-ci-robot
Copy link
Contributor

@fabriziopandini: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main ca12f14 link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@sbueringer
Copy link
Member

/lgtm
/approve

/hold
In case you want to squash / wait for other reviews

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 8, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 8, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 445fdbc0b582e1f525968ee58b0cc0c5dcc072e6

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 8, 2025
@fabriziopandini
Copy link
Member Author

/hold cancel
Let's keep going, if someone will have additional comments, I will follow up in another PR

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 8, 2025
@k8s-ci-robot k8s-ci-robot merged commit 3fd0121 into kubernetes-sigs:main May 8, 2025
19 of 20 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.11 milestone May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster Issues or PRs related to clusters area/machine Issues or PRs related to machine lifecycle management area/machinedeployment Issues or PRs related to machinedeployments area/machineset Issues or PRs related to machinesets cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants