Skip to content

Commit c9586d9

Browse files
committed
fix after rebase
1 parent a44a89f commit c9586d9

File tree

5 files changed

+49
-33
lines changed

5 files changed

+49
-33
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ public class AnnotationControllerConfiguration<P extends HasMetadata>
4545
private static final String KUBE_DEPENDENT_NAME = KubernetesDependent.class.getSimpleName();
4646

4747
protected final Reconciler<P> reconciler;
48-
private final ControllerConfiguration annotation;
48+
private final io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration annotation;
4949
private List<DependentResourceSpec> specs;
5050
private Class<P> resourceClass;
5151

5252
public AnnotationControllerConfiguration(Reconciler<P> reconciler) {
5353
this.reconciler = reconciler;
54-
this.annotation = reconciler.getClass().getAnnotation(ControllerConfiguration.class);
54+
this.annotation = reconciler.getClass()
55+
.getAnnotation(io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.class);
5556
if (annotation == null) {
5657
throw new OperatorException(
5758
"Missing mandatory @" + ControllerConfiguration.class.getSimpleName() +
@@ -328,7 +329,8 @@ private Object createKubernetesResourceConfig(Class<? extends DependentResource>
328329
private ResourceDiscriminator<?, ? extends HasMetadata> instantiateDiscriminatorIfNotVoid(
329330
Class<? extends ResourceDiscriminator> discriminator) {
330331
if (discriminator != VoidResourceDiscriminator.class) {
331-
return instantiateAndConfigureIfNeeded(discriminator, ResourceDiscriminator.class);
332+
return instantiateAndConfigureIfNeeded(discriminator, ResourceDiscriminator.class,
333+
CONTROLLER_CONFIG_ANNOTATION);
332334
}
333335
return null;
334336
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ public void run() {
107107
alreadyVisited.add(dependentResourceNode);
108108
boolean deletePostConditionMet =
109109
deletePostCondition.map(c -> c.isMet(primary,
110-
dependentResourceNode.getDependentResource().getSecondaryResource(primary)
110+
// todo pass also discriminator
111+
context
112+
.getSecondaryResource(
113+
dependentResourceNode.getDependentResource().resourceType())
111114
.orElse(null),
112115
context)).orElse(true);
113116
if (deletePostConditionMet) {

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ private synchronized <R> void handleReconcile(DependentResourceNode<R, P> depend
8686

8787
boolean reconcileConditionMet = dependentResourceNode.getReconcilePrecondition()
8888
.map(rc -> rc.isMet(primary,
89-
dependentResourceNode.getDependentResource().getSecondaryResource(primary).orElse(null),
89+
context
90+
.getSecondaryResource(dependentResourceNode.getDependentResource().resourceType())
91+
.orElse(null),
9092
context))
9193
.orElse(true);
9294

@@ -169,7 +171,9 @@ public void run() {
169171
reconciled.add(dependentResourceNode);
170172
boolean ready = dependentResourceNode.getReadyPostcondition()
171173
.map(rc -> rc.isMet(primary,
172-
dependentResourceNode.getDependentResource().getSecondaryResource(primary)
174+
context
175+
.getSecondaryResource(
176+
dependentResourceNode.getDependentResource().resourceType())
173177
.orElse(null),
174178
context))
175179
.orElse(true);
@@ -210,8 +214,8 @@ public void run() {
210214
}
211215
boolean deletePostConditionMet =
212216
deletePostCondition.map(c -> c.isMet(primary,
213-
dependentResourceNode.getDependentResource().getSecondaryResource(primary)
214-
.orElse(null),
217+
context.getSecondaryResource(
218+
dependentResourceNode.getDependentResource().resourceType()).orElse(null),
215219
context)).orElse(true);
216220
if (deletePostConditionMet) {
217221
alreadyVisited.add(dependentResourceNode);

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
import org.junit.jupiter.api.Test;
55

66
import io.javaoperatorsdk.operator.AggregatedOperatorException;
7+
import io.javaoperatorsdk.operator.api.reconciler.Context;
78
import io.javaoperatorsdk.operator.processing.dependent.workflow.builder.WorkflowBuilder;
89
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;
910

1011
import static io.javaoperatorsdk.operator.processing.dependent.workflow.ExecutionAssert.assertThat;
1112
import static org.junit.jupiter.api.Assertions.assertThrows;
13+
import static org.mockito.Mockito.mock;
1214

1315
class WorkflowCleanupExecutorTest extends AbstractWorkflowExecutorTest {
1416

1517
protected TestDeleterDependent dd1 = new TestDeleterDependent("DR_DELETER_1");
1618
protected TestDeleterDependent dd2 = new TestDeleterDependent("DR_DELETER_2");
1719
protected TestDeleterDependent dd3 = new TestDeleterDependent("DR_DELETER_3");
20+
Context<TestCustomResource> mockContext = mock(Context.class);
1821

1922
@Test
2023
void cleanUpDiamondWorkflow() {
@@ -45,7 +48,7 @@ void dontDeleteIfDependentErrored() {
4548
.withThrowExceptionFurther(false)
4649
.build();
4750

48-
var res = workflow.cleanup(new TestCustomResource(), null);
51+
var res = workflow.cleanup(new TestCustomResource(), mockContext);
4952
assertThrows(AggregatedOperatorException.class,
5053
res::throwAggregateExceptionIfErrorsPresent);
5154

@@ -64,7 +67,7 @@ void cleanupConditionTrivialCase() {
6467
.addDependentResource(dd2).dependsOn(dd1).withDeletePostcondition(noMetDeletePostCondition)
6568
.build();
6669

67-
var res = workflow.cleanup(new TestCustomResource(), null);
70+
var res = workflow.cleanup(new TestCustomResource(), mockContext);
6871

6972
assertThat(executionHistory).deleted(dd2).notReconciled(dd1);
7073
Assertions.assertThat(res.getDeleteCalledOnDependents()).containsExactlyInAnyOrder(dd2);
@@ -79,7 +82,7 @@ void cleanupConditionMet() {
7982
.addDependentResource(dd2).dependsOn(dd1).withDeletePostcondition(metDeletePostCondition)
8083
.build();
8184

82-
var res = workflow.cleanup(new TestCustomResource(), null);
85+
var res = workflow.cleanup(new TestCustomResource(), mockContext);
8386

8487
assertThat(executionHistory).deleted(dd2, dd1);
8588

@@ -99,7 +102,7 @@ void cleanupConditionDiamondWorkflow() {
99102
.addDependentResource(dd4).dependsOn(dd2, dd3)
100103
.build();
101104

102-
var res = workflow.cleanup(new TestCustomResource(), null);
105+
var res = workflow.cleanup(new TestCustomResource(), mockContext);
103106

104107
assertThat(executionHistory)
105108
.reconciledInOrder(dd4, dd2)

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

+25-21
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import org.junit.jupiter.api.Test;
55

66
import io.javaoperatorsdk.operator.AggregatedOperatorException;
7+
import io.javaoperatorsdk.operator.api.reconciler.Context;
78
import io.javaoperatorsdk.operator.processing.dependent.workflow.builder.WorkflowBuilder;
89
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;
910

1011
import static io.javaoperatorsdk.operator.processing.dependent.workflow.ExecutionAssert.assertThat;
1112
import static org.junit.jupiter.api.Assertions.assertThrows;
13+
import static org.mockito.Mockito.mock;
1214

1315
@SuppressWarnings("rawtypes")
1416
class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest {
@@ -21,14 +23,16 @@ class WorkflowReconcileExecutorTest extends AbstractWorkflowExecutorTest {
2123
private final Condition<String, TestCustomResource> notMetReadyCondition =
2224
(primary, secondary, context) -> false;
2325

26+
Context<TestCustomResource> mockContext = mock(Context.class);
27+
2428
@Test
2529
void reconcileTopLevelResources() {
2630
var workflow = new WorkflowBuilder<TestCustomResource>()
2731
.addDependentResource(dr1)
2832
.addDependentResource(dr2)
2933
.build();
3034

31-
var res = workflow.reconcile(new TestCustomResource(), null);
35+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
3236

3337
assertThat(executionHistory).reconciled(dr1, dr2);
3438
Assertions.assertThat(res.getErroredDependents()).isEmpty();
@@ -42,7 +46,7 @@ void reconciliationWithSimpleDependsOn() {
4246
.addDependentResource(dr2).dependsOn(dr1)
4347
.build();
4448

45-
var res = workflow.reconcile(new TestCustomResource(), null);
49+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
4650

4751
Assertions.assertThat(res.getErroredDependents()).isEmpty();
4852
assertThat(executionHistory).reconciledInOrder(dr1, dr2);
@@ -61,7 +65,7 @@ void reconciliationWithTwoTheDependsOns() {
6165
.addDependentResource(dr3).dependsOn(dr1)
6266
.build();
6367

64-
var res = workflow.reconcile(new TestCustomResource(), null);
68+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
6569

6670
Assertions.assertThat(res.getErroredDependents()).isEmpty();
6771
assertThat(executionHistory)
@@ -83,7 +87,7 @@ void diamondShareWorkflowReconcile() {
8387
.addDependentResource(dr4).dependsOn(dr3).dependsOn(dr2)
8488
.build();
8589

86-
var res = workflow.reconcile(new TestCustomResource(), null);
90+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
8791

8892
Assertions.assertThat(res.getErroredDependents()).isEmpty();
8993
assertThat(executionHistory)
@@ -103,7 +107,7 @@ void exceptionHandlingSimpleCases() {
103107
.withThrowExceptionFurther(false)
104108
.build();
105109

106-
var res = workflow.reconcile(new TestCustomResource(), null);
110+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
107111

108112
assertThrows(AggregatedOperatorException.class,
109113
res::throwAggregateExceptionIfErrorsPresent);
@@ -123,7 +127,7 @@ void dependentsOnErroredResourceNotReconciled() {
123127
.withThrowExceptionFurther(false)
124128
.build();
125129

126-
var res = workflow.reconcile(new TestCustomResource(), null);
130+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
127131
assertThrows(AggregatedOperatorException.class,
128132
res::throwAggregateExceptionIfErrorsPresent);
129133

@@ -145,7 +149,7 @@ void oneBranchErrorsOtherCompletes() {
145149
.withThrowExceptionFurther(false)
146150
.build();
147151

148-
var res = workflow.reconcile(new TestCustomResource(), null);
152+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
149153
assertThrows(AggregatedOperatorException.class,
150154
res::throwAggregateExceptionIfErrorsPresent);
151155

@@ -164,7 +168,7 @@ void onlyOneDependsOnErroredResourceNotReconciled() {
164168
.withThrowExceptionFurther(false)
165169
.build();
166170

167-
var res = workflow.reconcile(new TestCustomResource(), null);
171+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
168172
assertThrows(AggregatedOperatorException.class,
169173
res::throwAggregateExceptionIfErrorsPresent);
170174

@@ -182,7 +186,7 @@ void simpleReconcileCondition() {
182186
.addDependentResource(drDeleter).withReconcilePrecondition(not_met_reconcile_condition)
183187
.build();
184188

185-
var res = workflow.reconcile(new TestCustomResource(), null);
189+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
186190

187191
assertThat(executionHistory).notReconciled(dr1).reconciled(dr2).deleted(drDeleter);
188192
Assertions.assertThat(res.getErroredDependents()).isEmpty();
@@ -200,7 +204,7 @@ void triangleOnceConditionNotMet() {
200204
.dependsOn(dr1)
201205
.build();
202206

203-
var res = workflow.reconcile(new TestCustomResource(), null);
207+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
204208

205209
assertThat(executionHistory).reconciledInOrder(dr1, dr2).deleted(drDeleter);
206210
Assertions.assertThat(res.getErroredDependents()).isEmpty();
@@ -222,7 +226,7 @@ void reconcileConditionTransitiveDelete() {
222226
.withReconcilePrecondition(met_reconcile_condition)
223227
.build();
224228

225-
var res = workflow.reconcile(new TestCustomResource(), null);
229+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
226230

227231
Assertions.assertThat(res.getErroredDependents()).isEmpty();
228232
assertThat(executionHistory).notReconciled(dr2);
@@ -246,7 +250,7 @@ void reconcileConditionAlsoErrorDependsOn() {
246250
.withThrowExceptionFurther(false)
247251
.build();
248252

249-
var res = workflow.reconcile(new TestCustomResource(), null);
253+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
250254
assertThrows(AggregatedOperatorException.class,
251255
res::throwAggregateExceptionIfErrorsPresent);
252256

@@ -267,7 +271,7 @@ void oneDependsOnConditionNotMet() {
267271
.addDependentResource(drDeleter).dependsOn(dr1, dr2)
268272
.build();
269273

270-
var res = workflow.reconcile(new TestCustomResource(), null);
274+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
271275

272276
Assertions.assertThat(res.getErroredDependents()).isEmpty();
273277

@@ -287,7 +291,7 @@ void deletedIfReconcileConditionNotMet() {
287291
.addDependentResource(drDeleter2).dependsOn(dr1, drDeleter)
288292
.build();
289293

290-
var res = workflow.reconcile(new TestCustomResource(), null);
294+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
291295

292296
assertThat(executionHistory)
293297
.reconciledInOrder(dr1, drDeleter2, drDeleter)
@@ -313,7 +317,7 @@ void deleteDoneInReverseOrder() {
313317
.addDependentResource(drDeleter4).dependsOn(drDeleter3)
314318
.build();
315319

316-
var res = workflow.reconcile(new TestCustomResource(), null);
320+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
317321

318322
assertThat(executionHistory)
319323
.reconciledInOrder(dr1, drDeleter4, drDeleter3, drDeleter)
@@ -339,7 +343,7 @@ void diamondDeleteWithPostConditionInMiddle() {
339343
.addDependentResource(drDeleter4).dependsOn(drDeleter3, drDeleter2)
340344
.build();
341345

342-
var res = workflow.reconcile(new TestCustomResource(), null);
346+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
343347

344348
assertThat(executionHistory).notReconciled(drDeleter)
345349
.reconciledInOrder(drDeleter4, drDeleter2)
@@ -363,7 +367,7 @@ void diamondDeleteErrorInMiddle() {
363367
.withThrowExceptionFurther(false)
364368
.build();
365369

366-
var res = workflow.reconcile(new TestCustomResource(), null);
370+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
367371

368372
assertThat(executionHistory)
369373
.notReconciled(drDeleter, drError)
@@ -381,7 +385,7 @@ void readyConditionTrivialCase() {
381385
.addDependentResource(dr2).dependsOn(dr1)
382386
.build();
383387

384-
var res = workflow.reconcile(new TestCustomResource(), null);
388+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
385389

386390
assertThat(executionHistory).reconciledInOrder(dr1, dr2);
387391

@@ -397,7 +401,7 @@ void readyConditionNotMetTrivialCase() {
397401
.addDependentResource(dr2).dependsOn(dr1)
398402
.build();
399403

400-
var res = workflow.reconcile(new TestCustomResource(), null);
404+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
401405

402406

403407
assertThat(executionHistory).reconciled(dr1).notReconciled(dr2);
@@ -417,7 +421,7 @@ void readyConditionNotMetInOneParent() {
417421
.addDependentResource(dr3).dependsOn(dr1, dr2)
418422
.build();
419423

420-
var res = workflow.reconcile(new TestCustomResource(), null);
424+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
421425

422426
assertThat(executionHistory).reconciled(dr1, dr2).notReconciled(dr3);
423427
Assertions.assertThat(res.getErroredDependents()).isEmpty();
@@ -437,7 +441,7 @@ void diamondShareWithReadyCondition() {
437441
.addDependentResource(dr4).dependsOn(dr2, dr3)
438442
.build();
439443

440-
var res = workflow.reconcile(new TestCustomResource(), null);
444+
var res = workflow.reconcile(new TestCustomResource(), mockContext);
441445

442446
Assertions.assertThat(res.getErroredDependents()).isEmpty();
443447
assertThat(executionHistory).reconciledInOrder(dr1, dr2)

0 commit comments

Comments
 (0)