-
Notifications
You must be signed in to change notification settings - Fork 242
Informer pools #3325
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
Informer pools #3325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,10 @@ | |
| import io.fabric8.kubernetes.client.KubernetesClient; | ||
| import io.javaoperatorsdk.operator.Operator; | ||
| import io.javaoperatorsdk.operator.api.monitoring.Metrics; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Experimental; | ||
| import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory; | ||
| import io.javaoperatorsdk.operator.processing.event.source.informer.pool.AbstractInformerPool; | ||
| import io.javaoperatorsdk.operator.processing.event.source.informer.pool.InformerPool; | ||
|
|
||
| @SuppressWarnings({"unused", "UnusedReturnValue"}) | ||
| public class ConfigurationServiceOverrider { | ||
|
|
@@ -53,6 +56,7 @@ public class ConfigurationServiceOverrider { | |
| private Set<Class<? extends HasMetadata>> defaultNonSSAResource; | ||
| private Boolean useSSAToPatchPrimaryResource; | ||
| private Boolean cloneSecondaryResourcesWhenGettingFromCache; | ||
| private InformerPool informerPool; | ||
|
|
||
| @SuppressWarnings("rawtypes") | ||
| private DependentResourceFactory dependentResourceFactory; | ||
|
|
@@ -176,6 +180,21 @@ public ConfigurationServiceOverrider withCloneSecondaryResourcesWhenGettingFromC | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Overrides the informer pool strategy used to create/share the informers backing the event | ||
| * sources. When not set, the default (informer-sharing) pool is used. | ||
| * | ||
| * <p>Custom strategies extend {@link AbstractInformerPool}, which already takes care of creating | ||
| * and starting the informers. | ||
| */ | ||
| @Experimental( | ||
| "Only the configuration API around informer pooling could still change in a" | ||
| + " non-backwards-compatible way, the pooling itself is prod ready.") | ||
| public ConfigurationServiceOverrider withInformerPool(AbstractInformerPool informerPool) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter should be
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, will fix this in a subsequent PR. |
||
| this.informerPool = informerPool; | ||
| return this; | ||
| } | ||
|
|
||
| public ConfigurationService build() { | ||
| return new BaseConfigurationService(original.getVersion(), cloner, client) { | ||
| @Override | ||
|
|
@@ -309,6 +328,15 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() { | |
| cloneSecondaryResourcesWhenGettingFromCache, | ||
| ConfigurationService::cloneSecondaryResourcesWhenGettingFromCache); | ||
| } | ||
|
|
||
| @Override | ||
| public InformerPool informerPool() { | ||
| if (informerPool == null) { | ||
| return super.informerPool(); | ||
| } | ||
| informerPool.setConfigurationService(this); | ||
| return informerPool; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; | ||
| import io.javaoperatorsdk.operator.api.config.Utils; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Constants; | ||
| import io.javaoperatorsdk.operator.processing.GroupVersionKind; | ||
| import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore; | ||
| import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; | ||
| import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; | ||
|
|
@@ -42,6 +43,7 @@ | |
| public class InformerConfiguration<R extends HasMetadata> { | ||
| private final Builder builder = new Builder(); | ||
| private final Class<R> resourceClass; | ||
| private final GroupVersionKind resourceGroupVersionKind; | ||
| private final String resourceTypeName; | ||
| private String name; | ||
| private Set<String> namespaces; | ||
|
|
@@ -59,6 +61,7 @@ public class InformerConfiguration<R extends HasMetadata> { | |
|
|
||
| protected InformerConfiguration( | ||
| Class<R> resourceClass, | ||
| GroupVersionKind resourceGroupVersionKind, | ||
| String name, | ||
| Set<String> namespaces, | ||
| boolean followControllerNamespaceChanges, | ||
|
|
@@ -74,7 +77,7 @@ protected InformerConfiguration( | |
| Boolean comparableResourceVersions, | ||
| // TODO for removal in major release | ||
| Duration ghostResourceCacheCheckInterval) { | ||
| this(resourceClass); | ||
| this(resourceClass, resourceGroupVersionKind); | ||
| this.name = name; | ||
| this.namespaces = namespaces; | ||
| this.followControllerNamespaceChanges = followControllerNamespaceChanges; | ||
|
|
@@ -90,9 +93,14 @@ protected InformerConfiguration( | |
| this.comparableResourceVersions = comparableResourceVersions; | ||
| } | ||
|
|
||
| private InformerConfiguration(Class<R> resourceClass) { | ||
| private InformerConfiguration(Class<R> resourceClass, GroupVersionKind resourceGroupVersionKind) { | ||
| this.resourceClass = resourceClass; | ||
| this.resourceGroupVersionKind = resourceGroupVersionKind; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like an either/or type of situation where either we have a resource class or we pass a GVK, no? The GVK should always be present and inferred (I think it should be possible to do so) from the resource class if that is what is provided. |
||
| this.resourceTypeName = | ||
| // note the direction: this is true for GenericKubernetesResource, but also when the | ||
| // resource | ||
| // class is a supertype of it - i.e. a plain HasMetadata, for which no type name can be | ||
| // resolved from @Group/@Version annotations | ||
| resourceClass.isAssignableFrom(GenericKubernetesResource.class) | ||
| // in general this is irrelevant now for secondary resources it is used just by | ||
| // controller | ||
|
|
@@ -101,17 +109,24 @@ private InformerConfiguration(Class<R> resourceClass) { | |
| : ReconcilerUtilsInternal.getResourceTypeName(resourceClass); | ||
| } | ||
|
|
||
| @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| public static <R extends HasMetadata> InformerConfiguration<R>.Builder builder( | ||
| Class<R> resourceClass, GroupVersionKind groupVersionKind) { | ||
| return new InformerConfiguration(resourceClass, groupVersionKind).builder; | ||
| } | ||
|
|
||
| @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| public static <R extends HasMetadata> InformerConfiguration<R>.Builder builder( | ||
| Class<R> resourceClass) { | ||
| return new InformerConfiguration(resourceClass).builder; | ||
| return new InformerConfiguration(resourceClass, null).builder; | ||
| } | ||
|
|
||
| @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| public static <R extends HasMetadata> InformerConfiguration<R>.Builder builder( | ||
| InformerConfiguration<R> original) { | ||
| return new InformerConfiguration( | ||
| original.resourceClass, | ||
| original.resourceGroupVersionKind, | ||
| original.name, | ||
| original.namespaces, | ||
| original.followControllerNamespaceChanges, | ||
|
|
@@ -305,6 +320,10 @@ public Long getInformerListLimit() { | |
| return informerListLimit; | ||
| } | ||
|
|
||
| public GroupVersionKind getResourceGroupVersionKind() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this was an afterthought (I mean the whole GenericKubernetesResource support), I wanted make this consistent with the resourceClass provided in this class too. Maybe we could have both optional and deprecate the old methods. Well just remove this on next. |
||
| return resourceGroupVersionKind; | ||
| } | ||
|
|
||
| public FieldSelector getFieldSelector() { | ||
| return fieldSelector; | ||
| } | ||
|
|
@@ -500,10 +519,20 @@ public Builder withInformerListLimit(Long informerListLimit) { | |
| } | ||
|
|
||
| public Builder withFieldSelector(FieldSelector fieldSelector) { | ||
| InformerConfiguration.this.fieldSelector = fieldSelector; | ||
| // an empty selector filters nothing, so it must not be distinguishable from having none at | ||
| // all: the informer pool keys on the field selector, and the annotation path always builds | ||
| // one (@Informer#fieldSelector defaults to {}) where the programmatic path leaves it null, | ||
| // which would otherwise stop the two from sharing an informer | ||
| InformerConfiguration.this.fieldSelector = isEmpty(fieldSelector) ? null : fieldSelector; | ||
| return this; | ||
| } | ||
|
|
||
| private static boolean isEmpty(FieldSelector fieldSelector) { | ||
| return fieldSelector == null | ||
| || fieldSelector.getFields() == null | ||
| || fieldSelector.getFields().isEmpty(); | ||
| } | ||
|
|
||
| public Builder withComparableResourceVersions(boolean comparableResourceVersions) { | ||
| InformerConfiguration.this.comparableResourceVersions = comparableResourceVersions; | ||
| return this; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,7 @@ default boolean followControllerNamespaceChanges() { | |
|
|
||
| <P extends HasMetadata> PrimaryToSecondaryMapper<P> getPrimaryToSecondaryMapper(); | ||
|
|
||
| // todo deprecate | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This same as ResourceClass, should be part of InformerConfiguration not the event source configuraiton
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, checking, but we don't use Optional on other values there either, so would just stick with this for now, maybe fix those in v6? |
||
| Optional<GroupVersionKind> getGroupVersionKind(); | ||
|
|
||
| default String name() { | ||
|
|
@@ -167,7 +168,7 @@ private Builder( | |
| this.resourceClass = resourceClass; | ||
| this.groupVersionKind = groupVersionKind; | ||
| this.primaryResourceClass = primaryResourceClass; | ||
| this.config = InformerConfiguration.builder(resourceClass); | ||
| this.config = InformerConfiguration.builder(resourceClass, groupVersionKind); | ||
| } | ||
|
|
||
| public Builder<R> withName(String name) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.