-
Notifications
You must be signed in to change notification settings - Fork 218
feat: operator can be restarted #1675
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
863016d
feat: operator can be restarted
csviri 3dae636
wip
csviri 508fec1
wip
csviri e59ab20
fixes
csviri 14727af
remove not used flag
csviri b3749d3
indexer fix
csviri 71635d7
improvemets
csviri 2a3a9e0
wip
csviri b29500f
fix: avoid NPE on stop if things were not started
metacosm 64f15fc
chore: make test more "realistic"
metacosm 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
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
63 changes: 63 additions & 0 deletions
63
operator-framework/src/test/java/io/javaoperatorsdk/operator/OperatorRestartIT.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,63 @@ | ||
package io.javaoperatorsdk.operator; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClientBuilder; | ||
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
import io.javaoperatorsdk.operator.sample.restart.RestartTestCustomResource; | ||
import io.javaoperatorsdk.operator.sample.restart.RestartTestReconciler; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
class OperatorRestartIT { | ||
private final static KubernetesClient client = new KubernetesClientBuilder().build(); | ||
private final static Operator operator = new Operator(o -> o.withCloseClientOnStop(false)); | ||
private final static RestartTestReconciler reconciler = new RestartTestReconciler(); | ||
private static int reconcileNumberBeforeStop = 0; | ||
|
||
@BeforeAll | ||
static void registerReconciler() { | ||
LocallyRunOperatorExtension.applyCrd(RestartTestCustomResource.class, client); | ||
operator.register(reconciler); | ||
} | ||
|
||
@BeforeEach | ||
void startOperator() { | ||
operator.start(); | ||
} | ||
|
||
@AfterEach | ||
void stopOperator() { | ||
operator.stop(); | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
void createResource() { | ||
client.resource(testCustomResource()).createOrReplace(); | ||
await().untilAsserted(() -> assertThat(reconciler.getNumberOfExecutions()).isGreaterThan(0)); | ||
reconcileNumberBeforeStop = reconciler.getNumberOfExecutions(); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
void reconcile() { | ||
await().untilAsserted(() -> assertThat(reconciler.getNumberOfExecutions()) | ||
.isGreaterThan(reconcileNumberBeforeStop)); | ||
} | ||
|
||
RestartTestCustomResource testCustomResource() { | ||
RestartTestCustomResource cr = new RestartTestCustomResource(); | ||
cr.setMetadata(new ObjectMetaBuilder() | ||
.withName("test1") | ||
.build()); | ||
return cr; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../src/test/java/io/javaoperatorsdk/operator/sample/restart/ConfigMapDependentResource.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,35 @@ | ||
package io.javaoperatorsdk.operator.sample.restart; | ||
|
||
import java.util.Map; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.ConfigMapBuilder; | ||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; | ||
|
||
@KubernetesDependent(labelSelector = "app=restart-test") | ||
public class ConfigMapDependentResource | ||
extends CRUDKubernetesDependentResource<ConfigMap, RestartTestCustomResource> { | ||
|
||
public static final String DATA_KEY = "key"; | ||
|
||
public ConfigMapDependentResource() { | ||
super(ConfigMap.class); | ||
} | ||
|
||
@Override | ||
protected ConfigMap desired(RestartTestCustomResource primary, | ||
Context<RestartTestCustomResource> context) { | ||
return new ConfigMapBuilder() | ||
.withMetadata(new ObjectMetaBuilder() | ||
.withLabels(Map.of("app", "restart-test")) | ||
.withName(primary.getMetadata().getName()) | ||
.withNamespace(primary.getMetadata().getNamespace()) | ||
.build()) | ||
.withData(Map.of(DATA_KEY, primary.getMetadata().getName())) | ||
.build(); | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...k/src/test/java/io/javaoperatorsdk/operator/sample/restart/RestartTestCustomResource.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.sample.restart; | ||
|
||
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("rt") | ||
public class RestartTestCustomResource | ||
extends CustomResource<Void, Void> | ||
implements Namespaced { | ||
} |
Oops, something went wrong.
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.
Shouldn't the executor service be shut down then in
stop
?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.
it is: https://github.com/java-operator-sdk/java-operator-sdk/blob/b29500f9674f4ec512540cd0a371901d4319908b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java#L100-L109
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.
Yes but what I meant is that we're lacking symmetry between start and stop here (i.e. the executor service is stopped at another level). Maybe
stop
should setexecutor
tonull
to prevent it from being used before being restarted? I guess this is more a theoretical question than a practical one.