|
2 | 2 |
|
3 | 3 |
|
4 | 4 | import io.fabric8.kubernetes.client.CustomResource; |
| 5 | +import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationsImpl; |
5 | 6 | import io.javaoperatorsdk.operator.processing.event.*; |
6 | 7 | import org.slf4j.Logger; |
7 | 8 | import org.slf4j.LoggerFactory; |
@@ -103,13 +104,18 @@ void eventProcessingFinished(ExecutionScope executionScope, PostExecutionControl |
103 | 104 | * If an execution is finished, where we updated a custom resource, but there are other events already buffered for next |
104 | 105 | * execution we might not get the newest custom resource from CustomResource event source in time. Thus we execute |
105 | 106 | * the next batch of events but with a non up to date CR. Here we cache the latest CustomResource from the update |
106 | | - * execution so we make sure its already used in the up-comming execution. |
| 107 | + * execution so we make sure its already used in the up-coming execution. |
107 | 108 | */ |
108 | 109 | private void cacheUpdatedResourceIfChanged(ExecutionScope executionScope, PostExecutionControl postExecutionControl) { |
109 | 110 | if (postExecutionControl.customResourceUpdatedDuringExecution()) { |
| 111 | + |
110 | 112 | CustomResource originalCustomResource = executionScope.getCustomResource(); |
111 | 113 | CustomResource customResourceAfterExecution = postExecutionControl.getUpdatedCustomResource().get(); |
112 | | - if (!getVersion(originalCustomResource).equals(getVersion(customResourceAfterExecution))) { |
| 114 | + CustomResource cachedVersion = this.customResourceCache.getLatestResource(getUID(customResourceAfterExecution)).get(); |
| 115 | + String originalResourceVersion = getVersion(originalCustomResource); |
| 116 | + if (getVersion(cachedVersion).equals(originalResourceVersion) && !originalResourceVersion.equals(getVersion(customResourceAfterExecution))) { |
| 117 | + log.debug("Updating custom resource cache from update response for resource uid: {} new version: {} old version: {}", |
| 118 | + getUID(originalCustomResource), getVersion(customResourceAfterExecution), getVersion(originalCustomResource)); |
113 | 119 | this.customResourceCache.cacheResource(customResourceAfterExecution); |
114 | 120 | } |
115 | 121 | } |
|
0 commit comments