ferenc-csaky commented on code in PR #823:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/823#discussion_r1587630531
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/StatusRecorder.java:
##########
@@ -127,47 +128,65 @@ private void replaceStatus(CR resource, STATUS
prevStatus, KubernetesClient clie
} catch (KubernetesClientException kce) {
// 409 is the error code for conflicts resulting from the
locking
if (kce.getCode() == 409) {
- var currentVersion =
resource.getMetadata().getResourceVersion();
- LOG.debug(
- "Could not apply status update for resource
version {}",
- currentVersion);
-
- var latest = client.resource(resource).get();
- var latestVersion =
latest.getMetadata().getResourceVersion();
-
- if (latestVersion.equals(currentVersion)) {
- // This should not happen as long as the client works
consistently
- LOG.error("Unable to fetch latest resource version");
- throw kce;
- }
-
- if (latest.getStatus().equals(prevStatus)) {
- if (retries++ < 3) {
- LOG.debug(
- "Retrying status update for latest version
{}", latestVersion);
-
resource.getMetadata().setResourceVersion(latestVersion);
- } else {
- // If we cannot get the latest version in 3 tries
we throw the error to
- // retry with delay
- throw kce;
- }
- } else {
- throw new StatusConflictException(
- "Status have been modified externally in
version "
- + latestVersion
- + " Previous: "
- +
objectMapper.writeValueAsString(prevStatus)
- + " Latest: "
- +
objectMapper.writeValueAsString(latest.getStatus()));
- }
+ handleLockingError(resource, prevStatus, client, retries,
kce);
+ ++retries;
} else {
- // We simply throw non conflict errors, to trigger retry
with delay
+ // We simply throw non-conflict errors, to trigger retry
with delay
throw kce;
}
}
}
}
+ @VisibleForTesting
+ void handleLockingError(
+ CR resource,
+ STATUS prevStatus,
+ KubernetesClient client,
+ int retries,
+ KubernetesClientException kce)
+ throws JsonProcessingException {
+
+ var currentVersion = resource.getMetadata().getResourceVersion();
+ LOG.debug("Could not apply status update for resource version {}",
currentVersion);
+
+ var latest = client.resource(resource).get();
+ if (latest == null || latest.getMetadata() == null) {
+ // This can happen occasionally, we throw the error to retry with
delay.
+ throw new KubernetesClientException(
Review Comment:
Wrapped the original ex into a new one to make the added parts testable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]