|
1 | 1 | package io.javaoperatorsdk.operator.api.config;
|
2 | 2 |
|
3 |
| -import java.lang.reflect.ParameterizedType; |
4 | 3 | import java.util.Collections;
|
5 |
| -import java.util.Set; |
| 4 | +import java.util.List; |
6 | 5 |
|
7 | 6 | import io.fabric8.kubernetes.api.model.HasMetadata;
|
8 |
| -import io.fabric8.kubernetes.client.CustomResource; |
9 | 7 | import io.javaoperatorsdk.operator.ReconcilerUtils;
|
10 | 8 | import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;
|
11 |
| -import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilters; |
| 9 | +import io.javaoperatorsdk.operator.api.reconciler.Constants; |
| 10 | +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; |
12 | 11 |
|
13 |
| -public interface ControllerConfiguration<R extends HasMetadata> { |
| 12 | +public interface ControllerConfiguration<R extends HasMetadata> extends |
| 13 | + ResourceConfiguration<R, ControllerConfiguration<R>> { |
14 | 14 |
|
15 | 15 | default String getName() {
|
16 | 16 | return ReconcilerUtils.getDefaultReconcilerName(getAssociatedReconcilerClassName());
|
17 | 17 | }
|
18 | 18 |
|
19 |
| - default String getResourceTypeName() { |
20 |
| - return CustomResource.getCRDName(getResourceClass()); |
21 |
| - } |
22 |
| - |
23 | 19 | default String getFinalizer() {
|
24 | 20 | return ReconcilerUtils.getDefaultFinalizerName(getResourceTypeName());
|
25 | 21 | }
|
26 | 22 |
|
27 |
| - /** |
28 |
| - * Retrieves the label selector that is used to filter which custom resources are actually watched |
29 |
| - * by the associated controller. See |
30 |
| - * https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ for more details on |
31 |
| - * syntax. |
32 |
| - * |
33 |
| - * @return the label selector filtering watched custom resources |
34 |
| - */ |
35 |
| - default String getLabelSelector() { |
36 |
| - return null; |
37 |
| - } |
38 |
| - |
39 | 23 | default boolean isGenerationAware() {
|
40 | 24 | return true;
|
41 | 25 | }
|
42 | 26 |
|
43 |
| - default Class<R> getResourceClass() { |
44 |
| - ParameterizedType type = (ParameterizedType) getClass().getGenericInterfaces()[0]; |
45 |
| - return (Class<R>) type.getActualTypeArguments()[0]; |
46 |
| - } |
47 |
| - |
48 | 27 | String getAssociatedReconcilerClassName();
|
49 | 28 |
|
50 |
| - default Set<String> getNamespaces() { |
51 |
| - return Collections.emptySet(); |
52 |
| - } |
53 |
| - |
54 |
| - default boolean watchAllNamespaces() { |
55 |
| - return allNamespacesWatched(getNamespaces()); |
56 |
| - } |
57 |
| - |
58 |
| - static boolean allNamespacesWatched(Set<String> namespaces) { |
59 |
| - return namespaces == null || namespaces.isEmpty(); |
60 |
| - } |
61 |
| - |
62 |
| - default boolean watchCurrentNamespace() { |
63 |
| - return currentNamespaceWatched(getNamespaces()); |
64 |
| - } |
65 |
| - |
66 |
| - static boolean currentNamespaceWatched(Set<String> namespaces) { |
67 |
| - return namespaces != null |
68 |
| - && namespaces.size() == 1 |
69 |
| - && namespaces.contains( |
70 |
| - io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.WATCH_CURRENT_NAMESPACE); |
71 |
| - } |
72 |
| - |
73 |
| - /** |
74 |
| - * Computes the effective namespaces based on the set specified by the user, in particular |
75 |
| - * retrieves the current namespace from the client when the user specified that they wanted to |
76 |
| - * watch the current namespace only. |
77 |
| - * |
78 |
| - * @return a Set of namespace names the associated controller will watch |
79 |
| - */ |
80 |
| - default Set<String> getEffectiveNamespaces() { |
81 |
| - var targetNamespaces = getNamespaces(); |
82 |
| - if (watchCurrentNamespace()) { |
83 |
| - final var parent = getConfigurationService(); |
84 |
| - if (parent == null) { |
85 |
| - throw new IllegalStateException( |
86 |
| - "Parent ConfigurationService must be set before calling this method"); |
87 |
| - } |
88 |
| - targetNamespaces = Collections.singleton(parent.getClientConfiguration().getNamespace()); |
89 |
| - } |
90 |
| - return targetNamespaces; |
91 |
| - } |
92 |
| - |
93 | 29 | default RetryConfiguration getRetryConfiguration() {
|
94 | 30 | return RetryConfiguration.DEFAULT;
|
95 | 31 | }
|
96 | 32 |
|
97 |
| - ConfigurationService getConfigurationService(); |
98 |
| - |
99 |
| - default void setConfigurationService(ConfigurationService service) {} |
100 |
| - |
101 | 33 | default boolean useFinalizer() {
|
102 |
| - return !io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.NO_FINALIZER |
103 |
| - .equals(getFinalizer()); |
| 34 | + return !Constants.NO_FINALIZER.equals(getFinalizer()); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + default ResourceEventFilter<R, ControllerConfiguration<R>> getEventFilter() { |
| 39 | + return ResourceConfiguration.super.getEventFilter(); |
104 | 40 | }
|
105 | 41 |
|
106 |
| - /** |
107 |
| - * Allow controllers to filter events before they are provided to the |
108 |
| - * {@link io.javaoperatorsdk.operator.processing.event.EventHandler}. Note that the provided |
109 |
| - * filter is combined with {@link #isGenerationAware()} to compute the final set of fiolters that |
110 |
| - * should be applied; |
111 |
| - * |
112 |
| - * @return filter |
113 |
| - */ |
114 |
| - default ResourceEventFilter<R> getEventFilter() { |
115 |
| - return ResourceEventFilters.passthrough(); |
| 42 | + default List<? extends DependentResource> getDependentResources() { |
| 43 | + return Collections.emptyList(); |
116 | 44 | }
|
117 | 45 | }
|
0 commit comments