|
| 1 | +package io.javaoperatorsdk.operator.processing.event.source; |
| 2 | + |
| 3 | +import java.util.Optional; |
| 4 | +import java.util.function.Predicate; |
| 5 | +import java.util.stream.Stream; |
| 6 | + |
| 7 | +import io.fabric8.kubernetes.api.model.HasMetadata; |
| 8 | +import io.fabric8.kubernetes.api.model.KubernetesResourceList; |
| 9 | +import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; |
| 10 | +import io.javaoperatorsdk.operator.api.config.Cloner; |
| 11 | +import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; |
| 12 | +import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfiguration; |
| 13 | +import io.javaoperatorsdk.operator.processing.event.ResourceID; |
| 14 | + |
| 15 | +public class DependentResourceEventSource<T extends HasMetadata, P extends HasMetadata> |
| 16 | + extends InformerEventSource<T, P> |
| 17 | + implements EventSourceWrapper<T>, ResourceEventSource<T, P> { |
| 18 | + private final DependentResourceConfiguration<T, P> configuration; |
| 19 | + |
| 20 | + public DependentResourceEventSource( |
| 21 | + FilterWatchListDeletable<T, KubernetesResourceList<T>> client, |
| 22 | + Cloner cloner, DependentResourceConfiguration<T, P> dependentConfiguration) { |
| 23 | + super(client.runnableInformer(0), |
| 24 | + dependentConfiguration.getPrimaryResourcesRetriever(), |
| 25 | + dependentConfiguration.getAssociatedResourceRetriever(), |
| 26 | + dependentConfiguration.skipUpdateIfUnchanged(), cloner); |
| 27 | + this.configuration = dependentConfiguration; |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public Optional<T> get(ResourceID resourceID) { |
| 32 | + return getCache().get(resourceID); |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public Stream<T> list(Predicate<T> predicate) { |
| 37 | + return getCache().list(predicate); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public Stream<T> list(String namespace, Predicate<T> predicate) { |
| 42 | + return getCache().list(namespace, predicate); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public ResourceCache<T> getResourceCache() { |
| 47 | + return getCache(); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public ResourceConfiguration<T, ? extends ResourceConfiguration> getConfiguration() { |
| 52 | + return configuration; |
| 53 | + } |
| 54 | +} |
0 commit comments