-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Incorrect SharedInformerFactory#getExistingSharedIndexInformer #2937
Comments
@hibnico : hello, I'm not able to reproduce this issue. I created package io.fabric8.crd;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;
@Group("com.acme")
@Version("v1")
public class MyAppCustomResource extends CustomResource<Void, Void> { } When I'm running this code I'm able to see both try (KubernetesClient client = new DefaultKubernetesClient()) {
SharedInformerFactory informerFactory = client.informers();
SharedIndexInformer<MyAppCustomResource> createdInformer = informerFactory.sharedIndexInformerForCustomResource(MyAppCustomResource.class, MyAppCustomResourceList.class, 5 * 1000L);
SharedIndexInformer<MyAppCustomResource> existingInformer = informerFactory.getExistingSharedIndexInformer(MyAppCustomResource.class);
System.out.println(createdInformer);
System.out.println(existingInformer);
} Could you please check what I'm doing wrong? |
The @kind annotation is missing, if the kind is not something close to the class name (considering the code, it seems about containing the plural of the class name), the lookup fails. |
Thanks for quick reply, I think I can see what's the issue now. For calculating plural I'm resolving it from class name instead of checking Lines 269 to 271 in 0d9e634
|
…mer returns null when @kind configured Right now we're just getting plural form of Class name for CustomResource while resolving SharedInformerFactory informer map's keys. But this leads to issues when user can configure his kind using `@Kind` annotation. This PR changes plural calculation logic to this: - Check @plural annotation, if present use this to check key - Check @kind annotation, use Pluralize.toPlural(kind.value()) to check key - Check Pluralize.toPlural(apiType.getSimpleName().toLowerCase()) to check key
…mer returns null when @kind configured Right now we're just getting plural form of Class name for CustomResource while resolving SharedInformerFactory informer map's keys. But this leads to issues when user can configure his kind using `@Kind` annotation. This PR changes plural calculation logic to this: - Check @plural annotation, if present use this to check key - Check @kind annotation, use Pluralize.toPlural(kind.value()) to check key - Check Pluralize.toPlural(apiType.getSimpleName().toLowerCase()) to check key
…mer returns null when @kind configured Right now we're just getting plural form of Class name for CustomResource while resolving SharedInformerFactory informer map's keys. But this leads to issues when user can configure his kind using `@Kind` annotation. This PR changes plural calculation logic to this: - Check @plural annotation, if present use this to check key - Check @kind annotation, use Pluralize.toPlural(kind.value()) to check key - Check Pluralize.toPlural(apiType.getSimpleName().toLowerCase()) to check key
…ns null when @kind configured Right now we're just getting plural form of Class name for CustomResource while resolving SharedInformerFactory informer map's keys. But this leads to issues when user can configure his kind using `@Kind` annotation. This PR changes plural calculation logic to this: - Check @plural annotation, if present use this to check key - Check @kind annotation, use Pluralize.toPlural(kind.value()) to check key - Check Pluralize.toPlural(apiType.getSimpleName().toLowerCase()) to check key
I am sorry I have missed the updates on this issue. Looking at the fix now, it will indeed fix the issue I faced, but I fear that the lookup strategy in the map of informers is still not safe. In the |
I think I should have removed |
What I'm saying is that it's no longer possible to fetch informer from map precisely when you have more than one informer of same type present in informer map. Do you think it's a good idea to add |
Ok, I see the deeper issue at stake here. Making In my use case, I wanted to have access to my specific informer into two parts of my software. And since in these two parts I can easily have access to the |
Umm, do you think it's a good idea for users to provide their own key. In case someone provides their own key like this:
Or maybe add another method |
Letting choose the key in the API is probably error prone, since the key must be unique. And then if a key has been overriden, the API should notify about it somehow. This doesn't simplify the API much. I like though the idea of being able to list all existing informers. Maybe the API could list all the informers with their creating contexts. Something like: |
…Informers` to return list of registered informers + Add a new method `getExistingSharedIndexInformers()` to SharedInformerFactory which would return a list of entries containing registered SharedIndexInformer and their respective OperationContext. This is added to overcome limitation of old `getExistingSharedIndexInformer(Class<T> apiTypeClass)` in case there are two informers registered with same type.
…Informers` to return list of registered informers + Add a new method `getExistingSharedIndexInformers()` to SharedInformerFactory which would return a list of entries containing registered SharedIndexInformer and their respective OperationContext. This is added to overcome limitation of old `getExistingSharedIndexInformer(Class<T> apiTypeClass)` in case there are two informers registered with same type.
…Informers` to return list of registered informers + Add a new method `getExistingSharedIndexInformers()` to SharedInformerFactory which would return a list of entries containing registered SharedIndexInformer and their respective OperationContext. This is added to overcome limitation of old `getExistingSharedIndexInformer(Class<T> apiTypeClass)` in case there are two informers registered with same type.
…Informers` to return list of registered informers + Add a new method `getExistingSharedIndexInformers()` to SharedInformerFactory which would return a list of entries containing registered SharedIndexInformer and their respective OperationContext. This is added to overcome limitation of old `getExistingSharedIndexInformer(Class<T> apiTypeClass)` in case there are two informers registered with same type.
…` to return list of registered informers + Add a new method `getExistingSharedIndexInformers()` to SharedInformerFactory which would return a list of entries containing registered SharedIndexInformer and their respective OperationContext. This is added to overcome limitation of old `getExistingSharedIndexInformer(Class<T> apiTypeClass)` in case there are two informers registered with same type.
Relates to: #2010 |
The caching key of informers has changed in the client 5.2. And as far as I can see, the lookup function is not coherent with the create functions. The function
getExistingSharedIndexInformer
is sensitive to the name I chose for the Java class of my custom resource.For instance, if I have a custom resource under the API
com.acme/myapp:v1
, and that I have created the Java classMyAppCustomResource
annotated to be a proper fabric8CustomResource
, in the following codeexistingInformer
will benull
, but I would expect thatexistingInformer
is the same instance ascreatedInformer
.The text was updated successfully, but these errors were encountered: