|
1 | 1 | package io.javaoperatorsdk.operator.api.config.informer;
|
2 | 2 |
|
3 |
| -import java.util.Collections; |
4 | 3 | import java.util.Objects;
|
5 | 4 | import java.util.Set;
|
6 | 5 |
|
|
11 | 10 | import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper;
|
12 | 11 | import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers;
|
13 | 12 |
|
14 |
| -@SuppressWarnings("rawtypes") |
15 | 13 | public interface InformerConfiguration<R extends HasMetadata>
|
16 | 14 | extends ResourceConfiguration<R> {
|
17 | 15 |
|
@@ -72,34 +70,67 @@ public InformerConfigurationBuilder<R> withSecondaryToPrimaryMapper(
|
72 | 70 | }
|
73 | 71 |
|
74 | 72 | public InformerConfigurationBuilder<R> withNamespaces(String... namespaces) {
|
75 |
| - this.namespaces = namespaces != null ? Set.of(namespaces) : Collections.emptySet(); |
76 |
| - return this; |
| 73 | + return withNamespaces( |
| 74 | + namespaces != null ? Set.of(namespaces) : ResourceConfiguration.DEFAULT_NAMESPACES); |
77 | 75 | }
|
78 | 76 |
|
79 | 77 | public InformerConfigurationBuilder<R> withNamespaces(Set<String> namespaces) {
|
80 |
| - this.namespaces = namespaces != null ? namespaces : Collections.emptySet(); |
81 |
| - return this; |
82 |
| - } |
83 |
| - |
84 |
| - public InformerConfigurationBuilder<R> withLabelSelector(String labelSelector) { |
85 |
| - this.labelSelector = labelSelector; |
86 |
| - return this; |
| 78 | + return withNamespaces(namespaces, false); |
87 | 79 | }
|
88 | 80 |
|
89 |
| - public <P extends HasMetadata> InformerConfigurationBuilder<R> setAndFollowControllerNamespaceChanges( |
90 |
| - Set<String> namespaces) { |
91 |
| - this.namespaces = namespaces; |
| 81 | + /** |
| 82 | + * Sets the initial set of namespaces to watch (typically extracted from the parent |
| 83 | + * {@link io.javaoperatorsdk.operator.processing.Controller}'s configuration), specifying |
| 84 | + * whether changes made to the parent controller configured namespaces should be tracked or not. |
| 85 | + * |
| 86 | + * @param namespaces the initial set of namespaces to watch |
| 87 | + * @param followChanges {@code true} to follow the changes made to the parent controller |
| 88 | + * namespaces, {@code false} otherwise |
| 89 | + * @return the builder instance so that calls can be chained fluently |
| 90 | + */ |
| 91 | + public InformerConfigurationBuilder<R> withNamespaces(Set<String> namespaces, |
| 92 | + boolean followChanges) { |
| 93 | + this.namespaces = namespaces != null ? namespaces : ResourceConfiguration.DEFAULT_NAMESPACES; |
92 | 94 | this.inheritControllerNamespacesOnChange = true;
|
93 | 95 | return this;
|
94 | 96 | }
|
95 | 97 |
|
96 |
| - public <P extends HasMetadata> InformerConfigurationBuilder<R> setAndFollowControllerNamespaceChanges( |
| 98 | + /** |
| 99 | + * Configures the informer to watch and track the same namespaces as the parent |
| 100 | + * {@link io.javaoperatorsdk.operator.processing.Controller}, meaning that the informer will be |
| 101 | + * restarted to watch the new namespaces if the parent controller's namespace configuration |
| 102 | + * changes. |
| 103 | + * |
| 104 | + * @param context {@link EventSourceContext} from which the parent |
| 105 | + * {@link io.javaoperatorsdk.operator.processing.Controller}'s configuration is retrieved |
| 106 | + * @param <P> the primary resource type associated with the parent controller |
| 107 | + * @return the builder instance so that calls can be chained fluently |
| 108 | + */ |
| 109 | + public <P extends HasMetadata> InformerConfigurationBuilder<R> withNamespacesInheritedFromController( |
97 | 110 | EventSourceContext<P> context) {
|
98 | 111 | namespaces = context.getControllerConfiguration().getEffectiveNamespaces();
|
99 | 112 | this.inheritControllerNamespacesOnChange = true;
|
100 | 113 | return this;
|
101 | 114 | }
|
102 | 115 |
|
| 116 | + /** |
| 117 | + * Whether or not the associated informer should track changes made to the parent |
| 118 | + * {@link io.javaoperatorsdk.operator.processing.Controller}'s namespaces configuration. |
| 119 | + * |
| 120 | + * @param followChanges {@code true} to reconfigure the associated informer when the parent |
| 121 | + * controller's namespaces are reconfigured, {@code false} otherwise |
| 122 | + * @return the builder instance so that calls can be chained fluently |
| 123 | + */ |
| 124 | + public InformerConfigurationBuilder<R> followNamespaceChanges(boolean followChanges) { |
| 125 | + this.inheritControllerNamespacesOnChange = followChanges; |
| 126 | + return this; |
| 127 | + } |
| 128 | + |
| 129 | + public InformerConfigurationBuilder<R> withLabelSelector(String labelSelector) { |
| 130 | + this.labelSelector = labelSelector; |
| 131 | + return this; |
| 132 | + } |
| 133 | + |
103 | 134 | public InformerConfiguration<R> build() {
|
104 | 135 | return new DefaultInformerConfiguration<>(labelSelector, resourceClass,
|
105 | 136 | secondaryToPrimaryMapper,
|
|
0 commit comments