14
14
import java .util .Map ;
15
15
import java .util .concurrent .ConcurrentHashMap ;
16
16
17
+ import static io .javaoperatorsdk .operator .processing .ProcessingUtils .*;
18
+
17
19
/**
18
20
* Dispatches events to the Controller and handles Finalizers for a single type of Custom Resource.
19
21
*/
@@ -49,8 +51,10 @@ private PostExecutionControl handDispatch(ExecutionScope executionScope) {
49
51
CustomResource resource = executionScope .getCustomResource ();
50
52
log .debug ("Handling events: {} for resource {}" , executionScope .getEvents (), resource .getMetadata ());
51
53
52
- if (ProcessingUtils . containsCustomResourceDeletedEvent (executionScope .getEvents ())) {
54
+ if (containsCustomResourceDeletedEvent (executionScope .getEvents ())) {
53
55
cleanup (executionScope .getCustomResource ());
56
+ log .debug ("Skipping dispatch processing because of a Delete event: {} with version: {}" ,
57
+ getUID (resource ), getVersion (resource ));
54
58
return PostExecutionControl .defaultDispatch ();
55
59
}
56
60
if ((markedForDeletion (resource ) && !ControllerUtils .hasGivenFinalizer (resource , resourceFinalizer ))) {
@@ -76,19 +80,27 @@ private PostExecutionControl handleCreateOrUpdate(ExecutionScope executionScope,
76
80
return PostExecutionControl .onlyFinalizerAdded ();
77
81
} else {
78
82
if (!skipBecauseOfGenerations (executionScope )) {
83
+ log .debug ("Executing createOrUpdate for resource {} with version: {} with execution scope: {}" ,
84
+ getUID (resource ), getVersion (resource ), executionScope );
79
85
UpdateControl <? extends CustomResource > updateControl = controller .createOrUpdateResource (resource , context );
80
86
if (updateControl .isUpdateStatusSubResource ()) {
81
87
customResourceFacade .updateStatus (updateControl .getCustomResource ());
82
88
} else if (updateControl .isUpdateCustomResource ()) {
83
89
updateCustomResource (updateControl .getCustomResource ());
84
90
}
85
91
markLastGenerationProcessed (resource );
92
+ } else {
93
+ log .debug ("Skipping event processing because generations: {} with version: {}" ,
94
+ getUID (resource ), getVersion (resource ));
86
95
}
87
96
return PostExecutionControl .defaultDispatch ();
88
97
}
89
98
}
90
99
91
100
private boolean skipBecauseOfGenerations (ExecutionScope executionScope ) {
101
+ if (!generationAware ) {
102
+ return false ;
103
+ }
92
104
if (executionScope .getEvents ().size () == 1 ) {
93
105
Event <?> event = executionScope .getEvents ().get (0 );
94
106
if (event instanceof CustomResourceEvent ) {
@@ -104,14 +116,15 @@ private boolean skipBecauseOfGenerations(ExecutionScope executionScope) {
104
116
}
105
117
106
118
private PostExecutionControl handleDelete (CustomResource resource , Context context ) {
119
+ log .debug ("Executing delete for resource: {} with version: {}" , getUID (resource ), getVersion (resource ));
107
120
DeleteControl deleteControl = controller .deleteResource (resource , context );
108
121
boolean hasFinalizer = ControllerUtils .hasGivenFinalizer (resource , resourceFinalizer );
109
122
if (deleteControl == DeleteControl .DEFAULT_DELETE && hasFinalizer ) {
110
123
removeFinalizer (resource );
111
124
cleanup (resource );
112
125
} else {
113
- log .debug ("Skipping finalizer remove. delete control: {}, hasFinalizer: {} " ,
114
- deleteControl , hasFinalizer );
126
+ log .debug ("Skipping finalizer remove for resource: {} with version: {} . delete control: {}, hasFinalizer: {} " ,
127
+ getUID ( resource ), getVersion ( resource ), deleteControl , hasFinalizer );
115
128
}
116
129
return PostExecutionControl .defaultDispatch ();
117
130
}
@@ -138,22 +151,22 @@ private void markLastGenerationProcessed(CustomResource resource) {
138
151
}
139
152
140
153
private void updateCustomResourceWithFinalizer (CustomResource resource ) {
141
- log .debug ("Adding finalizer for resource: {} version: {}" , resource . getMetadata (). getName ( ),
142
- resource . getMetadata (). getResourceVersion ( ));
154
+ log .debug ("Adding finalizer for resource: {} version: {}" , getUID ( resource ),
155
+ getVersion ( resource ));
143
156
addFinalizerIfNotPresent (resource );
144
157
replace (resource );
145
158
}
146
159
147
- private void updateCustomResource (CustomResource updatedResource ) {
148
- log .debug ("Updating resource: {} with version: {}" , updatedResource . getMetadata (). getName ( ),
149
- updatedResource . getMetadata (). getResourceVersion ( ));
150
- log .trace ("Resource before update: {}" , updatedResource );
151
- replace (updatedResource );
160
+ private void updateCustomResource (CustomResource resource ) {
161
+ log .debug ("Updating resource: {} with version: {}" , getUID ( resource ),
162
+ getVersion ( resource ));
163
+ log .trace ("Resource before update: {}" , resource );
164
+ replace (resource );
152
165
}
153
166
154
167
155
168
private void removeFinalizer (CustomResource resource ) {
156
- log .debug ("Removing finalizer on resource {}: " , resource );
169
+ log .debug ("Removing finalizer on resource: {} with version: {} " , getUID ( resource ), getVersion ( resource ) );
157
170
resource .getMetadata ().getFinalizers ().remove (resourceFinalizer );
158
171
customResourceFacade .replaceWithLock (resource );
159
172
}
0 commit comments