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

Expose a union interface for metav1.Object and runtime.Object #594

Closed
alvaroaleman opened this issue Sep 10, 2019 · 13 comments
Closed

Expose a union interface for metav1.Object and runtime.Object #594

alvaroaleman opened this issue Sep 10, 2019 · 13 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Milestone

Comments

@alvaroaleman
Copy link
Member

Most (all?) Kubernetes API types implement both metav1.Object and runtime.Object. Code that needs both usually accepts either, then type asserts for the other.

It would be nice to have a union interface for the two and re-use that throughout our code

@DirectXMan12
Copy link
Contributor

/kind feature

We've got a number of places where we error out if the object isn't a metav1.Object. When we next want to break things before 1.0.0, we should consider the implications of using this union interface, and adding helpers to assert that an object meets it (it's not a type-assert in cases where you have a generic runtime.Object).

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 10, 2019
@munnerz
Copy link
Member

munnerz commented Sep 11, 2019

Just my 2c - not all types do implement both, only those that are actually created as CRDs.

In cert-manager we have a few extensibility mechanisms that rely on webhooks, and so we use a type that implements TypeMeta but not ObjectMeta: https://github.com/jetstack/cert-manager/blob/master/pkg/acme/webhook/apis/acme/v1alpha1/types.go#L30

This means we implement runtime.Object, but not metav1.Object. This gives us conversion etc. It’s a pattern borrowed from apiextensions-apiserver itself with the AdmissionReview and ConversionReview types.

I think there are places where this sort of union interface could be useful, but we should use it sparingly where it’s actually helpful, and consider that we limit the number of things that can use such a method to those that also have a ‘metadata’ stanza.

@DirectXMan12
Copy link
Contributor

Right -- there are places where we actually want to say "we need object metadata", places where we say "we can do more stuff if we have object metadata", and places where all we need is the type.

@Adirio
Copy link
Contributor

Adirio commented Oct 30, 2019

As I said in #666, unifying the interface in cases when there is a type assertion (and by assertion I mean a type cast that returns an error if it doesn't meet it) would move some errors from run time to compile time and would also allow IDEs to catch this errors. SetControllerRef seems to be one of them. Should we make a list and categorize them as @DirectXMan12 suggests (both interfaces required vs extra interface helpful)?

@DirectXMan12
Copy link
Contributor

Should we make a list and categorize them as @DirectXMan12 suggests (both interfaces required vs extra interface helpful)?

👍 from me

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/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 Feb 3, 2020
@vincepri
Copy link
Member

vincepri commented Feb 4, 2020

/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 4, 2020
@vincepri vincepri added this to the Next milestone Feb 21, 2020
@vincepri
Copy link
Member

/help
/priority awaiting-more-evidence

@k8s-ci-robot
Copy link
Contributor

@vincepri:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/help
/priority awaiting-more-evidence

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.

@k8s-ci-robot k8s-ci-robot added priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Feb 21, 2020
@ruromero
Copy link
Contributor

ruromero commented Apr 8, 2020

FWIW we introduced the KubernetesResource to our operator-utils library and found it useful in multiple situations.

As has been already mentioned, this interface can avoid runtime errors and avoid unnecessary type conversions and maybe create higher level abstractions for some methods.

@alvaroaleman
Copy link
Member Author

Heads-up for ppl watching this issue, #898 merged so we now have such an union interface in pkg/controller/controllerutil. We don't yet use it anywhere though, hence leaving this issue open until we do use it where it makes sense.

@vincepri vincepri removed the priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. label May 22, 2020
@fabriziopandini
Copy link
Member

I'm taking a look at this issue and it seems that #1195 addressed most of it; is there something else left?

@alvaroaleman
Copy link
Member Author

@fabriziopandini yeah, this got implemented, seems we just forgot to close the issue. Thank you for looking into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

No branches or pull requests

9 participants