Skip to content

Commit e58457f

Browse files
committed
fix config override sequence issue
1 parent aec94c2 commit e58457f

File tree

2 files changed

+14
-8
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator
  • sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample

2 files changed

+14
-8
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,23 @@ public Operator() {
3131
}
3232

3333
public Operator(KubernetesClient kubernetesClient) {
34-
this(kubernetesClient, ConfigurationServiceProvider.instance());
34+
this(kubernetesClient, ConfigurationServiceProvider.instance(), null);
3535
}
3636

3737
/**
3838
* @deprecated Use {@link #Operator(Consumer)} instead
3939
*/
4040
@Deprecated
4141
public Operator(ConfigurationService configurationService) {
42-
this(null, configurationService);
42+
this(null, configurationService, null);
4343
}
4444

4545
public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
4646
this(null, overrider);
4747
}
4848

4949
public Operator(KubernetesClient client, Consumer<ConfigurationServiceOverrider> overrider) {
50-
this(client);
51-
ConfigurationServiceProvider.overrideCurrent(overrider);
50+
this(client, ConfigurationServiceProvider.instance(), overrider);
5251
}
5352

5453
/**
@@ -59,10 +58,18 @@ public Operator(KubernetesClient client, Consumer<ConfigurationServiceOverrider>
5958
* @param configurationService provides configuration
6059
*/
6160
public Operator(KubernetesClient kubernetesClient, ConfigurationService configurationService) {
61+
this(kubernetesClient, configurationService, null);
62+
}
63+
64+
private Operator(KubernetesClient kubernetesClient, ConfigurationService configurationService,
65+
Consumer<ConfigurationServiceOverrider> overrider) {
6266
this.kubernetesClient =
6367
kubernetesClient != null ? kubernetesClient : new KubernetesClientBuilder().build();
6468
ConfigurationServiceProvider.set(configurationService);
65-
configurationService.getLeaderElectionConfiguration()
69+
if (overrider != null) {
70+
ConfigurationServiceProvider.overrideCurrent(overrider);
71+
}
72+
ConfigurationServiceProvider.instance().getLeaderElectionConfiguration()
6673
.ifPresent(c -> leaderElectionManager.init(c, this.kubernetesClient));
6774
}
6875

sample-operators/leader-election/src/test/java/io/javaoperatorsdk/operator/sample/LeaderElectionE2E.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.junit.jupiter.api.AfterEach;
1515
import org.junit.jupiter.api.BeforeEach;
1616
import org.junit.jupiter.api.Test;
17-
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
1817
import org.slf4j.Logger;
1918
import org.slf4j.LoggerFactory;
2019

@@ -41,14 +40,14 @@ class LeaderElectionE2E {
4140

4241
private static final String OPERATOR_1_POD_NAME = "leader-election-operator-1";
4342
private static final String OPERATOR_2_POD_NAME = "leader-election-operator-2";
44-
public static final int MINIMAL_EXPECTED_RECONCILIATION = 2;
43+
public static final int MINIMAL_EXPECTED_RECONCILIATION = 3;
4544

4645
private String namespace;
4746
private KubernetesClient client;
4847

4948
@Test
5049
// not for local mode by design
51-
@EnabledIfSystemProperty(named = "test.deployment", matches = "remote")
50+
// @EnabledIfSystemProperty(named = "test.deployment", matches = "remote")
5251
void otherInstancesTakesOverWhenSteppingDown() {
5352
log.info("Deploying operator");
5453
deployOperatorsInOrder();

0 commit comments

Comments
 (0)