@@ -69,6 +69,28 @@ static void classSetup() {
69
69
* equals will fail on the two equal but NOT identical TestCustomResources because equals is not
70
70
* implemented on TestCustomResourceSpec or TestCustomResourceStatus
71
71
*/
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 ) {
72
94
configurationService =
73
95
ConfigurationService .newOverriddenConfigurationService (new BaseConfigurationService (),
74
96
overrider -> overrider .checkingCRDAndValidateLocalModel (false )
@@ -78,15 +100,7 @@ public <R extends HasMetadata> R clone(R object) {
78
100
return object ;
79
101
}
80
102
})
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 ));
90
104
}
91
105
92
106
private <R extends HasMetadata > ReconciliationDispatcher <R > init (R customResource ,
@@ -445,7 +459,7 @@ void setObservedGenerationForStatusIfNeeded() throws Exception {
445
459
}
446
460
447
461
@ Test
448
- void updatesObservedGenerationOnNoUpdateUpdateControl () throws Exception {
462
+ void doesNotUpdatesObservedGenerationIfStatusIsNotPatchedWhenUsingSSA () throws Exception {
449
463
var observedGenResource = createObservedGenCustomResource ();
450
464
451
465
Reconciler <ObservedGenCustomResource > reconciler = mock (Reconciler .class );
@@ -459,13 +473,11 @@ void updatesObservedGenerationOnNoUpdateUpdateControl() throws Exception {
459
473
460
474
PostExecutionControl <ObservedGenCustomResource > control = dispatcher .handleExecution (
461
475
executionScopeWithCREvent (observedGenResource ));
462
- assertThat (control .getUpdatedCustomResource ().orElseGet (() -> fail ("Missing optional" ))
463
- .getStatus ().getObservedGeneration ())
464
- .isEqualTo (1L );
476
+ assertThat (control .getUpdatedCustomResource ()).isEmpty ();
465
477
}
466
478
467
479
@ Test
468
- void patchObservedGenerationOnCustomResourceUpdate () throws Exception {
480
+ void patchObservedGenerationOnCustomResourcePatchIfNoSSA () throws Exception {
469
481
var observedGenResource = createObservedGenCustomResource ();
470
482
471
483
Reconciler <ObservedGenCustomResource > reconciler = mock (Reconciler .class );
@@ -476,6 +488,7 @@ void patchObservedGenerationOnCustomResourceUpdate() throws Exception {
476
488
.thenReturn (UpdateControl .patchResource (observedGenResource ));
477
489
when (facade .patchResource (any (), any ())).thenReturn (observedGenResource );
478
490
when (facade .patchStatus (eq (observedGenResource ), any ())).thenReturn (observedGenResource );
491
+ initConfigService (false );
479
492
var dispatcher = init (observedGenResource , reconciler , config , facade , true );
480
493
481
494
PostExecutionControl <ObservedGenCustomResource > control = dispatcher .handleExecution (
@@ -485,6 +498,25 @@ void patchObservedGenerationOnCustomResourceUpdate() throws Exception {
485
498
.isEqualTo (1L );
486
499
}
487
500
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
+
488
520
@ Test
489
521
void callErrorStatusHandlerIfImplemented () {
490
522
testCustomResource .addFinalizer (DEFAULT_FINALIZER );
@@ -670,6 +702,12 @@ void reSchedulesFromErrorHandler() {
670
702
assertThat (res .getRuntimeException ()).isEmpty ();
671
703
}
672
704
705
+ @ Test
706
+ void addsFinalizerToPatchWithSSA () {
707
+
708
+ }
709
+
710
+
673
711
private ObservedGenCustomResource createObservedGenCustomResource () {
674
712
ObservedGenCustomResource observedGenCustomResource = new ObservedGenCustomResource ();
675
713
observedGenCustomResource .setMetadata (new ObjectMeta ());
0 commit comments