Skip to content

Commit b0f1447

Browse files
committed
test wip
Signed-off-by: Attila Mészáros <csviri@gmail.com>
1 parent d79eeb1 commit b0f1447

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

docs/documentation/v5-0-migration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ permalink: /docs/v5-0-migration
3333
6. `ConfigurationService.getTerminationTimeoutSeconds` and associated overriding mechanism have been removed,
3434
use `Operator.stop(Duration)` instead.
3535
7. `Operator.installShutdownHook()` has been removed, use `Operator.installShutdownHook(Duration)` instead
36+
8. SSA for patch finalizer etc
37+
TODO: explain usage, observed generation change handling etc - with SSA only for patch resources.

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ static void classSetup() {
6969
* equals will fail on the two equal but NOT identical TestCustomResources because equals is not
7070
* implemented on TestCustomResourceSpec or TestCustomResourceStatus
7171
*/
72+
initConfigService(true);
73+
// configurationService =
74+
// ConfigurationService.newOverriddenConfigurationService(new BaseConfigurationService(),
75+
// overrider -> overrider.checkingCRDAndValidateLocalModel(false)
76+
// .withResourceCloner(new Cloner() {
77+
// @Override
78+
// public <R extends HasMetadata> R clone(R object) {
79+
// return object;
80+
// }
81+
// })
82+
// .withUseSSAToPatchPrimaryResource(false));
83+
}
84+
85+
@BeforeEach
86+
void setup() {
87+
testCustomResource = TestUtils.testCustomResource();
88+
reconciler = spy(new TestReconciler());
89+
reconciliationDispatcher =
90+
init(testCustomResource, reconciler, null, customResourceFacade, true);
91+
}
92+
93+
static void initConfigService(boolean useSSA) {
7294
configurationService =
7395
ConfigurationService.newOverriddenConfigurationService(new BaseConfigurationService(),
7496
overrider -> overrider.checkingCRDAndValidateLocalModel(false)
@@ -78,15 +100,7 @@ public <R extends HasMetadata> R clone(R object) {
78100
return object;
79101
}
80102
})
81-
.withUseSSAToPatchPrimaryResource(false));
82-
}
83-
84-
@BeforeEach
85-
void setup() {
86-
testCustomResource = TestUtils.testCustomResource();
87-
reconciler = spy(new TestReconciler());
88-
reconciliationDispatcher =
89-
init(testCustomResource, reconciler, null, customResourceFacade, true);
103+
.withUseSSAToPatchPrimaryResource(useSSA));
90104
}
91105

92106
private <R extends HasMetadata> ReconciliationDispatcher<R> init(R customResource,
@@ -445,7 +459,7 @@ void setObservedGenerationForStatusIfNeeded() throws Exception {
445459
}
446460

447461
@Test
448-
void updatesObservedGenerationOnNoUpdateUpdateControl() throws Exception {
462+
void doesNotUpdatesObservedGenerationIfStatusIsNotPatchedWhenUsingSSA() throws Exception {
449463
var observedGenResource = createObservedGenCustomResource();
450464

451465
Reconciler<ObservedGenCustomResource> reconciler = mock(Reconciler.class);
@@ -459,13 +473,11 @@ void updatesObservedGenerationOnNoUpdateUpdateControl() throws Exception {
459473

460474
PostExecutionControl<ObservedGenCustomResource> control = dispatcher.handleExecution(
461475
executionScopeWithCREvent(observedGenResource));
462-
assertThat(control.getUpdatedCustomResource().orElseGet(() -> fail("Missing optional"))
463-
.getStatus().getObservedGeneration())
464-
.isEqualTo(1L);
476+
assertThat(control.getUpdatedCustomResource()).isEmpty();
465477
}
466478

467479
@Test
468-
void patchObservedGenerationOnCustomResourceUpdate() throws Exception {
480+
void patchObservedGenerationOnCustomResourcePatchIfNoSSA() throws Exception {
469481
var observedGenResource = createObservedGenCustomResource();
470482

471483
Reconciler<ObservedGenCustomResource> reconciler = mock(Reconciler.class);
@@ -476,6 +488,7 @@ void patchObservedGenerationOnCustomResourceUpdate() throws Exception {
476488
.thenReturn(UpdateControl.patchResource(observedGenResource));
477489
when(facade.patchResource(any(), any())).thenReturn(observedGenResource);
478490
when(facade.patchStatus(eq(observedGenResource), any())).thenReturn(observedGenResource);
491+
initConfigService(false);
479492
var dispatcher = init(observedGenResource, reconciler, config, facade, true);
480493

481494
PostExecutionControl<ObservedGenCustomResource> control = dispatcher.handleExecution(
@@ -485,6 +498,25 @@ void patchObservedGenerationOnCustomResourceUpdate() throws Exception {
485498
.isEqualTo(1L);
486499
}
487500

501+
@Test
502+
void doesNotPatchObservedGenerationOnCustomResourcePatch() throws Exception {
503+
var observedGenResource = createObservedGenCustomResource();
504+
505+
Reconciler<ObservedGenCustomResource> reconciler = mock(Reconciler.class);
506+
final var config = MockControllerConfiguration.forResource(ObservedGenCustomResource.class);
507+
CustomResourceFacade<ObservedGenCustomResource> facade = mock(CustomResourceFacade.class);
508+
when(config.isGenerationAware()).thenReturn(true);
509+
when(reconciler.reconcile(any(), any()))
510+
.thenReturn(UpdateControl.patchResource(observedGenResource));
511+
when(facade.patchResource(any(), any())).thenReturn(observedGenResource);
512+
when(facade.patchStatus(eq(observedGenResource), any())).thenReturn(observedGenResource);
513+
var dispatcher = init(observedGenResource, reconciler, config, facade, true);
514+
515+
PostExecutionControl<ObservedGenCustomResource> control = dispatcher.handleExecution(
516+
executionScopeWithCREvent(observedGenResource));
517+
assertThat(control.getUpdatedCustomResource()).isEmpty();
518+
}
519+
488520
@Test
489521
void callErrorStatusHandlerIfImplemented() {
490522
testCustomResource.addFinalizer(DEFAULT_FINALIZER);
@@ -670,6 +702,12 @@ void reSchedulesFromErrorHandler() {
670702
assertThat(res.getRuntimeException()).isEmpty();
671703
}
672704

705+
@Test
706+
void addsFinalizerToPatchWithSSA() {
707+
708+
}
709+
710+
673711
private ObservedGenCustomResource createObservedGenCustomResource() {
674712
ObservedGenCustomResource observedGenCustomResource = new ObservedGenCustomResource();
675713
observedGenCustomResource.setMetadata(new ObjectMeta());

0 commit comments

Comments
 (0)