|
1 | 1 | package io.javaoperatorsdk.operator.processing.event; |
2 | 2 |
|
3 | 3 | import java.lang.reflect.InvocationTargetException; |
| 4 | +import java.net.HttpURLConnection; |
4 | 5 | import java.util.function.Function; |
5 | 6 |
|
6 | 7 | import org.slf4j.Logger; |
7 | 8 | import org.slf4j.LoggerFactory; |
| 9 | +import org.slf4j.event.Level; |
8 | 10 |
|
9 | 11 | import io.fabric8.kubernetes.api.model.HasMetadata; |
10 | 12 | import io.fabric8.kubernetes.api.model.KubernetesResourceList; |
@@ -216,12 +218,35 @@ public boolean isLastAttempt() { |
216 | 218 | customResourceFacade.patchStatus( |
217 | 219 | errorStatusUpdateControl.getResource().orElseThrow(), originalResource); |
218 | 220 | } catch (Exception ex) { |
219 | | - log.error( |
220 | | - "updateErrorStatus failed for resource: {} with version: {} for error {}", |
221 | | - getUID(resource), |
222 | | - getVersion(resource), |
223 | | - e.getMessage(), |
224 | | - ex); |
| 221 | + int code = ex instanceof KubernetesClientException kcex ? kcex.getCode() : -1; |
| 222 | + Level exceptionLevel = Level.ERROR; |
| 223 | + String failedMessage = ""; |
| 224 | + if (context.isNextReconciliationImminent() |
| 225 | + || !(errorStatusUpdateControl.isNoRetry() || retryInfo.isLastAttempt())) { |
| 226 | + if (code == HttpURLConnection.HTTP_CONFLICT |
| 227 | + || (originalResource.getMetadata().getResourceVersion() != null && code == 422)) { |
| 228 | + exceptionLevel = Level.DEBUG; |
| 229 | + failedMessage = " due to conflict"; |
| 230 | + log.info( |
| 231 | + "ErrorStatusUpdateControl.patchStatus of {} failed due to a conflict, but the next" |
| 232 | + + " reconiliation is imminent.", |
| 233 | + ResourceID.fromResource(originalResource)); |
| 234 | + } else { |
| 235 | + exceptionLevel = Level.WARN; |
| 236 | + failedMessage = ", but will be retried soon,"; |
| 237 | + } |
| 238 | + } |
| 239 | + |
| 240 | + log.atLevel(exceptionLevel) |
| 241 | + .log( |
| 242 | + "ErrorStatusUpdateControl.patchStatus failed{} for {} with UID: {} and version: {}" |
| 243 | + + " for error {}", |
| 244 | + failedMessage, |
| 245 | + ResourceID.fromResource(originalResource), |
| 246 | + getUID(resource), |
| 247 | + getVersion(resource), |
| 248 | + e.getMessage(), |
| 249 | + ex); |
225 | 250 | } |
226 | 251 | } |
227 | 252 | if (errorStatusUpdateControl.isNoRetry()) { |
|
0 commit comments