Skip to content

Commit a9692d5

Browse files
committed
feat: spec now holds optional configuration
Signed-off-by: Chris Laprun <claprun@redhat.com>
1 parent 04846d9 commit a9692d5

File tree

9 files changed

+23
-18
lines changed

9 files changed

+23
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private static List<DependentResourceSpec> dependentResources(
224224
Utils.instantiate(dependent.reconcilePrecondition(), Condition.class, context),
225225
Utils.instantiate(dependent.deletePostcondition(), Condition.class, context),
226226
Utils.instantiate(dependent.activationCondition(), Condition.class, context),
227-
eventSourceName);
227+
eventSourceName, null); // todo: actually compute the configuration
228228
specsMap.put(dependentName, spec);
229229
}
230230
return specsMap.values().stream().toList();

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/ConfigurationConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
public interface ConfigurationConverter<A extends Annotation, C> {
99

1010
C configFrom(A configAnnotation, ControllerConfiguration<?> parentConfiguration,
11-
DependentResourceSpec<?, ?> spec, DependentResource<?, ?> dependentResource);
11+
DependentResourceSpec<?, ?, ?> spec, DependentResource<?, ?> dependentResource);
1212
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceSpec.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
99
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
1010

11-
public class DependentResourceSpec<R, P extends HasMetadata> {
11+
public class DependentResourceSpec<R, P extends HasMetadata, C> {
1212

1313
private final Class<? extends DependentResource<R, P>> dependentResourceClass;
1414

@@ -25,11 +25,12 @@ public class DependentResourceSpec<R, P extends HasMetadata> {
2525
private final Condition<?, ?> activationCondition;
2626

2727
private final String useEventSourceWithName;
28+
private final C nullableConfiguation;
2829

2930
public DependentResourceSpec(Class<? extends DependentResource<R, P>> dependentResourceClass,
3031
String name, Set<String> dependsOn, Condition<?, ?> readyCondition,
3132
Condition<?, ?> reconcileCondition, Condition<?, ?> deletePostCondition,
32-
Condition<?, ?> activationCondition, String useEventSourceWithName) {
33+
Condition<?, ?> activationCondition, String useEventSourceWithName, C nullableConfiguration) {
3334
this.dependentResourceClass = dependentResourceClass;
3435
this.name = name;
3536
this.dependsOn = dependsOn;
@@ -38,6 +39,7 @@ public DependentResourceSpec(Class<? extends DependentResource<R, P>> dependentR
3839
this.deletePostCondition = deletePostCondition;
3940
this.activationCondition = activationCondition;
4041
this.useEventSourceWithName = useEventSourceWithName;
42+
this.nullableConfiguation = nullableConfiguration;
4143
}
4244

4345
public Class<? extends DependentResource<R, P>> getDependentResourceClass() {
@@ -62,7 +64,7 @@ public boolean equals(Object o) {
6264
if (o == null || getClass() != o.getClass()) {
6365
return false;
6466
}
65-
DependentResourceSpec<?, ?> that = (DependentResourceSpec<?, ?>) o;
67+
DependentResourceSpec<?, ?, ?> that = (DependentResourceSpec<?, ?, ?>) o;
6668
return name.equals(that.name);
6769
}
6870

@@ -98,4 +100,8 @@ public Condition getActivationCondition() {
98100
public Optional<String> getUseEventSourceWithName() {
99101
return Optional.ofNullable(useEventSourceWithName);
100102
}
103+
104+
public Optional<C> getConfiguration() {
105+
return Optional.ofNullable(nullableConfiguation);
106+
}
101107
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class KubernetesDependentConverter<R extends HasMetadata, P extends HasMe
3434
@SuppressWarnings({"unchecked", "rawtypes"})
3535
public KubernetesDependentResourceConfig<R> configFrom(KubernetesDependent configAnnotation,
3636
ControllerConfiguration<?> controllerConfig,
37-
DependentResourceSpec<?, ?> spec, DependentResource<?, ?> dependentResource) {
37+
DependentResourceSpec<?, ?, ?> spec, DependentResource<?, ?> dependentResource) {
3838

3939
var createResourceOnlyIfNotExistingWithSSA =
4040
DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA;
@@ -48,7 +48,7 @@ public KubernetesDependentResourceConfig<R> configFrom(KubernetesDependent confi
4848

4949
var informerConfiguration = createInformerConfiguration(configAnnotation,
5050
controllerConfig,
51-
(DependentResourceSpec<R, P>) spec,
51+
(DependentResourceSpec<R, P, KubernetesDependentResourceConfig<R>>) spec,
5252
(DependentResource<R, P>) dependentResource);
5353

5454
return new KubernetesDependentResourceConfig(useSSA, createResourceOnlyIfNotExistingWithSSA,
@@ -59,7 +59,8 @@ public KubernetesDependentResourceConfig<R> configFrom(KubernetesDependent confi
5959
@SuppressWarnings({"unchecked", "rawtypes"})
6060
private InformerConfiguration<R> createInformerConfiguration(KubernetesDependent configAnnotation,
6161
ControllerConfiguration<?> controllerConfig,
62-
DependentResourceSpec<R, P> spec, DependentResource<R, P> dependentResource) {
62+
DependentResourceSpec<R, P, KubernetesDependentResourceConfig<R>> spec,
63+
DependentResource<R, P> dependentResource) {
6364
Class<? extends KubernetesDependentResource<?, ?>> dependentResourceClass =
6465
(Class<? extends KubernetesDependentResource<?, ?>>) spec.getDependentResourceClass();
6566
var resourceType = dependentResource.resourceType();

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected DefaultManagedWorkflow(List<DependentResourceSpec> orderedSpecs, boole
3131
.map(DependentResourceSpec::getName)
3232
.collect(Collectors.toSet());
3333
this.orderedSpecs = orderedSpecs;
34-
for (DependentResourceSpec<?, ?> spec : orderedSpecs) {
34+
for (DependentResourceSpec<?, ?, ?> spec : orderedSpecs) {
3535
// add cycle detection?
3636
if (spec.getDependsOn().isEmpty()) {
3737
topLevelResources.add(spec.getName());
@@ -99,7 +99,7 @@ public Workflow<P> resolve(KubernetesClient client,
9999
}
100100

101101
@SuppressWarnings({"rawtypes", "unchecked"})
102-
private <R> DependentResource<R, P> resolve(DependentResourceSpec<R, P> spec,
102+
private <R> DependentResource<R, P> resolve(DependentResourceSpec<R, P, ?> spec,
103103
KubernetesClient client,
104104
ControllerConfiguration<P> configuration) {
105105
final DependentResource<R, P> dependentResource =

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public Object configFrom(Annotation configAnnotation,
136136
assertEquals(overriddenConverter, converter);
137137
}
138138

139-
private DependentResourceSpec<?, ?> specWithDependentClass(
139+
private DependentResourceSpec<?, ?, ?> specWithDependentClass(
140140
Class<? extends DependentResource> dr) {
141141
var spec = mock(DependentResourceSpec.class);
142142
when(spec.getDependentResourceClass()).thenReturn(dr);
@@ -243,7 +243,7 @@ private static class CustomConfigConverter
243243
@Override
244244
public CustomConfig configFrom(CustomAnnotation configAnnotation,
245245
io.javaoperatorsdk.operator.api.config.ControllerConfiguration<?> parentConfiguration,
246-
DependentResourceSpec<?, ?> spec, DependentResource<?, ?> dependentResource) {
246+
DependentResourceSpec<?, ?, ?> spec, DependentResource<?, ?> dependentResource) {
247247
if (configAnnotation == null) {
248248
return new CustomConfig(CONVERTER_PROVIDED_DEFAULT);
249249
} else {

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTestUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
import io.javaoperatorsdk.operator.processing.dependent.EmptyTestDependentResource;
1212
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource;
1313

14-
import static org.mockito.Mockito.mock;
15-
import static org.mockito.Mockito.when;
16-
import static org.mockito.Mockito.withSettings;
14+
import static org.mockito.Mockito.*;
1715

1816
@SuppressWarnings("rawtypes")
1917
public class ManagedWorkflowTestUtils {
2018

2119
@SuppressWarnings("unchecked")
2220
public static DependentResourceSpec createDRS(String name, String... dependOns) {
2321
return new DependentResourceSpec(EmptyTestDependentResource.class, name, Set.of(dependOns),
24-
null, null, null, null, null);
22+
null, null, null, null, null, null);
2523
}
2624

2725
public static DependentResourceSpec createDRSWithTraits(String name,

operator-framework/src/test/java/io/javaoperatorsdk/operator/config/BaseConfigurationServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ private static class CustomConfigConverter
509509
@Override
510510
public CustomConfig configFrom(CustomAnnotation configAnnotation,
511511
io.javaoperatorsdk.operator.api.config.ControllerConfiguration<?> parentConfiguration,
512-
DependentResourceSpec<?, ?> spec, DependentResource<?, ?> dependentResource) {
512+
DependentResourceSpec<?, ?, ?> spec, DependentResource<?, ?> dependentResource) {
513513
if (configAnnotation == null) {
514514
return new CustomConfig(CONVERTER_PROVIDED_DEFAULT);
515515
} else {

sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SchemaDependentResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static class ResourcePollerConfigConverter implements
128128
@Override
129129
public ResourcePollerConfig configFrom(SchemaConfig configAnnotation,
130130
ControllerConfiguration<?> parentConfiguration,
131-
DependentResourceSpec<?, ?> spec, DependentResource<?, ?> dependentResource) {
131+
DependentResourceSpec<?, ?, ?> spec, DependentResource<?, ?> dependentResource) {
132132
if (configAnnotation != null) {
133133
return new ResourcePollerConfig(Duration.ofMillis(configAnnotation.pollPeriod()),
134134
new MySQLDbConfig(configAnnotation.host(), String.valueOf(configAnnotation.port()),

0 commit comments

Comments
 (0)