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

[1.20.2] FakeDynamicClient can't assign or convert unstructured.Unstructured into list item type #983

Closed
adambkaplan opened this issue Jun 10, 2021 · 6 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@adambkaplan
Copy link

Code repository uses the fake dynamic client to test the interaction with a custom resource (Kind: Build, GV: shipwright.io/v1alpha1).
The custom resource has its core object and list types registered to a scheme, and the CRD's scheme is added to the core scheme when setting up the dynamic client.

When running a unit test with the fake dynamic client, the resource can be created and retrieved via the GET resource interface. However when trying to list the objects, the following error is returned:

"item[0]: can't assign or convert unstructured.Unstructured into v1alpha1.Build",

Is this a bug in the fake dynamic client?

@adambkaplan
Copy link
Author

Note that no error was returned in v1.19

adambkaplan added a commit to adambkaplan/shipwright-cli that referenced this issue Jun 10, 2021
k8s 1.20's fake dynamic client returns an error trying to convert an
unstructured type to the list's underlying type. Skipping the resource
list unit test until the fake dynamic client is fixed upstream.

See kubernetes/client-go#983
HeavyWombat pushed a commit to HeavyWombat/cli that referenced this issue Jul 8, 2021
k8s 1.20's fake dynamic client returns an error trying to convert an
unstructured type to the list's underlying type. Skipping the resource
list unit test until the fake dynamic client is fixed upstream.

See kubernetes/client-go#983
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 8, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 8, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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/test-infra repository.

@imuxin
Copy link

imuxin commented May 19, 2022

v0.21.4 fixed.

Related commits:
46c1ad3
k8s-dig/kubernetes@d4da537

aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 2, 2024
… NewSimpleDynamicClientWithCustomListKinds

Using NewSimpleDynamicClientWithCustomListKinds leads to an error during type conversion from unstructured to an instance of the object.
Remove the gvrToListKind argument as its no longer needed.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 2, 2024
… NewSimpleDynamicClientWithCustomListKinds

Using NewSimpleDynamicClientWithCustomListKinds leads to an error during type conversion from unstructured to an instance of the object.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 3, 2024
…d map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 3, 2024
…d map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 3, 2024
…d map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 10, 2024
…d map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 15, 2024
…d map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
aerosouund added a commit to aerosouund/kyverno that referenced this issue Oct 15, 2024
…d map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>
realshuting added a commit to kyverno/kyverno that referenced this issue Oct 16, 2024
* feature: Add LabelSelector as a field of resource spec to allow fetching by labels

Signed-off-by: aerosouund <[email protected]>

* chore: Generate CRDs

Signed-off-by: aerosouund <[email protected]>

* feat: Add the capability to fetch with label selector

- Add the label selector as a parameter to GetResources of the engine api client and the dclient.
- Use the label selector with list options in the dclient.
- convert a metav1.LabelSelector to a labels.Selector before fetching to be able to convert it to a string to be used with ListOptions.

Signed-off-by: aerosouund <[email protected]>

* feat: Pass label selector to the GetResources method

Signed-off-by: aerosouund <[email protected]>

* feat: Return the resource selector when resolving spec

Signed-off-by: aerosouund <[email protected]>

* fix: Instantiate the fake client schema using the passed gvrToListKind map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>

* test: Add labelSelector unit test to mutate existing test.

- Remove the unwanted call to GetResource.
- Pass an empty map of GVR to string to the fake client constructor.

Signed-off-by: aerosouund <[email protected]>

* test: Add chainsaw test

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen

Signed-off-by: aerosouund <[email protected]>

* chore: Generate helm CRDs

Signed-off-by: aerosouund <[email protected]>

* refactor: Put the LabelSelector in a separate struct

Many types use the ResourceSpec struct and not all of them support label selectors.
This removes the field into a separate schema dedicated to target selection called TargetSelector.
It has the ResourceSpec and the selector.

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen after modifying selector comment

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen

Signed-off-by: aerosouund <[email protected]>

---------

Signed-off-by: aerosouund <[email protected]>
Co-authored-by: shuting <[email protected]>
gcp-cherry-pick-bot bot pushed a commit to kyverno/kyverno that referenced this issue Oct 17, 2024
* feature: Add LabelSelector as a field of resource spec to allow fetching by labels

Signed-off-by: aerosouund <[email protected]>

* chore: Generate CRDs

Signed-off-by: aerosouund <[email protected]>

* feat: Add the capability to fetch with label selector

- Add the label selector as a parameter to GetResources of the engine api client and the dclient.
- Use the label selector with list options in the dclient.
- convert a metav1.LabelSelector to a labels.Selector before fetching to be able to convert it to a string to be used with ListOptions.

Signed-off-by: aerosouund <[email protected]>

* feat: Pass label selector to the GetResources method

Signed-off-by: aerosouund <[email protected]>

* feat: Return the resource selector when resolving spec

Signed-off-by: aerosouund <[email protected]>

* fix: Instantiate the fake client schema using the passed gvrToListKind map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>

* test: Add labelSelector unit test to mutate existing test.

- Remove the unwanted call to GetResource.
- Pass an empty map of GVR to string to the fake client constructor.

Signed-off-by: aerosouund <[email protected]>

* test: Add chainsaw test

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen

Signed-off-by: aerosouund <[email protected]>

* chore: Generate helm CRDs

Signed-off-by: aerosouund <[email protected]>

* refactor: Put the LabelSelector in a separate struct

Many types use the ResourceSpec struct and not all of them support label selectors.
This removes the field into a separate schema dedicated to target selection called TargetSelector.
It has the ResourceSpec and the selector.

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen after modifying selector comment

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen

Signed-off-by: aerosouund <[email protected]>

---------

Signed-off-by: aerosouund <[email protected]>
Co-authored-by: shuting <[email protected]>
realshuting added a commit to kyverno/kyverno that referenced this issue Oct 17, 2024
* feature: Add LabelSelector as a field of resource spec to allow fetching by labels



* chore: Generate CRDs



* feat: Add the capability to fetch with label selector

- Add the label selector as a parameter to GetResources of the engine api client and the dclient.
- Use the label selector with list options in the dclient.
- convert a metav1.LabelSelector to a labels.Selector before fetching to be able to convert it to a string to be used with ListOptions.



* feat: Pass label selector to the GetResources method



* feat: Return the resource selector when resolving spec



* fix: Instantiate the fake client schema using the passed gvrToListKind map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3



* test: Add labelSelector unit test to mutate existing test.

- Remove the unwanted call to GetResource.
- Pass an empty map of GVR to string to the fake client constructor.



* test: Add chainsaw test



* chore: Run codegen



* chore: Generate helm CRDs



* refactor: Put the LabelSelector in a separate struct

Many types use the ResourceSpec struct and not all of them support label selectors.
This removes the field into a separate schema dedicated to target selection called TargetSelector.
It has the ResourceSpec and the selector.



* chore: Run codegen after modifying selector comment



* chore: Run codegen



---------

Signed-off-by: aerosouund <[email protected]>
Co-authored-by: Ammar Yasser <[email protected]>
Co-authored-by: shuting <[email protected]>
pipo02mix pushed a commit to giantswarm/kyverno-upstream that referenced this issue Feb 10, 2025
* feature: Add LabelSelector as a field of resource spec to allow fetching by labels

Signed-off-by: aerosouund <[email protected]>

* chore: Generate CRDs

Signed-off-by: aerosouund <[email protected]>

* feat: Add the capability to fetch with label selector

- Add the label selector as a parameter to GetResources of the engine api client and the dclient.
- Use the label selector with list options in the dclient.
- convert a metav1.LabelSelector to a labels.Selector before fetching to be able to convert it to a string to be used with ListOptions.

Signed-off-by: aerosouund <[email protected]>

* feat: Pass label selector to the GetResources method

Signed-off-by: aerosouund <[email protected]>

* feat: Return the resource selector when resolving spec

Signed-off-by: aerosouund <[email protected]>

* fix: Instantiate the fake client schema using the passed gvrToListKind map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- kubernetes/client-go#983
- kubernetes/client-go@46c1ad3

Signed-off-by: aerosouund <[email protected]>

* test: Add labelSelector unit test to mutate existing test.

- Remove the unwanted call to GetResource.
- Pass an empty map of GVR to string to the fake client constructor.

Signed-off-by: aerosouund <[email protected]>

* test: Add chainsaw test

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen

Signed-off-by: aerosouund <[email protected]>

* chore: Generate helm CRDs

Signed-off-by: aerosouund <[email protected]>

* refactor: Put the LabelSelector in a separate struct

Many types use the ResourceSpec struct and not all of them support label selectors.
This removes the field into a separate schema dedicated to target selection called TargetSelector.
It has the ResourceSpec and the selector.

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen after modifying selector comment

Signed-off-by: aerosouund <[email protected]>

* chore: Run codegen

Signed-off-by: aerosouund <[email protected]>

---------

Signed-off-by: aerosouund <[email protected]>
Co-authored-by: shuting <[email protected]>
Signed-off-by: pipo02mix <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants