Skip to content

🌱 Optimise patch calls#13367

Merged
k8s-ci-robot merged 2 commits intokubernetes-sigs:mainfrom
fabriziopandini:patch-improvements
Mar 9, 2026
Merged

🌱 Optimise patch calls#13367
k8s-ci-robot merged 2 commits intokubernetes-sigs:mainfrom
fabriziopandini:patch-improvements

Conversation

@fabriziopandini
Copy link
Copy Markdown
Member

@fabriziopandini fabriziopandini commented Feb 20, 2026

What this PR does / why we need it:
This PR drops usage of patch helper when we are modifying only few fields, not including conditions.
Also, avoid patching entirely when the object is not changed,.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #13305

/area util

@k8s-ci-robot k8s-ci-robot added the area/util Issues or PRs related to utils label Feb 20, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 20, 2026
@sbueringer sbueringer mentioned this pull request Feb 23, 2026
31 tasks
@fabriziopandini
Copy link
Copy Markdown
Member Author

/hold

Need rebase

@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 Feb 23, 2026
@fabriziopandini
Copy link
Copy Markdown
Member Author

/hold cancel

@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 Feb 23, 2026
kcpRef := *metav1.NewControllerRef(kcp, controlplanev1.GroupVersion.WithKind(kubeadmControlPlaneKind))
for _, m := range machines {
// No op if OwnerReferences is set and up to date.
if util.HasExactOwnerRef(m.OwnerReferences, kcpRef) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it really correct to skip all this code if m has the ownerRef? (especially including adoptOwnedSecrets)

I would move this down to l.1591

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved the code below, but I also think that most of this code can be entirely dropped.

This code was introduced by #2489 before the 0.4 release. when KCP was introduced and it was necessary to handle the adoption of standalone machines and related PKI material.

We are now well past this transition, and I think that we can safely drop the transition of PKI material.
We can debate about adoption.

My opinion is that the only part that should remain is EnforceOwnerRef

Copy link
Copy Markdown
Member

@sbueringer sbueringer Mar 9, 2026

Choose a reason for hiding this comment

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

I think I agree, let's just make this a separate effort.

In general, I'm just not entirely sure how much of this kind of code is for legacy code paths and how much is to restore ownerRef chains after backup/restore. (we have similar code in MS IIRC)

So I would like to be careful with changes like this and tackle them in a separate effort

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

💯 agreed on considering this as a follow up (low priority)

@@ -1647,29 +1640,25 @@ func (r *KubeadmControlPlaneReconciler) ensureCertificatesOwnerRef(ctx context.C
continue
}

Copy link
Copy Markdown
Member

@sbueringer sbueringer Feb 24, 2026

Choose a reason for hiding this comment

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

To me it looks like this code is not equivalent.

Previously we also did something for secrets that did not have ClusterSecretType. Is this change intentional? (probably yes, but wanted to double check)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I reviewed this change to reduce the diff from original
(not worth the effort to risk regressions for micro optimizations)

Copy link
Copy Markdown
Member

@sbueringer sbueringer Mar 9, 2026

Choose a reason for hiding this comment

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

Thx! It was just pretty tough to review for me

@fabriziopandini
Copy link
Copy Markdown
Member Author

/test pull-cluster-api-test-main

@fabriziopandini fabriziopandini added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 8, 2026
@sbueringer
Copy link
Copy Markdown
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 9, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 8a6174d80da4c2d1521e6453d5f5dd82605f882f

@k8s-ci-robot
Copy link
Copy Markdown
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

Details 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 Mar 9, 2026
@k8s-ci-robot k8s-ci-robot merged commit 7658261 into kubernetes-sigs:main Mar 9, 2026
19 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.13 milestone Mar 9, 2026
@fabriziopandini fabriziopandini deleted the patch-improvements branch April 10, 2026 12:44
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/util Issues or PRs related to utils 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/L Denotes a PR that changes 100-499 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.

3 participants