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

🌱 Stop relying on GVK being set on regular typed objects #9956

Merged
merged 1 commit into from Jan 11, 2024

Conversation

sbueringer
Copy link
Member

Signed-off-by: Stefan Büringer buringerst@vmware.com

What this PR does / why we need it:
Today controller-runtime doesn't set the GVKs of objects in all cases.

The current state is:

  • APIReader:
    • sets GVK on Unstructured objects
    • does not set GVK on regular typed objects
  • Cached reader:
    • sets GVK on Unstructured objects
    • sets GVK on regular typed objects (if disableDeepCopy = false, which is default)
  • fake client

Because of these inconsistencies (that cannot be easily changed upstream) and because it's hard to tell across entire call stacks where objects come from I would suggest to only rely on GVK being set on Unstructured objects. For Unstructured objects GVK has to be always set to be able to identify the object, for regular typed objects this is not the case.

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 4, 2024
@@ -416,7 +416,7 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
if scope.Config.Spec.InitConfiguration == nil {
scope.Config.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: "kubeadm.k8s.io/v1beta1",
APIVersion: "kubeadm.k8s.io/v1beta3",
Copy link
Member Author

Choose a reason for hiding this comment

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

@fabriziopandini I guess this wasn't a problem because this code was never actually used?

Copy link
Member

Choose a reason for hiding this comment

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

I need to dig into this, I will follow up ASAP (eventually we can drop this from this PR if you want to move forward)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the PR doesn't change it for the worse

@@ -193,7 +193,7 @@ func addVariablesForPatch(blueprint *scope.ClusterBlueprint, desired *scope.Clus
if item.HolderReference.Kind == "MachineDeployment" {
md, ok := mdStateIndex[item.HolderReference.Name]
if !ok {
return errors.Errorf("could not find desired state for MachineDeployment %s", klog.KObj(md.Object))
return errors.Errorf("could not find desired state for MachineDeployment %s", klog.KRef(item.HolderReference.Namespace, item.HolderReference.Name))
Copy link
Member Author

@sbueringer sbueringer Jan 4, 2024

Choose a reason for hiding this comment

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

This panic'ed previously if we actually hit this line

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@sbueringer
Copy link
Member Author

@sbueringer
Copy link
Member Author

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

@chrischdi
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 8, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 2f2609fd5a6c83cc5228ddac2174f21b59ba7782

Signed-off-by: Stefan Büringer buringerst@vmware.com
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2024
Copy link
Member

@chrischdi chrischdi left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 11, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 17bbc8d6dff53dad0bde996c8f0ee540cd0d9bdc

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this change, only few nits from my side

@@ -193,7 +193,7 @@ func addVariablesForPatch(blueprint *scope.ClusterBlueprint, desired *scope.Clus
if item.HolderReference.Kind == "MachineDeployment" {
md, ok := mdStateIndex[item.HolderReference.Name]
if !ok {
return errors.Errorf("could not find desired state for MachineDeployment %s", klog.KObj(md.Object))
return errors.Errorf("could not find desired state for MachineDeployment %s", klog.KRef(item.HolderReference.Namespace, item.HolderReference.Name))
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@fabriziopandini
Copy link
Member

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 Jan 11, 2024
@k8s-ci-robot k8s-ci-robot merged commit ec2abf8 into kubernetes-sigs:main Jan 11, 2024
20 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.7 milestone Jan 11, 2024
@sbueringer sbueringer deleted the pr-gvk branch January 12, 2024 12:38
thbkrkr added a commit to elastic/cloud-on-k8s that referenced this pull request Jan 30, 2024
…7468)

* fix(deps): update module sigs.k8s.io/controller-runtime to v0.17.0

* make generate

* Stop relying on GVK being set on SCP object

TestReconcileStackConfigPolicy_Reconcile fails because with kubernetes-sigs/controller-runtime#2633 the fakeClient does not set the TypeMeta of the StackConfigPolicy object, so its typeMeta.Kind becomes empty but CanBeOwnedBy depends on it.

The behavior change to not populate TypeMeta for regular object is to be aligned with the behavior of the real client, see kubernetes-sigs/cluster-api#9956:
- APIReader does not set GVK on regular typed objects
- Cached reader does not set GVK on regular typed objects (if disableDeepCopy = false, which is NOT default).

We could just set the Kind of the StackConfigPolicy object in the tests but it's better to
stop relying on GVK being set on the StackConfigPolicy object.

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Thibault Richard <thb.krkr@gmail.com>
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/api Issues or PRs related to the APIs 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants