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
27
27
return new UpdateControl <>(customResource , true , false );
28
28
}
29
29
30
+ public static <T extends CustomResource >
31
+ UpdateControl <T > updateCustomResourceAndStatusSubResource (T customResource ) {
32
+ return new UpdateControl <>(customResource , true , true );
33
+ }
34
+
30
35
public static <T extends CustomResource > UpdateControl <T > noUpdate () {
31
36
return new UpdateControl <>(null , false , false );
32
37
}
@@ -42,4 +47,8 @@ public boolean isUpdateStatusSubResource() {
42
47
public boolean isUpdateCustomResource () {
43
48
return updateCustomResource ;
44
49
}
50
+
51
+ public boolean isUpdateCustomResourceAndStatusSubResource () {
52
+ return updateCustomResource && updateStatusSubResource ;
53
+ }
45
54
}
Original file line number Diff line number Diff line change @@ -103,12 +103,16 @@ private PostExecutionControl handleCreateOrUpdate(
103
103
UpdateControl <? extends CustomResource > updateControl =
104
104
controller .createOrUpdateResource (resource , context );
105
105
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 ()) {
107
110
updatedCustomResource =
108
111
customResourceFacade .updateStatus (updateControl .getCustomResource ());
109
112
} else if (updateControl .isUpdateCustomResource ()) {
110
113
updatedCustomResource = updateCustomResource (updateControl .getCustomResource ());
111
114
}
115
+
112
116
if (updatedCustomResource != null ) {
113
117
return PostExecutionControl .customResourceUpdated (updatedCustomResource );
114
118
} else {
Original file line number Diff line number Diff line change @@ -72,6 +72,19 @@ void updatesOnlyStatusSubResource() {
72
72
verify (customResourceFacade , never ()).replaceWithLock (any ());
73
73
}
74
74
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
+
75
88
@ Test
76
89
void callCreateOrUpdateOnModifiedResource () {
77
90
eventDispatcher .handleExecution (
You can’t perform that action at this time.
0 commit comments