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

⚠️ Fakeclient: Only set TypeMeta for unstructured #2633

Merged
merged 1 commit into from Jan 4, 2024

Conversation

alvaroaleman
Copy link
Member

Currently, the fakeclient unconditionally sets metadata for all objects retrieved through it. This causes two problems:

  • It differs from the behavior of the real client, except for the cached one if DeepCopy is enabled and might lead ppl to think that they can rely on TypeMeta being populated, which is absolutely not the case
  • It causes panics for types that have TypeMeta defined as pointer, making it impossible to use the client with them

This PR changes the behavior to only populate TypeMeta for unstructured.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 3, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 3, 2024
Currently, the fakeclient unconditionally sets metadata for all objects
retrieved through it. This causes two problems:
* It differs from the behavior of the real client, except for the cached
  one if `DeepCopy` is enabled and might lead ppl to think that they can
  rely on `TypeMeta` being populated, which is absolutely not the case
* It causes panics for types that have `TypeMeta` defined as pointer,
  making it impossible to use the client with them

This PR changes the behavior to only populate TypeMeta for `unstructured`.
@sbueringer
Copy link
Member

sbueringer commented Jan 4, 2024

Thx!

/lgtm

/hold
Feel free to merge, not sure if you want additional 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 Jan 4, 2024
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 4, 2024
@sbueringer sbueringer added this to the v0.17.x milestone Jan 4, 2024
@vincepri
Copy link
Member

vincepri commented Jan 4, 2024

/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 Jan 4, 2024
@k8s-ci-robot k8s-ci-robot merged commit 91f642b into kubernetes-sigs:main Jan 4, 2024
9 checks passed
@alvaroaleman alvaroaleman deleted the pointer branch January 4, 2024 17:22
ksimon1 added a commit to ksimon1/ssp-operator that referenced this pull request Jan 19, 2024
there was change in behaviour of kubernetes-sigs/controller-runtime -
kubernetes-sigs/controller-runtime#2633.
This commit updates test to copy TypeMeta in update CreateOrUpdate
function.
Signed-off-by: Karel Simon <ksimon@redhat.com>
ksimon1 added a commit to ksimon1/ssp-operator that referenced this pull request Jan 24, 2024
there was change in behaviour of kubernetes-sigs/controller-runtime -
kubernetes-sigs/controller-runtime#2633.
This commit updates test to copy TypeMeta in update CreateOrUpdate
function.
Signed-off-by: Karel Simon <ksimon@redhat.com>
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>
tiraboschi added a commit to tiraboschi/hyperconverged-cluster-operator that referenced this pull request Jan 31, 2024
- Bump controller-runtime to v0.17.0
- Introduce a few minor fixes for new fakeclient behaviour, see:
kubernetes-sigs/controller-runtime#2633

Signed-off-by: Simone Tiraboschi <stirabos@redhat.com>
kubevirt-bot pushed a commit to kubevirt/hyperconverged-cluster-operator that referenced this pull request Feb 1, 2024
- Bump controller-runtime to v0.17.0
- Introduce a few minor fixes for new fakeclient behaviour, see:
kubernetes-sigs/controller-runtime#2633

Signed-off-by: Simone Tiraboschi <stirabos@redhat.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. 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