Skip to content

Commit 667b956

Browse files
committed
refactor: make WorkflowSpec an interface (#2300)
Signed-off-by: Chris Laprun <[email protected]> Signed-off-by: Attila Mészáros <[email protected]>
1 parent 5cdefa5 commit 667b956

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Set;
88
import java.util.concurrent.TimeUnit;
99
import java.util.function.Function;
10-
import java.util.stream.Collectors;
1110

1211
import org.slf4j.Logger;
1312
import org.slf4j.LoggerFactory;
@@ -168,8 +167,18 @@ protected <P extends HasMetadata> ControllerConfiguration<P> configFor(Reconcile
168167
final var workflowAnnotation = reconciler.getClass().getAnnotation(
169168
io.javaoperatorsdk.operator.api.reconciler.Workflow.class);
170169
if (workflowAnnotation != null) {
171-
List<DependentResourceSpec> specs = dependentResources(workflowAnnotation, config);
172-
WorkflowSpec workflowSpec = new WorkflowSpec(specs, workflowAnnotation.explicitInvocation());
170+
final var specs = dependentResources(workflowAnnotation, config);
171+
WorkflowSpec workflowSpec = new WorkflowSpec() {
172+
@Override
173+
public List<DependentResourceSpec> getDependentResourceSpecs() {
174+
return specs;
175+
}
176+
177+
@Override
178+
public boolean isExplicitInvocation() {
179+
return workflowAnnotation.explicitInvocation();
180+
}
181+
};
173182
config.setWorkflowSpec(workflowSpec);
174183
}
175184

@@ -212,7 +221,7 @@ private static List<DependentResourceSpec> dependentResources(
212221
eventSourceName);
213222
specsMap.put(dependentName, spec);
214223
}
215-
return specsMap.values().stream().collect(Collectors.toUnmodifiableList());
224+
return specsMap.values().stream().toList();
216225
}
217226

218227
protected boolean createIfNeeded() {

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

+3-16
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,10 @@
44

55
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
66

7-
public class WorkflowSpec {
7+
public interface WorkflowSpec {
88

99
@SuppressWarnings("rawtypes")
10-
private final List<DependentResourceSpec> dependentResourceSpecs;
11-
private final boolean explicitInvocation;
10+
List<DependentResourceSpec> getDependentResourceSpecs();
1211

13-
public WorkflowSpec(List<DependentResourceSpec> dependentResourceSpecs,
14-
boolean explicitInvocation) {
15-
this.dependentResourceSpecs = dependentResourceSpecs;
16-
this.explicitInvocation = explicitInvocation;
17-
}
18-
19-
public List<DependentResourceSpec> getDependentResourceSpecs() {
20-
return dependentResourceSpecs;
21-
}
22-
23-
public boolean isExplicitInvocation() {
24-
return explicitInvocation;
25-
}
12+
boolean isExplicitInvocation();
2613
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public void checkForNameDuplication(List<DependentResourceSpec> dependentResourc
3939
}
4040
}
4141

42-
public <P extends HasMetadata> ManagedWorkflow<P> createWorkflow(
43-
WorkflowSpec workflowSpec) {
44-
42+
public <P extends HasMetadata> ManagedWorkflow<P> createWorkflow(WorkflowSpec workflowSpec) {
4543
return createAsDefault(workflowSpec.getDependentResourceSpecs());
4644
}
4745

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,18 @@ void isCleanerIfHasDeleter() {
6262
@SuppressWarnings("unchecked")
6363
ManagedWorkflow managedWorkflow(DependentResourceSpec... specs) {
6464
final var configuration = mock(ControllerConfiguration.class);
65-
final var specList = List.of(specs);
6665

67-
var ws = new WorkflowSpec(specList, false);
66+
var ws = new WorkflowSpec() {
67+
@Override
68+
public List<DependentResourceSpec> getDependentResourceSpecs() {
69+
return List.of(specs);
70+
}
71+
72+
@Override
73+
public boolean isExplicitInvocation() {
74+
return false;
75+
}
76+
};
6877
when(configuration.getWorkflowSpec()).thenReturn(Optional.of(ws));
6978

7079
return new BaseConfigurationService().getWorkflowFactory()

0 commit comments

Comments
 (0)