11
11
import io .fabric8 .kubernetes .client .dsl .Resource ;
12
12
import io .javaoperatorsdk .operator .api .ObservedGenerationAware ;
13
13
import io .javaoperatorsdk .operator .api .config .ControllerConfiguration ;
14
- import io .javaoperatorsdk .operator .api .reconciler .BaseControl ;
15
- import io .javaoperatorsdk .operator .api .reconciler .Context ;
16
- import io .javaoperatorsdk .operator .api .reconciler .DefaultContext ;
17
- import io .javaoperatorsdk .operator .api .reconciler .DeleteControl ;
18
- import io .javaoperatorsdk .operator .api .reconciler .ErrorStatusHandler ;
19
- import io .javaoperatorsdk .operator .api .reconciler .Reconciler ;
20
- import io .javaoperatorsdk .operator .api .reconciler .UpdateControl ;
14
+ import io .javaoperatorsdk .operator .api .reconciler .*;
21
15
import io .javaoperatorsdk .operator .processing .Controller ;
22
16
23
17
import static io .javaoperatorsdk .operator .processing .KubernetesResourceUtils .getName ;
@@ -114,7 +108,7 @@ private PostExecutionControl<R> handleReconcile(
114
108
cloneResourceForErrorStatusHandlerIfNeeded (originalResource , context );
115
109
return reconcileExecution (executionScope , resourceForExecution , originalResource , context );
116
110
} catch (RuntimeException e ) {
117
- handleLastAttemptErrorStatusHandler (originalResource , context , e );
111
+ handleErrorStatusHandler (originalResource , context , e );
118
112
throw e ;
119
113
}
120
114
}
@@ -128,7 +122,7 @@ private PostExecutionControl<R> handleReconcile(
128
122
* place for status update.
129
123
*/
130
124
private R cloneResourceForErrorStatusHandlerIfNeeded (R resource , Context context ) {
131
- if (isLastAttemptOfRetryAndErrorStatusHandlerPresent ( context ) ||
125
+ if (isErrorStatusHandlerPresent ( ) ||
132
126
shouldUpdateObservedGenerationAutomatically (resource )) {
133
127
return configuration ().getConfigurationService ().getResourceCloner ().clone (resource );
134
128
} else {
@@ -164,26 +158,32 @@ && shouldUpdateObservedGenerationAutomatically(resourceForExecution)) {
164
158
return createPostExecutionControl (updatedCustomResource , updateControl );
165
159
}
166
160
167
- private void handleLastAttemptErrorStatusHandler (R resource , Context context ,
161
+ private void handleErrorStatusHandler (R resource , Context context ,
168
162
RuntimeException e ) {
169
- if (isLastAttemptOfRetryAndErrorStatusHandlerPresent ( context )) {
163
+ if (isErrorStatusHandlerPresent ( )) {
170
164
try {
165
+ var retryInfo = context .getRetryInfo ().orElse (new RetryInfo () {
166
+ @ Override
167
+ public int getAttemptCount () {
168
+ return 0 ;
169
+ }
170
+
171
+ @ Override
172
+ public boolean isLastAttempt () {
173
+ return controller .getConfiguration ().getRetryConfiguration () == null ;
174
+ }
175
+ });
171
176
var updatedResource = ((ErrorStatusHandler <R >) controller .getReconciler ())
172
- .updateErrorStatus (resource , e );
173
- customResourceFacade . updateStatus ( updatedResource );
177
+ .updateErrorStatus (resource , retryInfo , e );
178
+ updatedResource . ifPresent ( customResourceFacade :: updateStatus );
174
179
} catch (RuntimeException ex ) {
175
180
log .error ("Error during error status handling." , ex );
176
181
}
177
182
}
178
183
}
179
184
180
- private boolean isLastAttemptOfRetryAndErrorStatusHandlerPresent (Context context ) {
181
- if (context .getRetryInfo ().isPresent ()) {
182
- return context .getRetryInfo ().get ().isLastAttempt ()
183
- && controller .getReconciler () instanceof ErrorStatusHandler ;
184
- } else {
185
- return false ;
186
- }
185
+ private boolean isErrorStatusHandlerPresent () {
186
+ return controller .getReconciler () instanceof ErrorStatusHandler ;
187
187
}
188
188
189
189
private R updateStatusGenerationAware (R resource ) {
0 commit comments