@@ -130,7 +130,7 @@ void addFinalizerOnNewResource() {
130
130
verify (reconciler , never ())
131
131
.reconcile (ArgumentMatchers .eq (testCustomResource ), any ());
132
132
verify (customResourceFacade , times (1 ))
133
- .updateResource (
133
+ .replaceResourceWithLock (
134
134
argThat (testCustomResource -> testCustomResource .hasFinalizer (DEFAULT_FINALIZER )));
135
135
assertThat (testCustomResource .hasFinalizer (DEFAULT_FINALIZER )).isTrue ();
136
136
}
@@ -152,20 +152,20 @@ void updatesOnlyStatusSubResourceIfFinalizerSet() {
152
152
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
153
153
154
154
verify (customResourceFacade , times (1 )).patchStatus (eq (testCustomResource ), any ());
155
- verify (customResourceFacade , never ()).updateResource (any ());
155
+ verify (customResourceFacade , never ()).replaceResourceWithLock (any ());
156
156
}
157
157
158
158
@ Test
159
159
void updatesBothResourceAndStatusIfFinalizerSet () {
160
160
testCustomResource .addFinalizer (DEFAULT_FINALIZER );
161
161
162
162
reconciler .reconcile = (r , c ) -> UpdateControl .updateResourceAndStatus (testCustomResource );
163
- when (customResourceFacade .updateResource (testCustomResource ))
163
+ when (customResourceFacade .replaceResourceWithLock (testCustomResource ))
164
164
.thenReturn (testCustomResource );
165
165
166
166
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
167
167
168
- verify (customResourceFacade , times (1 )).updateResource (testCustomResource );
168
+ verify (customResourceFacade , times (1 )).replaceResourceWithLock (testCustomResource );
169
169
verify (customResourceFacade , times (1 )).updateStatus (testCustomResource );
170
170
}
171
171
@@ -179,7 +179,7 @@ void patchesStatus() {
179
179
180
180
verify (customResourceFacade , times (1 )).patchStatus (eq (testCustomResource ), any ());
181
181
verify (customResourceFacade , never ()).updateStatus (any ());
182
- verify (customResourceFacade , never ()).updateResource (any ());
182
+ verify (customResourceFacade , never ()).replaceResourceWithLock (any ());
183
183
}
184
184
185
185
@ Test
@@ -211,7 +211,7 @@ void removesDefaultFinalizerOnDeleteIfSet() {
211
211
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
212
212
213
213
assertThat (postExecControl .isFinalizerRemoved ()).isTrue ();
214
- verify (customResourceFacade , times (1 )).updateResource (testCustomResource );
214
+ verify (customResourceFacade , times (1 )).replaceResourceWithLock (testCustomResource );
215
215
}
216
216
217
217
@ Test
@@ -220,7 +220,7 @@ void retriesFinalizerRemovalWithFreshResource() {
220
220
markForDeletion (testCustomResource );
221
221
var resourceWithFinalizer = TestUtils .testCustomResource ();
222
222
resourceWithFinalizer .addFinalizer (DEFAULT_FINALIZER );
223
- when (customResourceFacade .updateResource (testCustomResource ))
223
+ when (customResourceFacade .replaceResourceWithLock (testCustomResource ))
224
224
.thenThrow (new KubernetesClientException (null , 409 , null ))
225
225
.thenReturn (testCustomResource );
226
226
when (customResourceFacade .getResource (any (), any ())).thenReturn (resourceWithFinalizer );
@@ -229,15 +229,15 @@ void retriesFinalizerRemovalWithFreshResource() {
229
229
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
230
230
231
231
assertThat (postExecControl .isFinalizerRemoved ()).isTrue ();
232
- verify (customResourceFacade , times (2 )).updateResource (any ());
232
+ verify (customResourceFacade , times (2 )).replaceResourceWithLock (any ());
233
233
verify (customResourceFacade , times (1 )).getResource (any (), any ());
234
234
}
235
235
236
236
@ Test
237
237
void throwsExceptionIfFinalizerRemovalRetryExceeded () {
238
238
testCustomResource .addFinalizer (DEFAULT_FINALIZER );
239
239
markForDeletion (testCustomResource );
240
- when (customResourceFacade .updateResource (any ()))
240
+ when (customResourceFacade .replaceResourceWithLock (any ()))
241
241
.thenThrow (new KubernetesClientException (null , 409 , null ));
242
242
when (customResourceFacade .getResource (any (), any ()))
243
243
.thenAnswer ((Answer <TestCustomResource >) invocationOnMock -> createResourceWithFinalizer ());
@@ -249,7 +249,7 @@ void throwsExceptionIfFinalizerRemovalRetryExceeded() {
249
249
assertThat (postExecControl .getRuntimeException ()).isPresent ();
250
250
assertThat (postExecControl .getRuntimeException ().get ())
251
251
.isInstanceOf (OperatorException .class );
252
- verify (customResourceFacade , times (MAX_FINALIZER_REMOVAL_RETRY )).updateResource (any ());
252
+ verify (customResourceFacade , times (MAX_FINALIZER_REMOVAL_RETRY )).replaceResourceWithLock (any ());
253
253
verify (customResourceFacade , times (MAX_FINALIZER_REMOVAL_RETRY - 1 )).getResource (any (),
254
254
any ());
255
255
}
@@ -258,15 +258,15 @@ void throwsExceptionIfFinalizerRemovalRetryExceeded() {
258
258
void throwsExceptionIfFinalizerRemovalClientExceptionIsNotConflict () {
259
259
testCustomResource .addFinalizer (DEFAULT_FINALIZER );
260
260
markForDeletion (testCustomResource );
261
- when (customResourceFacade .updateResource (any ()))
261
+ when (customResourceFacade .replaceResourceWithLock (any ()))
262
262
.thenThrow (new KubernetesClientException (null , 400 , null ));
263
263
264
264
var res =
265
265
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
266
266
267
267
assertThat (res .getRuntimeException ()).isPresent ();
268
268
assertThat (res .getRuntimeException ().get ()).isInstanceOf (KubernetesClientException .class );
269
- verify (customResourceFacade , times (1 )).updateResource (any ());
269
+ verify (customResourceFacade , times (1 )).replaceResourceWithLock (any ());
270
270
verify (customResourceFacade , never ()).getResource (any (), any ());
271
271
}
272
272
@@ -312,7 +312,7 @@ void doesNotRemovesTheSetFinalizerIfTheDeleteNotMethodInstructsIt() {
312
312
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
313
313
314
314
assertEquals (1 , testCustomResource .getMetadata ().getFinalizers ().size ());
315
- verify (customResourceFacade , never ()).updateResource (any ());
315
+ verify (customResourceFacade , never ()).replaceResourceWithLock (any ());
316
316
}
317
317
318
318
@ Test
@@ -322,21 +322,21 @@ void doesNotUpdateTheResourceIfNoUpdateUpdateControlIfFinalizerSet() {
322
322
reconciler .reconcile = (r , c ) -> UpdateControl .noUpdate ();
323
323
324
324
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
325
- verify (customResourceFacade , never ()).updateResource (any ());
325
+ verify (customResourceFacade , never ()).replaceResourceWithLock (any ());
326
326
verify (customResourceFacade , never ()).updateStatus (testCustomResource );
327
327
}
328
328
329
329
@ Test
330
330
void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned () {
331
331
removeFinalizers (testCustomResource );
332
332
reconciler .reconcile = (r , c ) -> UpdateControl .noUpdate ();
333
- when (customResourceFacade .updateResource (any ())).thenReturn (testCustomResource );
333
+ when (customResourceFacade .replaceResourceWithLock (any ())).thenReturn (testCustomResource );
334
334
335
335
var postExecControl =
336
336
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
337
337
338
338
assertEquals (1 , testCustomResource .getMetadata ().getFinalizers ().size ());
339
- verify (customResourceFacade , times (1 )).updateResource (any ());
339
+ verify (customResourceFacade , times (1 )).replaceResourceWithLock (any ());
340
340
assertThat (postExecControl .updateIsStatusPatch ()).isFalse ();
341
341
assertThat (postExecControl .getUpdatedCustomResource ()).isPresent ();
342
342
}
@@ -348,7 +348,7 @@ void doesNotCallDeleteIfMarkedForDeletionButNotOurFinalizer() {
348
348
349
349
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
350
350
351
- verify (customResourceFacade , never ()).updateResource (any ());
351
+ verify (customResourceFacade , never ()).replaceResourceWithLock (any ());
352
352
verify (reconciler , never ()).cleanup (eq (testCustomResource ), any ());
353
353
}
354
354
@@ -474,7 +474,7 @@ void updateObservedGenerationOnCustomResourceUpdate() throws Exception {
474
474
when (config .isGenerationAware ()).thenReturn (true );
475
475
when (reconciler .reconcile (any (), any ()))
476
476
.thenReturn (UpdateControl .updateResource (observedGenResource ));
477
- when (facade .updateResource (any ())).thenReturn (observedGenResource );
477
+ when (facade .replaceResourceWithLock (any ())).thenReturn (observedGenResource );
478
478
when (facade .updateStatus (observedGenResource )).thenReturn (observedGenResource );
479
479
var dispatcher = init (observedGenResource , reconciler , config , facade , true );
480
480
@@ -640,7 +640,7 @@ void noRequestOnConditionalUpdates() {
640
640
@ Test
641
641
void conditionalUpdateSpecChangedNoStatus () {
642
642
testCustomResource .addFinalizer (DEFAULT_FINALIZER );
643
- when (customResourceFacade .updateResource (any ())).thenAnswer (a -> a .getArguments ()[0 ]);
643
+ when (customResourceFacade .replaceResourceWithLock (any ())).thenAnswer (a -> a .getArguments ()[0 ]);
644
644
645
645
reconciler .reconcile = (r , c ) -> {
646
646
// in this test the cloning is turned off for easier verification, but required here
@@ -652,7 +652,7 @@ void conditionalUpdateSpecChangedNoStatus() {
652
652
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
653
653
654
654
verify (customResourceFacade , never ()).patchStatus (any (), any ());
655
- verify (customResourceFacade , times (1 )).updateResource (any ());
655
+ verify (customResourceFacade , times (1 )).replaceResourceWithLock (any ());
656
656
}
657
657
658
658
private void checkConditionalUpdate (
@@ -664,7 +664,7 @@ private void checkConditionalUpdate(
664
664
reconciliationDispatcher .handleExecution (executionScopeWithCREvent (testCustomResource ));
665
665
666
666
verify (customResourceFacade , never ()).patchStatus (any (), any ());
667
- verify (customResourceFacade , never ()).updateResource (any ());
667
+ verify (customResourceFacade , never ()).replaceResourceWithLock (any ());
668
668
verify (customResourceFacade , never ()).updateStatus (any ());
669
669
}
670
670
0 commit comments