|
14 | 14 | import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
|
15 | 15 | import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent;
|
16 | 16 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
|
| 17 | +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; |
| 18 | +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; |
17 | 19 | import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig;
|
18 | 20 | import io.javaoperatorsdk.operator.sample.readonly.ReadOnlyDependent;
|
19 | 21 |
|
20 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
21 | 23 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
| 24 | +import static org.junit.jupiter.api.Assertions.assertNull; |
22 | 25 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
23 | 26 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
24 | 27 |
|
25 | 28 | class AnnotationControllerConfigurationTest {
|
26 | 29 |
|
| 30 | + @Test |
| 31 | + void defaultValuesShouldBeConsistent() { |
| 32 | + final var configuration = new AnnotationControllerConfiguration<>(new SelectorReconciler()); |
| 33 | + final var annotated = extractDependentKubernetesResourceConfig(configuration, 1); |
| 34 | + final var unannotated = extractDependentKubernetesResourceConfig(configuration, 0); |
| 35 | + |
| 36 | + assertNull(annotated.labelSelector()); |
| 37 | + assertNull(unannotated.labelSelector()); |
| 38 | + } |
| 39 | + |
| 40 | + private KubernetesDependentResourceConfig extractDependentKubernetesResourceConfig( |
| 41 | + io.javaoperatorsdk.operator.api.config.ControllerConfiguration<?> configuration, int index) { |
| 42 | + return (KubernetesDependentResourceConfig) configuration.getDependentResources().get(index) |
| 43 | + .getDependentResourceConfiguration() |
| 44 | + .orElseThrow(); |
| 45 | + } |
| 46 | + |
27 | 47 | @Test
|
28 | 48 | void getDependentResources() {
|
29 | 49 | var configuration = new AnnotationControllerConfiguration<>(new NoDepReconciler());
|
@@ -144,4 +164,25 @@ public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap>
|
144 | 164 | return null;
|
145 | 165 | }
|
146 | 166 | }
|
| 167 | + |
| 168 | + @ControllerConfiguration(dependents = { |
| 169 | + @Dependent(type = SelectorReconciler.WithAnnotation.class), |
| 170 | + @Dependent(type = ReadOnlyDependent.class) |
| 171 | + }) |
| 172 | + private static class SelectorReconciler implements Reconciler<ConfigMap> { |
| 173 | + |
| 174 | + @Override |
| 175 | + public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) |
| 176 | + throws Exception { |
| 177 | + return null; |
| 178 | + } |
| 179 | + |
| 180 | + @KubernetesDependent |
| 181 | + private static class WithAnnotation extends KubernetesDependentResource<ConfigMap, ConfigMap> { |
| 182 | + |
| 183 | + public WithAnnotation() { |
| 184 | + super(ConfigMap.class); |
| 185 | + } |
| 186 | + } |
| 187 | + } |
147 | 188 | }
|
0 commit comments