-
Notifications
You must be signed in to change notification settings - Fork 223
fix: startup all resource indexing #2881
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 all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fa459d9
fix: startup resource cache access
csviri 12c2168
wip
csviri abde7f6
wip
csviri 6f5e6e3
complementary index
csviri 37fc1e0
test
csviri 240099a
fix
csviri 1e771e2
wip
csviri 1da8b91
logging
csviri 53c2155
cleanup on test
csviri 08c0d5e
lower limit
csviri e5aef30
wip
csviri 0c1b210
wip
csviri 3d797ce
wip
csviri e003db3
wip
csviri 17d40cc
wip
csviri 9e41f50
wip
csviri faf9bdf
improve:
csviri f9aafb8
Revert "improve:"
csviri f862506
fix
csviri d6c1a97
test
csviri 0c81798
wip
csviri 559845a
test fix
csviri 81073ca
revert it scale
csviri e0acdbd
wip
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
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
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
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
13 changes: 13 additions & 0 deletions
13
...eratorsdk/operator/baseapi/startsecondaryaccess/StartupSecondaryAccessCustomResource.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,13 @@ | ||
package io.javaoperatorsdk.operator.baseapi.startsecondaryaccess; | ||
|
||
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("ssac") | ||
public class StartupSecondaryAccessCustomResource extends CustomResource<Void, Void> | ||
implements Namespaced {} |
53 changes: 53 additions & 0 deletions
53
...va/io/javaoperatorsdk/operator/baseapi/startsecondaryaccess/StartupSecondaryAccessIT.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,53 @@ | ||
package io.javaoperatorsdk.operator.baseapi.startsecondaryaccess; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
|
||
import static io.javaoperatorsdk.operator.baseapi.startsecondaryaccess.StartupSecondaryAccessReconciler.LABEL_KEY; | ||
import static io.javaoperatorsdk.operator.baseapi.startsecondaryaccess.StartupSecondaryAccessReconciler.LABEL_VALUE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
class StartupSecondaryAccessIT { | ||
|
||
public static final int SECONDARY_NUMBER = 200; | ||
|
||
@RegisterExtension | ||
static LocallyRunOperatorExtension extension = | ||
LocallyRunOperatorExtension.builder() | ||
.withReconciler(new StartupSecondaryAccessReconciler()) | ||
.withBeforeStartHook( | ||
ex -> { | ||
var primary = new StartupSecondaryAccessCustomResource(); | ||
primary.setMetadata(new ObjectMetaBuilder().withName("test1").build()); | ||
primary = ex.serverSideApply(primary); | ||
|
||
for (int i = 0; i < SECONDARY_NUMBER; i++) { | ||
ConfigMap cm = new ConfigMap(); | ||
cm.setMetadata( | ||
new ObjectMetaBuilder() | ||
.withLabels(Map.of(LABEL_KEY, LABEL_VALUE)) | ||
.withNamespace(ex.getNamespace()) | ||
.withName("cm" + i) | ||
.build()); | ||
cm.addOwnerReference(primary); | ||
ex.serverSideApply(cm); | ||
} | ||
}) | ||
.build(); | ||
|
||
@Test | ||
void reconcilerSeeAllSecondaryResources() { | ||
var reconciler = extension.getReconcilerOfType(StartupSecondaryAccessReconciler.class); | ||
|
||
await().untilAsserted(() -> assertThat(reconciler.isReconciled()).isTrue()); | ||
|
||
assertThat(reconciler.isSecondaryAndCacheSameAmount()).isTrue(); | ||
xstefank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...vaoperatorsdk/operator/baseapi/startsecondaryaccess/StartupSecondaryAccessReconciler.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,75 @@ | ||
package io.javaoperatorsdk.operator.baseapi.startsecondaryaccess; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; | ||
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.Reconciler; | ||
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; | ||
import io.javaoperatorsdk.operator.processing.event.source.EventSource; | ||
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource; | ||
|
||
import static io.javaoperatorsdk.operator.baseapi.startsecondaryaccess.StartupSecondaryAccessIT.SECONDARY_NUMBER; | ||
|
||
@ControllerConfiguration | ||
public class StartupSecondaryAccessReconciler | ||
implements Reconciler<StartupSecondaryAccessCustomResource> { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(StartupSecondaryAccessReconciler.class); | ||
|
||
public static final String LABEL_KEY = "app"; | ||
public static final String LABEL_VALUE = "secondary-test"; | ||
|
||
private InformerEventSource<ConfigMap, StartupSecondaryAccessCustomResource> cmInformer; | ||
|
||
private boolean secondaryAndCacheSameAmount = true; | ||
private boolean reconciled = false; | ||
|
||
@Override | ||
public UpdateControl<StartupSecondaryAccessCustomResource> reconcile( | ||
StartupSecondaryAccessCustomResource resource, | ||
Context<StartupSecondaryAccessCustomResource> context) { | ||
|
||
var secondary = context.getSecondaryResources(ConfigMap.class); | ||
var cached = cmInformer.list().toList(); | ||
|
||
log.info( | ||
"Secondary number: {}, cached: {}, expected: {}", | ||
secondary.size(), | ||
cached.size(), | ||
SECONDARY_NUMBER); | ||
|
||
if (secondary.size() != cached.size()) { | ||
secondaryAndCacheSameAmount = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not simply: secondaryAndCacheSameAmount = secondary.size() == cache.size(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would not work if later is the same value would overwrite the false, so here the aim is that if once false therefore always false |
||
} | ||
reconciled = true; | ||
return UpdateControl.noUpdate(); | ||
} | ||
|
||
@Override | ||
public List<EventSource<?, StartupSecondaryAccessCustomResource>> prepareEventSources( | ||
EventSourceContext<StartupSecondaryAccessCustomResource> context) { | ||
cmInformer = | ||
new InformerEventSource<>( | ||
InformerEventSourceConfiguration.from( | ||
ConfigMap.class, StartupSecondaryAccessCustomResource.class) | ||
.withLabelSelector(LABEL_KEY + "=" + LABEL_VALUE) | ||
.build(), | ||
context); | ||
return List.of(cmInformer); | ||
} | ||
|
||
public boolean isSecondaryAndCacheSameAmount() { | ||
return secondaryAndCacheSameAmount; | ||
} | ||
|
||
public boolean isReconciled() { | ||
return reconciled; | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need a "before-shutdown" hook as well to perform clean-up if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is usually not needed strictly , since one can clean the resources at the end of the test, so functionally that is doable. But agree that might be a nicer api.