Skip to content

Commit b2322b5

Browse files
doxiaorjeberhard
andauthored
Remove cluster replicas and patch domain replicas and introspectVersion (#3391)
Co-authored-by: Ryan Eberhard <ryan.eberhard@oracle.com>
1 parent 12c313d commit b2322b5

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItKubernetesDomainEvents.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import static oracle.weblogic.kubernetes.utils.ClusterUtils.addClusterToDomain;
6969
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterAndVerify;
7070
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterResource;
71+
import static oracle.weblogic.kubernetes.utils.ClusterUtils.removeReplicasSettingAndVerify;
7172
import static oracle.weblogic.kubernetes.utils.ClusterUtils.scaleCluster;
7273
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
7374
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
@@ -413,17 +414,20 @@ void testDomainK8sEventsScalePastMaxWithoutChangingIntrospectVersion() {
413414
void testDomainK8sEventsScalePastMaxAndChangeIntrospectVersion() {
414415
OffsetDateTime timestamp = now();
415416
try {
416-
logger.info("Scaling cluster using patching");
417+
removeReplicasSettingAndVerify(domainUid, cluster1Name, domainNamespace3, replicaCount,
418+
managedServerPodNamePrefix);
419+
417420
String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, domainNamespace3));
418-
assertFalse(scaleCluster(cluster1Name, domainNamespace3, 3), "failed to scale cluster via patching");
419421
String patchStr
420422
= "["
421-
+ "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
423+
+ "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"},"
424+
+ "{\"op\": \"replace\", \"path\": \"/spec/replicas\", \"value\": 3}"
422425
+ "]";
423426

424427
logger.info("Updating introspect version using patch string: {0}", patchStr);
425428
assertTrue(patchDomainCustomResource(domainUid, domainNamespace3, new V1Patch(patchStr),
426-
V1Patch.PATCH_FORMAT_JSON_PATCH), "Patch domain failed");
429+
V1Patch.PATCH_FORMAT_JSON_PATCH), "Patch domain did not fail as expected");
430+
427431

428432
logger.info("verify the Failed event is generated");
429433
checkFailedEvent(opNamespace, domainNamespace3, domainUid, REPLICAS_TOO_HIGH_ERROR, "Warning", timestamp);

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ClusterUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static oracle.weblogic.kubernetes.actions.impl.Cluster.listClusterCustomResources;
2222
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterDoesNotExist;
2323
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterExists;
24+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
2425
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
2526
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
2627
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -154,4 +155,25 @@ public static DomainResource addClusterToDomain(String clusterResName, String na
154155
domain.getSpec().withCluster(new V1LocalObjectReference().name(clusterResName));
155156
return domain;
156157
}
158+
159+
/**
160+
* Remove the replicas setting from a cluster resource.
161+
* @param domainUid uid of the domain
162+
* @param clusterName name of the cluster resource
163+
* @param namespace namespace
164+
* @param replicaCount original replicaCount
165+
* @param msPodNamePrefix prefix of managed server pod names
166+
* */
167+
public static void removeReplicasSettingAndVerify(String domainUid, String clusterName, String namespace,
168+
int replicaCount, String msPodNamePrefix) {
169+
getLogger().info("Remove replicas setting from cluster resource {0} in namespace {1}", clusterName, namespace);
170+
String patchStr = "[{\"op\": \"remove\",\"path\": \"/spec/replicas\"}]";
171+
assertTrue(patchClusterCustomResource(clusterName, namespace, new V1Patch(patchStr),
172+
V1Patch.PATCH_FORMAT_JSON_PATCH), "Patch cluster resource failed");
173+
174+
// verify there is no pod created larger than max size of cluster
175+
for (int i = 1; i <= replicaCount; i++) {
176+
checkPodReadyAndServiceExists(msPodNamePrefix + i, domainUid, namespace);
177+
}
178+
}
157179
}

0 commit comments

Comments
 (0)