Skip to content

Conversation

alvaroaleman
Copy link
Member

@alvaroaleman alvaroaleman commented May 27, 2025

The fakeclient currently differs from the liveclient in that if a
structured object is created that has typemeta set, it will retain that.
In contrast to that, the liveclient always strips it.

This change makes the fakeclient strip it just like the live client.

Based on top of #3228 which needs to merge first.

Noticed this while working on #2981

/hold

@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 27, 2025
@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 the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 27, 2025
@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 May 27, 2025
@alvaroaleman alvaroaleman force-pushed the typemeta branch 2 times, most recently from d6c17b7 to f8773da Compare May 27, 2025 18:02
The fakeclient currently differs from the liveclient in that if a
structured object is created that has typemeta set, it will retain that.
In contrast to that, the liveclient always strips it.

This change makes the fakeclient strip it just like the live client.
@alvaroaleman
Copy link
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 May 28, 2025
@troy0820
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 May 28, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: a49c7a92a457cad8c7b312b1d5588225f9280bf8

@k8s-ci-robot k8s-ci-robot merged commit 1dce621 into kubernetes-sigs:main May 28, 2025
9 checks passed
@sbueringer
Copy link
Member

/lgtm

jcanocan added a commit to jcanocan/ssp-operator that referenced this pull request Sep 1, 2025
The required fixed are the following:
 * The function RESTClientForGVK has introduced the
`forceDisableProtoBuf` field. The code base has been adjusted to set
this field as `false` where is is used.

 * Fake client now strips the TypeMeta fields
kubernetes-sigs/controller-runtime#3229.
Therefore, it is required to adjust how the cache gets the `Kind` field,
otherwise, the field is empty and objects are not cached.

Signed-off-by: Javier Cano Cano <[email protected]>
jcanocan added a commit to jcanocan/ssp-operator that referenced this pull request Sep 1, 2025
The required fixes are the following:
 * The function RESTClientForGVK has introduced the
`forceDisableProtoBuf` field. The code base has been adjusted to set
this field as `false` where is used.

 * Fake client now strips the TypeMeta fields
kubernetes-sigs/controller-runtime#3229.
Therefore, it is required to adjust how the cache gets the `Kind` field,
otherwise, the field is empty and objects are not cached.

Signed-off-by: Javier Cano Cano <[email protected]>
@tolusha
Copy link

tolusha commented Sep 18, 2025

Hello @alvaroaleman
Please, could you point where real client strips the TypeMeta?
Because basically I observe the difference in behavior. Only the fake client removes the TypeMeta.

@alvaroaleman
Copy link
Member Author

alvaroaleman commented Sep 18, 2025

It happens in the decoder: kubernetes/kubernetes#80609

Any code that assumes presence of type meta on objects is prone to become problematic, because if someone does p := &corev1.Pod{}, p won't have typemeta. Do not ever rely on it being present, use apiutil.GVKForObject

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.

5 participants