Skip to content

Commit 0953326

Browse files
committed
fix: reducing log level of failure to patch in handleErrorStatusHandler
closes: #2981 Signed-off-by: Steve Hawkins <[email protected]>
1 parent 87ec587 commit 0953326

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package io.javaoperatorsdk.operator.processing.event;
22

33
import java.lang.reflect.InvocationTargetException;
4+
import java.net.HttpURLConnection;
45
import java.util.function.Function;
56

67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
9+
import org.slf4j.event.Level;
810

911
import io.fabric8.kubernetes.api.model.HasMetadata;
1012
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
@@ -216,12 +218,35 @@ public boolean isLastAttempt() {
216218
customResourceFacade.patchStatus(
217219
errorStatusUpdateControl.getResource().orElseThrow(), originalResource);
218220
} 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);
225250
}
226251
}
227252
if (errorStatusUpdateControl.isNoRetry()) {

0 commit comments

Comments
 (0)