Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public class FeatureGates {
/* test */ static final FeatureGates NONE = new FeatureGates("");

private static final String CONTINUE_ON_MANUAL_RU_FAILURE = "ContinueReconciliationOnManualRollingUpdateFailure";
private static final String USE_STRETCH_CLUSTER = "UseStretchCluster";

// When adding new feature gates, do not forget to add them to allFeatureGates(), toString(), equals(), and `hashCode() methods
private final FeatureGate continueOnManualRUFailure =
new FeatureGate(CONTINUE_ON_MANUAL_RU_FAILURE, true);
private final FeatureGate useStretchCluster = new FeatureGate(USE_STRETCH_CLUSTER, false);

/**
* Constructs the feature gates configuration.
Expand All @@ -44,6 +46,9 @@ public FeatureGates(String featureGateConfig) {
featureGate = featureGate.substring(1);

switch (featureGate) {
case USE_STRETCH_CLUSTER:
setValueOnlyOnce(useStretchCluster, value);
break;
case CONTINUE_ON_MANUAL_RU_FAILURE:
setValueOnlyOnce(continueOnManualRUFailure, value);
break;
Expand Down Expand Up @@ -87,19 +92,28 @@ public boolean continueOnManualRUFailureEnabled() {
return continueOnManualRUFailure.isEnabled();
}

/**
* @return Returns true when the StretchCluster feature gate is enabled
*/
public boolean useStretchClusterEnabled() {
return useStretchCluster.isEnabled();
}


/**
* Returns a list of all Feature gates. Used for testing.
*
* @return List of all Feature Gates
*/
/*test*/ List<FeatureGate> allFeatureGates() {
return List.of(continueOnManualRUFailure);
return List.of(continueOnManualRUFailure, useStretchCluster);
}

@Override
public String toString() {
return "FeatureGates(" +
"ContinueReconciliationOnManualRollingUpdateFailure=" + continueOnManualRUFailure.isEnabled() +
"ContinueReconciliationOnManualRollingUpdateFailure=" + continueOnManualRUFailure.isEnabled() + "," +
"UseStretchCluster=" + useStretchCluster.isEnabled() +
")";
}

Expand Down Expand Up @@ -131,13 +145,13 @@ public boolean equals(Object o) {
return false;
} else {
FeatureGates other = (FeatureGates) o;
return Objects.equals(continueOnManualRUFailure, other.continueOnManualRUFailure);
return Objects.equals(continueOnManualRUFailure, other.continueOnManualRUFailure) && Objects.equals(useStretchCluster, other.useStretchCluster);
}
}

@Override
public int hashCode() {
return Objects.hashCode(continueOnManualRUFailure);
return Objects.hash(continueOnManualRUFailure, useStretchCluster);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ public void testFeatureGatesParsing() {
assertThat(new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure").continueOnManualRUFailureEnabled(), is(true));
assertThat(new FeatureGates("-ContinueReconciliationOnManualRollingUpdateFailure").continueOnManualRUFailureEnabled(), is(false));
assertThat(new FeatureGates(" -ContinueReconciliationOnManualRollingUpdateFailure ").continueOnManualRUFailureEnabled(), is(false));

assertThat(new FeatureGates("+UseStretchCluster").useStretchClusterEnabled(), is(true));
assertThat(new FeatureGates("-UseStretchCluster").useStretchClusterEnabled(), is(false));
assertThat(new FeatureGates(" -UseStretchCluster").useStretchClusterEnabled(), is(false));

assertThat(new FeatureGates("-UseStretchCluster,-ContinueReconciliationOnManualRollingUpdateFailure").useStretchClusterEnabled(), is(false));
assertThat(new FeatureGates("-UseStretchCluster,-ContinueReconciliationOnManualRollingUpdateFailure").continueOnManualRUFailureEnabled(), is(false));

assertThat(new FeatureGates(" +UseStretchCluster , +ContinueReconciliationOnManualRollingUpdateFailure").useStretchClusterEnabled(), is(true));
assertThat(new FeatureGates(" +UseStretchCluster , +ContinueReconciliationOnManualRollingUpdateFailure").continueOnManualRUFailureEnabled(), is(true));

assertThat(new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure,-UseStretchCluster").useStretchClusterEnabled(), is(false));
assertThat(new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure,-UseStretchCluster").continueOnManualRUFailureEnabled(), is(true));



// TODO: Add more tests with various feature gate combinations once we have multiple feature gates again.
// The commented out code below shows the tests we used to have with multiple feature gates.
//assertThat(new FeatureGates("-UseKRaft,-ContinueReconciliationOnManualRollingUpdateFailure").useKRaftEnabled(), is(false));
Expand All @@ -68,10 +84,19 @@ public void testFeatureGatesParsing() {

@ParallelTest
public void testFeatureGatesEquals() {
FeatureGates fg = new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure");
assertThat(fg, is(fg));
assertThat(fg, is(new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure")));
assertThat(fg, is(not(new FeatureGates("-ContinueReconciliationOnManualRollingUpdateFailure"))));
FeatureGates fgPositive = new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure,+UseStretchCluster");
assertThat(fgPositive, is(fgPositive));
assertThat(fgPositive, is(new FeatureGates("+UseStretchCluster,+ContinueReconciliationOnManualRollingUpdateFailure")));
assertThat(fgPositive, is(not(new FeatureGates("+UseStretchCluster,-ContinueReconciliationOnManualRollingUpdateFailure"))));
assertThat(fgPositive, is(not(new FeatureGates("-UseStretchCluster,-ContinueReconciliationOnManualRollingUpdateFailure"))));
assertThat(fgPositive, is(not(new FeatureGates("-UseStretchCluster,+ContinueReconciliationOnManualRollingUpdateFailure"))));

FeatureGates fgNegative = new FeatureGates("-ContinueReconciliationOnManualRollingUpdateFailure,-UseStretchCluster");
assertThat(fgNegative, is(fgNegative));
assertThat(fgNegative, is(new FeatureGates("-UseStretchCluster,-ContinueReconciliationOnManualRollingUpdateFailure")));
assertThat(fgNegative, is(not(new FeatureGates("+UseStretchCluster,-ContinueReconciliationOnManualRollingUpdateFailure"))));
assertThat(fgNegative, is(not(new FeatureGates("+UseStretchCluster,+ContinueReconciliationOnManualRollingUpdateFailure"))));
assertThat(fgNegative, is(not(new FeatureGates("-UseStretchCluster,+ContinueReconciliationOnManualRollingUpdateFailure"))));
}

@ParallelTest
Expand Down Expand Up @@ -117,7 +142,11 @@ public void testNonExistingGate() {
@ParallelTest
public void testEnvironmentVariable() {
assertThat(new FeatureGates("").toEnvironmentVariable(), is(""));
assertThat(new FeatureGates("-ContinueReconciliationOnManualRollingUpdateFailure").toEnvironmentVariable(), is("-ContinueReconciliationOnManualRollingUpdateFailure"));
assertThat(new FeatureGates("-ContinueReconciliationOnManualRollingUpdateFailure,+UseStretchCluster").toEnvironmentVariable(), is("-ContinueReconciliationOnManualRollingUpdateFailure,+UseStretchCluster"));
assertThat(new FeatureGates("-ContinueReconciliationOnManualRollingUpdateFailure,-UseStretchCluster").toEnvironmentVariable(), is("-ContinueReconciliationOnManualRollingUpdateFailure"));
assertThat(new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure,+UseStretchCluster").toEnvironmentVariable(), is("+UseStretchCluster"));
assertThat(new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure,-UseStretchCluster").toEnvironmentVariable(), is(""));
assertThat(new FeatureGates("+ContinueReconciliationOnManualRollingUpdateFailure").toEnvironmentVariable(), is(""));
assertThat(new FeatureGates("+UseStretchCluster").toEnvironmentVariable(), is("+UseStretchCluster"));
}
}