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

🐛 Use namespace of the reference on external.Get #11361

Merged

Conversation

Danil-Grigorev
Copy link
Member

@Danil-Grigorev Danil-Grigorev commented Oct 31, 2024

What this PR does / why we need it:

Using external.Get method may be problematic when the resources referenced are located in a different namespace from the originating resource, leading to not found errors on the lookup attempts.

Template definitions provide all information, including namespace of the object in the references, so using those instead.

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

/area clusterclass
/area api

@k8s-ci-robot k8s-ci-robot added area/clusterclass Issues or PRs related to clusterclass cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 31, 2024
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Oct 31, 2024
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 1, 2024
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 1, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references branch 3 times, most recently from 7672253 to edbd553 Compare November 1, 2024 12:02
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 1, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references branch 5 times, most recently from 511364f to b03866f Compare November 1, 2024 13:58
@Danil-Grigorev
Copy link
Member Author

/test pull-cluster-api-e2e-mink8s-main

@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-mink8s-main

@sbueringer sbueringer added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 4, 2024
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Thx, one nit

(if e2e tests work)

controllers/external/util.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-main

@Danil-Grigorev
Copy link
Member Author

/test pull-cluster-api-e2e-main

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 13, 2024
@sbueringer
Copy link
Member

Pretty far up in my review TODO list now. @Danil-Grigorev Can you please rebase?

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 13, 2024
@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-main

Copy link
Member

@furkatgofurov7 furkatgofurov7 left a comment

Choose a reason for hiding this comment

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

Looks good to me

@sbueringer sbueringer added area/util Issues or PRs related to utils and removed area/clusterclass Issues or PRs related to clusterclass labels Nov 18, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 18, 2024
@@ -25,23 +25,24 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Copy link
Member

@sbueringer sbueringer Nov 18, 2024

Choose a reason for hiding this comment

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

@Danil-Grigorev Did some analysis (sharing here for future-us :))

Ref fields with namespace defaulting before this PR:

  • Cluster.Spec.InfrastructureRef
  • Cluster.Spec.ControlPlaneRef
  • Machine.Spec.InfrastructureRef
  • Machine.Spec.Bootstrap.ConfigRef
  • MachinePool.Spec.Template.Spec.Bootstrap.ConfigRef
  • MachinePool.Spec.Template.Spec.InfrastructureRef
  • MHC.Spec.RemediationTemplate
  • KCP.spec.machineTemplate.infrastructureRef
  • ClusterClass (all refs)

Namespace fields for which we have to add defaulting:

  • MachineDeployment (not used anymore for rollout decisions, namespace is set in most cases by Cluster topology controller)
    • Defaulting already added with this PR
    • DeepCopy ref and set namespace if empty directly before external.Get (in reconcileExternalTemplateReference)
  • MachineSet (not used anymore for rollout decisions, namespace is set in most cases by the MD controller)
    • Defaulting already added with this PR
    • DeepCopy ref and set namespace if empty directly before external.Get (in reconcileExternalTemplateReference)

So I think we're almost good. I think we just can't assume that the defaulting/mutating webhook always run before our controllers (e.g. if a MD/MS is never modified). I think for this case it would be good to add safeguards in the reconcileExternalTemplateReference funcs to set the namespace if it is empty directly before we use it (but after UpdateReferenceAPIContract))

Copy link
Member

@sbueringer sbueringer Nov 18, 2024

Choose a reason for hiding this comment

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

(DeepCopy has been added now, updated the tasks accordingly)

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 18, 2024
@k8s-ci-robot
Copy link
Contributor

@Danil-Grigorev: 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 ca36516 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

/test pull-cluster-api-e2e-main

Thank you very much!

/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 Nov 18, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: b688a46b1bcb5744c4ee8aa65c01efc8883d9392

@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 Nov 18, 2024
@k8s-ci-robot k8s-ci-robot merged commit a21faa0 into kubernetes-sigs:main Nov 18, 2024
18 of 19 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.9 milestone Nov 18, 2024
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.

5 participants