-
Notifications
You must be signed in to change notification settings - Fork 223
feat: primary resource caching for followup reconciliation(s) #2761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
3aa6d17
feat: resource cache
csviri 0125d66
wip
csviri 8870c14
wip
csviri bff907c
wip
csviri 32823e0
wip
csviri b016bf0
wip
csviri 00fd9e6
wip
csviri 3b99f78
Integration tests
csviri 1812851
wip
csviri e09472a
fix
csviri 608fb09
Update operator-framework-core/src/main/java/io/javaoperatorsdk/opera…
csviri 21b2ef5
fix
csviri 870db57
additional test
csviri 9c58fd4
doc
csviri e481342
Update operator-framework-core/src/main/java/io/javaoperatorsdk/opera…
csviri 51f1ca0
Update operator-framework/src/test/java/io/javaoperatorsdk/operator/b…
csviri 3409053
Update operator-framework-core/src/main/java/io/javaoperatorsdk/opera…
csviri 68ca625
remove with lock versions
csviri 84eec7b
remove not used code
csviri 42b9ead
Revert "remove not used code"
csviri d51f0e3
Revert "remove with lock versions"
csviri 14c63bb
wip
csviri e9bcfbe
fix: typos and start improving javadoc
metacosm e8ede1a
refactor
csviri a71eafe
docs
csviri eff1ccb
Update operator-framework-core/src/main/java/io/javaoperatorsdk/opera…
csviri 217629f
Update operator-framework-core/src/main/java/io/javaoperatorsdk/opera…
csviri a8e7efc
Update docs/content/en/docs/documentation/reconciler.md
csviri a1d303d
Update operator-framework-core/src/main/java/io/javaoperatorsdk/opera…
csviri 7b58dca
Update docs/content/en/docs/documentation/reconciler.md
csviri a656160
improvements
csviri 1f1e1d0
docs
csviri 95a9f2e
improve
csviri 720a4c5
docs
csviri a510cc7
wip
csviri 0a79dd7
wip
csviri f12955b
fix: wording
metacosm 717933b
fix: wording & typos
metacosm 966aee7
add link for fabric8 configuration
csviri 68471f7
docs improve
csviri fb090a3
docs
csviri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Revert "remove with lock versions"
This reverts commit 68ca625.
- Loading branch information
commit d51f0e3cf27d6f08f48a2ac5b74b04f8eda4a6a0
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tatusPatchPrimaryCacheCustomResource.java → ...tatusPatchPrimaryCacheCustomResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tatuscache/StatusPatchPrimaryCacheIT.java → ...imarycache/StatusPatchPrimaryCacheIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tuscache/StatusPatchPrimaryCacheSpec.java → ...arycache/StatusPatchPrimaryCacheSpec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...scache/StatusPatchPrimaryCacheStatus.java → ...ycache/StatusPatchPrimaryCacheStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...atorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockCustomResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock; | ||
|
||
import io.fabric8.kubernetes.api.model.Namespaced; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.fabric8.kubernetes.model.annotation.Group; | ||
import io.fabric8.kubernetes.model.annotation.ShortNames; | ||
import io.fabric8.kubernetes.model.annotation.Version; | ||
|
||
@Group("sample.javaoperatorsdk") | ||
@Version("v1") | ||
@ShortNames("spcl") | ||
public class StatusPatchCacheWithLockCustomResource | ||
extends CustomResource<StatusPatchCacheWithLockSpec, StatusPatchCacheWithLockStatus> | ||
implements Namespaced {} |
48 changes: 48 additions & 0 deletions
48
.../io/javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock; | ||
|
||
import java.time.Duration; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
public class StatusPatchCacheWithLockIT { | ||
|
||
public static final String TEST_1 = "test1"; | ||
|
||
@RegisterExtension | ||
LocallyRunOperatorExtension extension = | ||
LocallyRunOperatorExtension.builder() | ||
.withReconciler(StatusPatchCacheWithLockReconciler.class) | ||
.build(); | ||
|
||
@Test | ||
void testStatusAlwaysUpToDate() { | ||
var reconciler = extension.getReconcilerOfType(StatusPatchCacheWithLockReconciler.class); | ||
|
||
extension.create(testResource()); | ||
|
||
// the reconciliation id periodically triggered, the status values should be increasing | ||
// monotonically | ||
await() | ||
.pollDelay(Duration.ofSeconds(1)) | ||
.pollInterval(Duration.ofMillis(30)) | ||
.untilAsserted( | ||
() -> { | ||
assertThat(reconciler.errorPresent).isFalse(); | ||
assertThat(reconciler.latestValue).isGreaterThan(10); | ||
csviri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
|
||
StatusPatchCacheWithLockCustomResource testResource() { | ||
var res = new StatusPatchCacheWithLockCustomResource(); | ||
res.setMetadata(new ObjectMetaBuilder().withName(TEST_1).build()); | ||
res.setSpec(new StatusPatchCacheWithLockSpec()); | ||
return res; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...operatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockReconciler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock; | ||
|
||
import java.util.List; | ||
|
||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; | ||
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; | ||
import io.javaoperatorsdk.operator.api.reconciler.PrimaryUpdateAndCacheUtils; | ||
import io.javaoperatorsdk.operator.api.reconciler.Reconciler; | ||
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; | ||
import io.javaoperatorsdk.operator.baseapi.statuscache.PeriodicTriggerEventSource; | ||
import io.javaoperatorsdk.operator.processing.event.source.EventSource; | ||
|
||
@ControllerConfiguration | ||
public class StatusPatchCacheWithLockReconciler | ||
implements Reconciler<StatusPatchCacheWithLockCustomResource> { | ||
|
||
public volatile int latestValue = 0; | ||
public volatile boolean errorPresent = false; | ||
|
||
@Override | ||
public UpdateControl<StatusPatchCacheWithLockCustomResource> reconcile( | ||
StatusPatchCacheWithLockCustomResource resource, | ||
Context<StatusPatchCacheWithLockCustomResource> context) | ||
throws InterruptedException { | ||
|
||
if (resource.getStatus() != null && resource.getStatus().getValue() != latestValue) { | ||
errorPresent = true; | ||
throw new IllegalStateException( | ||
"status is not up to date. Latest value: " | ||
+ latestValue | ||
+ " status values: " | ||
+ resource.getStatus().getValue()); | ||
} | ||
|
||
var freshCopy = createFreshCopy(resource); | ||
// setting the resource version | ||
freshCopy.getMetadata().setResourceVersion(resource.getMetadata().getResourceVersion()); | ||
freshCopy | ||
.getStatus() | ||
.setValue(resource.getStatus() == null ? 1 : resource.getStatus().getValue() + 1); | ||
|
||
var updated = | ||
PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatusWithLock(resource, freshCopy, context); | ||
latestValue = updated.getStatus().getValue(); | ||
|
||
return UpdateControl.noUpdate(); | ||
} | ||
|
||
@Override | ||
public List<EventSource<?, StatusPatchCacheWithLockCustomResource>> prepareEventSources( | ||
EventSourceContext<StatusPatchCacheWithLockCustomResource> context) { | ||
// periodic event triggering for testing purposes | ||
return List.of(new PeriodicTriggerEventSource<>(context.getPrimaryCache())); | ||
} | ||
|
||
private StatusPatchCacheWithLockCustomResource createFreshCopy( | ||
StatusPatchCacheWithLockCustomResource resource) { | ||
var res = new StatusPatchCacheWithLockCustomResource(); | ||
res.setMetadata( | ||
new ObjectMetaBuilder() | ||
.withName(resource.getMetadata().getName()) | ||
.withNamespace(resource.getMetadata().getNamespace()) | ||
.build()); | ||
res.setStatus(new StatusPatchCacheWithLockStatus()); | ||
|
||
return res; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...o/javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockSpec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock; | ||
|
||
public class StatusPatchCacheWithLockSpec { | ||
|
||
private int counter = 0; | ||
|
||
public int getCounter() { | ||
return counter; | ||
} | ||
|
||
public void setCounter(int counter) { | ||
this.counter = counter; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock; | ||
|
||
public class StatusPatchCacheWithLockStatus { | ||
|
||
private Integer value = 0; | ||
|
||
public Integer getValue() { | ||
return value; | ||
} | ||
|
||
public StatusPatchCacheWithLockStatus setValue(Integer value) { | ||
this.value = value; | ||
return this; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.