File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
main/java/io/javaoperatorsdk/operator
test/java/io/javaoperatorsdk/operator Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ public static <T extends CustomResource> UpdateControl<T> updateStatusSubResourc
2727 return new UpdateControl <>(customResource , true , false );
2828 }
2929
30+ public static <T extends CustomResource >
31+ UpdateControl <T > updateCustomResourceAndStatusSubResource (T customResource ) {
32+ return new UpdateControl <>(customResource , true , true );
33+ }
34+
3035 public static <T extends CustomResource > UpdateControl <T > noUpdate () {
3136 return new UpdateControl <>(null , false , false );
3237 }
@@ -42,4 +47,8 @@ public boolean isUpdateStatusSubResource() {
4247 public boolean isUpdateCustomResource () {
4348 return updateCustomResource ;
4449 }
50+
51+ public boolean isUpdateCustomResourceAndStatusSubResource () {
52+ return updateCustomResource && updateStatusSubResource ;
53+ }
4554}
Original file line number Diff line number Diff line change @@ -103,12 +103,16 @@ private PostExecutionControl handleCreateOrUpdate(
103103 UpdateControl <? extends CustomResource > updateControl =
104104 controller .createOrUpdateResource (resource , context );
105105 CustomResource updatedCustomResource = null ;
106- if (updateControl .isUpdateStatusSubResource ()) {
106+ if (updateControl .isUpdateCustomResourceAndStatusSubResource ()) {
107+ updatedCustomResource = updateCustomResource (updateControl .getCustomResource ());
108+ updatedCustomResource = customResourceFacade .updateStatus (updatedCustomResource );
109+ } else if (updateControl .isUpdateStatusSubResource ()) {
107110 updatedCustomResource =
108111 customResourceFacade .updateStatus (updateControl .getCustomResource ());
109112 } else if (updateControl .isUpdateCustomResource ()) {
110113 updatedCustomResource = updateCustomResource (updateControl .getCustomResource ());
111114 }
115+
112116 if (updatedCustomResource != null ) {
113117 return PostExecutionControl .customResourceUpdated (updatedCustomResource );
114118 } else {
Original file line number Diff line number Diff line change @@ -72,6 +72,19 @@ void updatesOnlyStatusSubResource() {
7272 verify (customResourceFacade , never ()).replaceWithLock (any ());
7373 }
7474
75+ @ Test
76+ void updatesBothResourceAndStatus () {
77+ when (controller .createOrUpdateResource (eq (testCustomResource ), any ()))
78+ .thenReturn (UpdateControl .updateCustomResourceAndStatusSubResource (testCustomResource ));
79+ when (customResourceFacade .replaceWithLock (testCustomResource )).thenReturn (testCustomResource );
80+
81+ eventDispatcher .handleExecution (
82+ executionScopeWithCREvent (Watcher .Action .MODIFIED , testCustomResource ));
83+
84+ verify (customResourceFacade , times (1 )).replaceWithLock (testCustomResource );
85+ verify (customResourceFacade , times (1 )).updateStatus (testCustomResource );
86+ }
87+
7588 @ Test
7689 void callCreateOrUpdateOnModifiedResource () {
7790 eventDispatcher .handleExecution (
You can’t perform that action at this time.
0 commit comments