-
Notifications
You must be signed in to change notification settings - Fork 232
removing tombstones #3013
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
removing tombstones #3013
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 |
|---|---|---|
|
|
@@ -96,18 +96,21 @@ class DefaultInformerEventSourceConfiguration<R extends HasMetadata> | |
| private final GroupVersionKind groupVersionKind; | ||
| private final InformerConfiguration<R> informerConfig; | ||
| private final KubernetesClient kubernetesClient; | ||
| private final boolean comparableResourceVersions; | ||
|
|
||
| protected DefaultInformerEventSourceConfiguration( | ||
| GroupVersionKind groupVersionKind, | ||
| PrimaryToSecondaryMapper<?> primaryToSecondaryMapper, | ||
| SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper, | ||
| InformerConfiguration<R> informerConfig, | ||
| KubernetesClient kubernetesClient) { | ||
| KubernetesClient kubernetesClient, | ||
| boolean comparableResourceVersions) { | ||
| this.informerConfig = Objects.requireNonNull(informerConfig); | ||
| this.groupVersionKind = groupVersionKind; | ||
| this.primaryToSecondaryMapper = primaryToSecondaryMapper; | ||
| this.secondaryToPrimaryMapper = secondaryToPrimaryMapper; | ||
| this.kubernetesClient = kubernetesClient; | ||
| this.comparableResourceVersions = comparableResourceVersions; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -135,6 +138,11 @@ public Optional<GroupVersionKind> getGroupVersionKind() { | |
| public Optional<KubernetesClient> getKubernetesClient() { | ||
| return Optional.ofNullable(kubernetesClient); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean parseResourceVersionsForEventFilteringAndCaching() { | ||
| return this.comparableResourceVersions; | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings({"unused", "UnusedReturnValue"}) | ||
|
|
@@ -148,6 +156,7 @@ class Builder<R extends HasMetadata> { | |
| private PrimaryToSecondaryMapper<?> primaryToSecondaryMapper; | ||
| private SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper; | ||
| private KubernetesClient kubernetesClient; | ||
| private boolean comparableResourceVersions = true; | ||
|
|
||
| private Builder(Class<R> resourceClass, Class<? extends HasMetadata> primaryResourceClass) { | ||
| this(resourceClass, primaryResourceClass, null); | ||
|
|
@@ -285,6 +294,11 @@ public Builder<R> withFieldSelector(FieldSelector fieldSelector) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder<R> parseResourceVersionsForEventFilteringAndCaching(boolean parse) { | ||
|
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.
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. I did this to be consistent with the other configuration for now. I can use a different name to start with here, or we can use a follow-up issue on how to approach the renaming in general. |
||
| this.comparableResourceVersions = parse; | ||
| return this; | ||
| } | ||
|
|
||
| public void updateFrom(InformerConfiguration<R> informerConfig) { | ||
| if (informerConfig != null) { | ||
| final var informerConfigName = informerConfig.getName(); | ||
|
|
@@ -324,7 +338,10 @@ public InformerEventSourceConfiguration<R> build() { | |
| HasMetadata.getKind(primaryResourceClass), | ||
| false)), | ||
| config.build(), | ||
| kubernetesClient); | ||
| kubernetesClient, | ||
| comparableResourceVersions); | ||
| } | ||
| } | ||
|
|
||
| boolean parseResourceVersionsForEventFilteringAndCaching(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,11 @@ public Optional<R> get(ResourceID resourceID) { | |
| : r); | ||
| } | ||
|
|
||
| public Optional<String> getLastSyncResourceVersion(Optional<String> namespace) { | ||
| return getSource(namespace.orElse(WATCH_ALL_NAMESPACES)) | ||
| .map(source -> source.getLastSyncResourceVersion()); | ||
|
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. nit: can be replaced by methode reference 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. Sorry, this can be removed - see #3015 |
||
| } | ||
|
|
||
| @Override | ||
| public Stream<ResourceID> keys() { | ||
| return sources.values().stream().flatMap(Cache::keys); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; | ||
| import io.javaoperatorsdk.operator.api.config.Informable; | ||
| import io.javaoperatorsdk.operator.api.config.NamespaceChangeable; | ||
| import io.javaoperatorsdk.operator.api.reconciler.PrimaryUpdateAndCacheUtils; | ||
| import io.javaoperatorsdk.operator.api.reconciler.dependent.RecentOperationCacheFiller; | ||
| import io.javaoperatorsdk.operator.health.InformerHealthIndicator; | ||
| import io.javaoperatorsdk.operator.health.InformerWrappingEventSourceHealthIndicator; | ||
|
|
@@ -122,30 +123,38 @@ public synchronized void stop() { | |
| @Override | ||
| public void handleRecentResourceUpdate( | ||
| ResourceID resourceID, R resource, R previousVersionOfResource) { | ||
| temporaryResourceCache.putResource( | ||
| resource, previousVersionOfResource.getMetadata().getResourceVersion()); | ||
| temporaryResourceCache.putResource(resource); | ||
| } | ||
|
|
||
| @Override | ||
| public void handleRecentResourceCreate(ResourceID resourceID, R resource) { | ||
| temporaryResourceCache.putAddedResource(resource); | ||
| temporaryResourceCache.putResource(resource); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<R> get(ResourceID resourceID) { | ||
| var res = cache.get(resourceID); | ||
| Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID); | ||
| if (resource.isPresent()) { | ||
| log.debug("Resource found in temporary cache for Resource ID: {}", resourceID); | ||
| if (parseResourceVersions | ||
| && resource.isPresent() | ||
| && res.filter( | ||
| r -> | ||
| PrimaryUpdateAndCacheUtils.compareResourceVersions(r, resource.orElseThrow()) | ||
| > 0) | ||
| .isEmpty()) { | ||
| log.debug("Latest resource found in temporary cache for Resource ID: {}", resourceID); | ||
| return resource; | ||
| } else { | ||
| log.debug( | ||
| "Resource not found in temporary cache reading it from informer cache," | ||
| + " for Resource ID: {}", | ||
| resourceID); | ||
| var res = cache.get(resourceID); | ||
| log.debug("Resource found in cache: {} for id: {}", res.isPresent(), resourceID); | ||
| return res; | ||
| } | ||
| log.debug( | ||
|
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. Would it make sense also to log if |
||
| "Resource not found, or older, in temporary cache. Found in informer cache {}, for" | ||
| + " Resource ID: {}", | ||
| res.isPresent(), | ||
| resourceID); | ||
| return res; | ||
| } | ||
|
|
||
| public Optional<String> getLastSyncResourceVersion(Optional<String> namespace) { | ||
| return cache.getLastSyncResourceVersion(namespace); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
|
|
||
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.
We should add this also to
@KubernetesDependentannotation.