|
2 | 2 |
|
3 | 3 | import java.util.Objects;
|
4 | 4 | import java.util.Optional;
|
5 |
| -import java.util.function.Consumer; |
| 5 | +import java.util.Set; |
6 | 6 |
|
7 | 7 | import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
|
8 | 8 | import io.fabric8.kubernetes.api.model.HasMetadata;
|
9 | 9 | import io.fabric8.kubernetes.client.KubernetesClient;
|
| 10 | +import io.fabric8.kubernetes.client.informers.cache.ItemStore; |
10 | 11 | import io.javaoperatorsdk.operator.api.config.Informable;
|
11 | 12 | import io.javaoperatorsdk.operator.processing.GroupVersionKind;
|
12 | 13 | import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper;
|
13 | 14 | import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper;
|
| 15 | +import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter; |
| 16 | +import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; |
| 17 | +import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter; |
| 18 | +import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; |
14 | 19 | import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers;
|
15 | 20 |
|
| 21 | +import static io.javaoperatorsdk.operator.api.reconciler.Constants.SAME_AS_CONTROLLER_NAMESPACES_SET; |
| 22 | +import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACE_SET; |
| 23 | +import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET; |
| 24 | + |
16 | 25 | public interface InformerEventSourceConfiguration<R extends HasMetadata>
|
17 | 26 | extends Informable<R> {
|
18 | 27 |
|
@@ -145,12 +154,6 @@ private Builder(Class<R> resourceClass,
|
145 | 154 | this.config = InformerConfiguration.builder(resourceClass);
|
146 | 155 | }
|
147 | 156 |
|
148 |
| - public Builder<R> withInformerConfiguration( |
149 |
| - Consumer<InformerConfiguration<R>.Builder> configurator) { |
150 |
| - configurator.accept(config); |
151 |
| - return this; |
152 |
| - } |
153 |
| - |
154 | 157 | public Builder<R> withName(String name) {
|
155 | 158 | this.name = name;
|
156 | 159 | config.withName(name);
|
@@ -187,6 +190,79 @@ public SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper() {
|
187 | 190 | return secondaryToPrimaryMapper;
|
188 | 191 | }
|
189 | 192 |
|
| 193 | + public Builder<R> withNamespaces(Set<String> namespaces) { |
| 194 | + config.withNamespaces(namespaces); |
| 195 | + return this; |
| 196 | + } |
| 197 | + |
| 198 | + public Builder<R> withNamespacesInheritedFromController() { |
| 199 | + withNamespaces(SAME_AS_CONTROLLER_NAMESPACES_SET); |
| 200 | + return this; |
| 201 | + } |
| 202 | + |
| 203 | + public Builder<R> withWatchAllNamespaces() { |
| 204 | + withNamespaces(WATCH_ALL_NAMESPACE_SET); |
| 205 | + return this; |
| 206 | + } |
| 207 | + |
| 208 | + public Builder<R> withWatchCurrentNamespace() { |
| 209 | + withNamespaces(WATCH_CURRENT_NAMESPACE_SET); |
| 210 | + return this; |
| 211 | + } |
| 212 | + |
| 213 | + |
| 214 | + /** |
| 215 | + * Whether the associated informer should track changes made to the parent |
| 216 | + * {@link io.javaoperatorsdk.operator.processing.Controller}'s namespaces configuration. |
| 217 | + * |
| 218 | + * @param followChanges {@code true} to reconfigure the associated informer when the parent |
| 219 | + * controller's namespaces are reconfigured, {@code false} otherwise |
| 220 | + * @return the builder instance so that calls can be chained fluently |
| 221 | + */ |
| 222 | + public Builder<R> withFollowControllerNamespacesChanges(boolean followChanges) { |
| 223 | + config.withFollowControllerNamespacesChanges(followChanges); |
| 224 | + return this; |
| 225 | + } |
| 226 | + |
| 227 | + public Builder<R> withLabelSelector(String labelSelector) { |
| 228 | + config.withLabelSelector(labelSelector); |
| 229 | + return this; |
| 230 | + } |
| 231 | + |
| 232 | + public Builder<R> withOnAddFilter( |
| 233 | + OnAddFilter<? super R> onAddFilter) { |
| 234 | + config.withOnAddFilter(onAddFilter); |
| 235 | + return this; |
| 236 | + } |
| 237 | + |
| 238 | + public Builder<R> withOnUpdateFilter( |
| 239 | + OnUpdateFilter<? super R> onUpdateFilter) { |
| 240 | + config.withOnUpdateFilter(onUpdateFilter); |
| 241 | + return this; |
| 242 | + } |
| 243 | + |
| 244 | + public Builder<R> withOnDeleteFilter( |
| 245 | + OnDeleteFilter<? super R> onDeleteFilter) { |
| 246 | + config.withOnDeleteFilter(onDeleteFilter); |
| 247 | + return this; |
| 248 | + } |
| 249 | + |
| 250 | + public Builder<R> withGenericFilter( |
| 251 | + GenericFilter<? super R> genericFilter) { |
| 252 | + config.withGenericFilter(genericFilter); |
| 253 | + return this; |
| 254 | + } |
| 255 | + |
| 256 | + public Builder<R> withItemStore(ItemStore<R> itemStore) { |
| 257 | + config.withItemStore(itemStore); |
| 258 | + return this; |
| 259 | + } |
| 260 | + |
| 261 | + public Builder<R> withInformerListLimit(Long informerListLimit) { |
| 262 | + config.withInformerListLimit(informerListLimit); |
| 263 | + return this; |
| 264 | + } |
| 265 | + |
190 | 266 | public void updateFrom(InformerConfiguration<R> informerConfig) {
|
191 | 267 | if (informerConfig != null) {
|
192 | 268 | final var informerConfigName = informerConfig.getName();
|
|
0 commit comments