-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[#10295] Allow using the informer interface, and trace down all types #10344
Conversation
I'll be looking at this tomorrow |
Thanks a lot for this @ctron. Can you add a description of what exactly the type expansion is doing and why it's needed? Perhaps with an example? |
private static final DotName KUBERNETES_RESOURCE = DotName | ||
.createSimple("io.fabric8.kubernetes.api.model.KubernetesResource"); | ||
private static final DotName KUBERNETES_RESOURCE_LIST = DotName | ||
.createSimple("io.fabric8.kubernetes.api.model.KubernetesResourceList"); | ||
private static final Set<String> EXCLUDED_CLASSES; |
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 think that we'll need a better name for this, it's a little too generic IMHO
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.
Sure, do you have suggestions?
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.
Maybe EXCLUDED_WATCH_CLASSES
?
I absolutely understand. Do you want this description in the GitHub comments? Or in the code itself? |
I'd say lets start with a GH comment and we'll see if we need anything else :) |
The problem is: the kubernetes extension finds the main class, used in the watcher (or informer) and enables this class for the reflection mechanism. So when the kubernetes client pulls in some JSON from the server, it can deserialize the JSON, with that class information. Which is done by Jackson, using reflection. All attributes that are on this specific class are covered. However, if you inherit fields from another class, or reference some other class, then these attribute cannot be found via reflection. Annotating them with The "expand" functionality (and I am open for a different name) takes the root class, extracted from the Watcher implementation, and walks through the type hierarchy, and also walks through the types of the the fields and getters, adding all referenced types to the reflection system. Assuming you have the following structure: class AbstractHasMetadata implements HasMetadata {
String kind;
String apiVersion;
}
class MyCrd extends AbstractHasMetadata {
MyCrdSpec spec;
}
class MyCrdSpec {
List<MyCrdConfig> allTheConfigs;
}
class MyCrdConfig {
String value;
}
void startWatcher() {
client.crd(MyCrd.class).watch(new Watcher<>() {
public void onAdd() {}
public void onRemove() {}
public void onUpdate() {}
});
} The extension currently detects So deserialization fails, when it e.g. finds the field "kind" from the abstract base class. Or when it finds the Now the extensions walks the type hierarchy up, adding the abstract class as well. But it also walks the fields of each type it processes, and finds the type |
Now I get it, thanks for the explanation @ctron. Last question: Instead of doing the manual walking of the hierarchy, did you try producing |
No I didn't, because I wasn't ware of that 😀 … I will take a look and give it a try. |
Yeah sorry, that's my fault that I didn't bring it to your attention :( Let me know how it goes |
…all types This change also evaluates implementations of `ResourceEventHandler`, which is the corresponding interface for the informer. This allows to use watchers or informers the same way. Also it traverses through the type information, adding all required types to the list of types enabling reflection. If only the direct class is added, deserialization will fail, unless all the references classes are manually annotated with @RegisterForReflection. Signed-off-by: Jens Reimann <[email protected]>
16ef3ca
to
567d9cf
Compare
Works as expected. I updated the PR. |
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.
LGTM, thanks!
This change also evaluates implementations of
ResourceEventHandler
,which is the corresponding interface for the informer. This allows to
use watchers or informers the same way.
Also it traverses through the type information, adding all required
types to the list of types enabling reflection. If only the direct class
is added, deserialization will fail, unless all the references classes
are manually annotated with @RegisterForReflection.
Signed-off-by: Jens Reimann [email protected]