Skip to content

Commit 2d43aff

Browse files
committed
feat: field selectors support for InformerEventSource
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 301859a commit 2d43aff

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package io.javaoperatorsdk.operator.api.config.informer;
22

3+
import java.util.AbstractMap;
4+
import java.util.ArrayList;
35
import java.util.Collection;
46
import java.util.Collections;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
510
import java.util.Set;
611
import java.util.stream.Collectors;
712

@@ -36,6 +41,8 @@ public class InformerConfiguration<R extends HasMetadata> {
3641
private GenericFilter<? super R> genericFilter;
3742
private ItemStore<R> itemStore;
3843
private Long informerListLimit;
44+
private Map<String, String> withFields = new HashMap<>();
45+
private List<AbstractMap.SimpleEntry<String, String>> withoutFields = new ArrayList<>();
3946

4047
protected InformerConfiguration(
4148
Class<R> resourceClass,
@@ -264,6 +271,14 @@ public Long getInformerListLimit() {
264271
return informerListLimit;
265272
}
266273

274+
public Map<String, String> getWithFields() {
275+
return withFields;
276+
}
277+
278+
public List<AbstractMap.SimpleEntry<String, String>> getWithoutFields() {
279+
return withoutFields;
280+
}
281+
267282
@SuppressWarnings("UnusedReturnValue")
268283
public class Builder {
269284

@@ -424,5 +439,27 @@ public Builder withInformerListLimit(Long informerListLimit) {
424439
InformerConfiguration.this.informerListLimit = informerListLimit;
425440
return this;
426441
}
442+
443+
public Builder withField(String field, String value) {
444+
InformerConfiguration.this.withFields.put(field, value);
445+
return this;
446+
}
447+
448+
public Builder withFields(Map<String, String> fields) {
449+
InformerConfiguration.this.withFields.putAll(fields);
450+
return this;
451+
}
452+
453+
/**
454+
* Note that there can be more values for the same field. Like key != value1,key != value2.
455+
*
456+
* @param field key
457+
* @param value negated
458+
* @return builder
459+
*/
460+
public Builder withoutField(String field, String value) {
461+
InformerConfiguration.this.withoutFields.add(new AbstractMap.SimpleEntry<>(field, value));
462+
return this;
463+
}
427464
}
428465
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ private InformerWrapper<R> createEventSource(
134134
ResourceEventHandler<R> eventHandler,
135135
String namespaceIdentifier) {
136136
final var informerConfig = configuration.getInformerConfig();
137+
138+
if (!informerConfig.getWithFields().isEmpty()) {
139+
filteredBySelectorClient =
140+
filteredBySelectorClient.withFields(informerConfig.getWithFields());
141+
}
142+
143+
if (!informerConfig.getWithoutFields().isEmpty()) {
144+
for (var e : informerConfig.getWithoutFields()) {
145+
filteredBySelectorClient = filteredBySelectorClient.withoutField(e.getKey(), e.getValue());
146+
}
147+
}
148+
137149
var informer =
138150
Optional.ofNullable(informerConfig.getInformerListLimit())
139151
.map(filteredBySelectorClient::withLimit)

0 commit comments

Comments
 (0)