Skip to content

Commit 464cb2c

Browse files
committed
Support maxUnavailable
1 parent aeb3e2c commit 464cb2c

File tree

8 files changed

+88
-3
lines changed

8 files changed

+88
-3
lines changed

model/src/main/java/oracle/kubernetes/weblogic/domain/ClusterConfigurator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
public interface ClusterConfigurator {
1313
ClusterConfigurator withReplicas(int replicas);
1414

15+
ClusterConfigurator withMaxUnavailable(int maxUnavailable);
16+
1517
ClusterConfigurator withDesiredState(String state);
1618

1719
ClusterConfigurator withEnvironmentVariable(String name, String value);

model/src/main/java/oracle/kubernetes/weblogic/domain/EffectiveConfigurationFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public interface EffectiveConfigurationFactory {
2222

2323
void setReplicaCount(String clusterName, int replicaCount);
2424

25+
int getMaxUnavailable(String clusterName);
26+
2527
boolean isShuttingDown();
2628

2729
List<String> getExportedNetworkAccessPointNames();

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/Cluster.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public class Cluster extends BaseConfiguration {
2727
@Range(minimum = 0)
2828
private Integer replicas;
2929

30+
@Description(
31+
"The maximum number of cluster membrers that can be temporarily unavailable. Defaults to 1.")
32+
@Range(minimum = 1)
33+
private Integer maxUnavailable;
34+
3035
public String getClusterName() {
3136
return clusterName;
3237
}
@@ -48,12 +53,21 @@ public void setReplicas(Integer replicas) {
4853
this.replicas = replicas;
4954
}
5055

56+
public Integer getMaxUnavailable() {
57+
return maxUnavailable;
58+
}
59+
60+
public void setMaxUnavailable(Integer maxUnavailable) {
61+
this.maxUnavailable = maxUnavailable;
62+
}
63+
5164
@Override
5265
public String toString() {
5366
return new ToStringBuilder(this)
5467
.appendSuper(super.toString())
5568
.append("clusterName", clusterName)
5669
.append("replicas", replicas)
70+
.append("maxUnavailable", maxUnavailable)
5771
.toString();
5872
}
5973

@@ -69,6 +83,7 @@ public boolean equals(Object o) {
6983
.appendSuper(super.equals(o))
7084
.append(clusterName, cluster.clusterName)
7185
.append(replicas, cluster.replicas)
86+
.append(maxUnavailable, cluster.maxUnavailable)
7287
.isEquals();
7388
}
7489

@@ -78,6 +93,7 @@ public int hashCode() {
7893
.appendSuper(super.hashCode())
7994
.append(clusterName)
8095
.append(replicas)
96+
.append(maxUnavailable)
8197
.toHashCode();
8298
}
8399
}

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/Domain.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,26 @@ public void setReplicaCount(String clusterName, int replicaLimit) {
213213
getEffectiveConfigurationFactory().setReplicaCount(clusterName, replicaLimit);
214214
}
215215

216+
/**
217+
* Returns the maximum number of unavailable replicas for the specified cluster.
218+
*
219+
* @param clusterName the name of the cluster
220+
* @return the result of applying any configurations for this value
221+
*/
222+
public int getMaxUnavailable(String clusterName) {
223+
return getEffectiveConfigurationFactory().getMaxUnavailable(clusterName);
224+
}
225+
226+
/**
227+
* Returns the minimum number of replicas for the specified cluster.
228+
*
229+
* @param clusterName the name of the cluster
230+
* @return the result of applying any configurations for this value
231+
*/
232+
public int getMinAvailable(String clusterName) {
233+
return Math.max(getReplicaCount(clusterName) - getMaxUnavailable(clusterName), 0);
234+
}
235+
216236
/**
217237
* DomainSpec is a description of a domain.
218238
*

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/DomainSpec.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ private boolean hasReplicaCount(Cluster cluster) {
684684
return cluster != null && cluster.getReplicas() != null;
685685
}
686686

687+
private int getMaxUnavailableFor(Cluster cluster) {
688+
return hasMaxUnavailable(cluster) ? cluster.getMaxUnavailable() : 1;
689+
}
690+
691+
private boolean hasMaxUnavailable(Cluster cluster) {
692+
return cluster != null && cluster.getMaxUnavailable() != null;
693+
}
694+
687695
private AdminServer getAdminServer() {
688696
return Optional.ofNullable(adminServer).orElse(AdminServer.NULL_ADMIN_SERVER);
689697
}
@@ -734,6 +742,11 @@ public void setReplicaCount(String clusterName, int replicaCount) {
734742
getOrCreateCluster(clusterName).setReplicas(replicaCount);
735743
}
736744

745+
@Override
746+
public int getMaxUnavailable(String clusterName) {
747+
return getMaxUnavailableFor(getCluster(clusterName));
748+
}
749+
737750
@Override
738751
public List<String> getExportedNetworkAccessPointNames() {
739752
return getAdminServer().getExportedNetworkAccessPointNames();

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/DomainV2Configurator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ public ClusterConfigurator withReplicas(int replicas) {
381381
return this;
382382
}
383383

384+
@Override
385+
public ClusterConfigurator withMaxUnavailable(int maxUnavailable) {
386+
cluster.setMaxUnavailable(maxUnavailable);
387+
return this;
388+
}
389+
384390
@Override
385391
public ClusterConfigurator withDesiredState(String state) {
386392
cluster.setServerStartState(state);

model/src/test/java/oracle/kubernetes/weblogic/domain/DomainTestBase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,34 @@ public void afterReplicaCountSetForCluster_canChangeIt() {
301301
assertThat(domain.getReplicaCount("cluster1"), equalTo(4));
302302
}
303303

304+
@Test
305+
public void afterReplicaCountMaxUnavailableSetForCluster_canReadMinAvailable() {
306+
configureCluster("cluster1").withReplicas(5).withMaxUnavailable(2);
307+
308+
assertThat(domain.getMinAvailable("cluster1"), equalTo(3));
309+
}
310+
311+
@Test
312+
public void afterReplicaCountSetForCluster_canReadMinAvailable() {
313+
configureCluster("cluster1").withReplicas(5);
314+
315+
assertThat(domain.getMinAvailable("cluster1"), equalTo(4));
316+
}
317+
318+
@Test
319+
public void afterReplicaCountMaxUnavailableSetForCluster_zeroMin() {
320+
configureCluster("cluster1").withReplicas(3).withMaxUnavailable(10);
321+
322+
assertThat(domain.getMinAvailable("cluster1"), equalTo(0));
323+
}
324+
325+
@Test
326+
public void afterMaxUnavailableSetForCluster_canReadIt() {
327+
configureCluster("cluster1").withMaxUnavailable(5);
328+
329+
assertThat(domain.getMaxUnavailable("cluster1"), equalTo(5));
330+
}
331+
304332
@Test
305333
public void whenServerNotConfigured_nodePortIsNull() {
306334
ServerSpec spec = domain.getServer(SERVER1, CLUSTER_NAME);

operator/src/main/java/oracle/kubernetes/operator/helpers/RollingHelper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
public class RollingHelper {
3636
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
3737

38-
private static final int MINIMUM_FOR_CLUSTER = 2;
39-
4038
private RollingHelper() {}
4139

4240
/**
@@ -222,7 +220,7 @@ public NextAction apply(Packet packet) {
222220

223221
// then add as many as possible next() entries leaving at least minimum cluster
224222
// availability
225-
while (countReady-- > MINIMUM_FOR_CLUSTER) {
223+
while (countReady-- > dom.getMinAvailable(clusterName)) {
226224
current = it.next();
227225
serverConfig = (WlsServerConfig) current.packet.get(ProcessingConstants.SERVER_SCAN);
228226
servers.add(serverConfig != null ? serverConfig.getName() : dom.getSpec().getAsName());

0 commit comments

Comments
 (0)