-
Notifications
You must be signed in to change notification settings - Fork 1.8k
model: Introduce KubernetesResource interface #2800
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
Conversation
@ruromero are you using this interface in a controller? Can you provide a more detailed example of how you'd use this interface? |
Yes we use it extensively in different operators. e.g. https://github.com/kiegroup/kie-cloud-operator/blob/master/pkg/controller/kieapp/kieapp_controller.go#L199 This is actually part of our operator-utils library and wanted to contribute it to the operator-sdk. If you find it useful we can think of more utilities to contribute. |
This interface provides a simpler way to interact with metav1.Object and runtime.Object avoiding unnecessary type castings and more flexibility Signed-off-by: ruromero <[email protected]>
type KubernetesResource interface { | ||
metav1.Object | ||
runtime.Object | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it should be added? What is the need/scenario that can be solved with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be an example where a generic method accepts any type of resource, sets the owner reference (metav1.Object) and creates the object (runtime.Object).
@@ -21,6 +21,7 @@ require ( | |||
github.com/mattn/go-isatty v0.0.12 | |||
github.com/mitchellh/go-homedir v1.1.0 | |||
github.com/mitchellh/mapstructure v1.1.2 | |||
github.com/openshift/api v0.0.0-20200205133042-34f0ec8dab87 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if we should add the OCP dep by default. wdyt @joelanford ?
This is a duplicate of kubernetes-sigs/controller-runtime#594. Can we continue the discussion there? |
After look the comment #2800 (comment) I understand that this suggestion would better addressed by via kubernetes-sigs/controller-runtime#594 as the solution applied there. So, I am closing this one. However, please feel free to re-open if you think that it should still be addressed here or if I misunderstood something. |
Would you re-consider this PR if the issue in controller-runtime does not progress? I still believe this small interface would help many developers writing better operators/controllers. |
@ruromero I would open this PR in controller-runtime. An implementation makes abstractions easier to discuss. |
Description of the change: Introduce KubernetesResource interface
Motivation for the change: This interface provides a simpler way to interact with metav1.Object and runtime.Object avoiding unnecessary type castings and more flexibility