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

🐛 respect context in unstructured client #812

Merged
merged 3 commits into from
Feb 26, 2020

Conversation

alexeldeib
Copy link
Contributor

@alexeldeib alexeldeib commented Feb 21, 2020

ref: #41 (comment)

aligns the unstructured client with the typed client, sharing a cache between them for object metadata. plumbs context through to the restclient for unstructured client in doing so.

@shawn-hurley mentioned there were previously some issues with this, but as-is the implementation passes all current tests?

also, idk how hacky people consider this 😄 feels like I probably need to fix up some GVKs somewhere in the lists...

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 21, 2020
@alexeldeib
Copy link
Contributor Author

cc @alvaroaleman for some additional 👀

@vincepri vincepri added this to the v0.5.x milestone Feb 21, 2020
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

shawn-hurley mentioned there were previously some issues with this, but as-is the implementation passes all current tests?

Yeah and we have a fairly exhaustive set on integration tests for the client, except for UpdateStatus and PatchStatus, could you add those? If they pass as well I think we should be good.

We should probably still wait for Shawn to confirm that whatever issue he saw doesn't exist here :)

NamespaceIfScoped(key.Namespace, r.isNamespaced()).
Resource(r.resource()).
Context(ctx).
Name(key.Name).Do().Into(obj)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please keep the linebreaking the same as in the other methods

"k8s.io/client-go/dynamic"
)

// client is a client.Client that reads and writes directly from/to an API server. It lazily initializes
// new clients at the time they are used, and caches the client.
type unstructuredClient struct {
cache *clientCache
client dynamic.Interface
restMapper meta.RESTMapper
Copy link
Member

Choose a reason for hiding this comment

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

From what I can see, both the client and the restMapper are now unused

"k8s.io/apimachinery/pkg/runtime/schema"
)

type parameterCodec struct{}
Copy link
Member

Choose a reason for hiding this comment

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

Could we add a var _ runtime.ParamterCodec = parameterCodec to make this easier to understand? Also, please add some godocs to it clarifying how exactly it differs from the ParamterCodec obtained via the scheme

Copy link
Contributor Author

@alexeldeib alexeldeib Feb 23, 2020

Choose a reason for hiding this comment

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

I think a more correct approach to take is setting the serializer for unstructured on the restclient when we fetch it from the cache. I think that will allow us to remove this code and streamline further.

If that doesn't work out, i'll add some comments that this is for no-conversion serialization of create/delete/etc params.

For comparison sake, I looked at the dynamic client go client which forces everything to metav1. So it's technically correct right now due to metav1 being the only option, but setting the serializer is the more future-proof option.

e: seems like that breaks all sorts of things, which I suppose makes sense. sticking to the param codec. Maybe it makes sense to add a no-conversion param codec to unstructured in apimachinery directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment and renamed for clarity

@alexeldeib
Copy link
Contributor Author

Thanks for the review, good points 👍 I think I might be able to make the parameter codec a bit cleaner, still poking at it. If not I'll drop a comment explaining.

For posterity, we chatted on slack and agreed this approach makes sense

Expect(err).NotTo(HaveOccurred())

By("validating updated Deployment has type information")
Expect(u.GroupVersionKind()).To(Equal(depGvk))
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also get the deployment with the generated clientset and verify that its status got updated/patched 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added it for patch, I think it's there for the update calls already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure why they're organized this way, but I guess the tests are broken out fairly granular -- one test only does the type validation but the other two validate the actual status server side?

Copy link
Member

Choose a reason for hiding this comment

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

Oh you are right. Indeed very granular. Well, that definitely helps when debugging :)

Copy link
Member

@alvaroaleman alvaroaleman 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 Feb 25, 2020
@alexeldeib
Copy link
Contributor Author

/assign @DirectXMan12

I imagine you'd want to review this before merging

@vincepri
Copy link
Member

LGTM as well

@DirectXMan12
Copy link
Contributor

awesome

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeldeib, DirectXMan12

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 Feb 26, 2020
@alexeldeib
Copy link
Contributor Author

alexeldeib commented Feb 26, 2020

/test pull-controller-runtime-test-master

50 millisecond timeout feels aggressive, not sure if there's something hiding causing a flake or if it's just a low threshold. I can't repro that failure locally anyway.

@k8s-ci-robot k8s-ci-robot merged commit 9f8aab6 into kubernetes-sigs:master Feb 26, 2020
nan-yu added a commit to nan-yu/application that referenced this pull request Jun 21, 2021
When using controller-runtime to fetch the components, the version
information was able to be inferred from GK. However, the latest
controller-runtime requires the version infomation to be defined:
kubernetes-sigs/controller-runtime#812.
Hense, we need to provide the component's version.
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