-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Comments
/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 |
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. |
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. |
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. |
👍 from me |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/lifecycle frozen |
/help |
@vincepri: Please ensure the request meets the requirements listed here. If this request no longer meets these requirements, the label can be removed In response to this:
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. |
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. |
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. |
I'm taking a look at this issue and it seems that #1195 addressed most of it; is there something else left? |
@fabriziopandini yeah, this got implemented, seems we just forgot to close the issue. Thank you for looking into it! |
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
The text was updated successfully, but these errors were encountered: