Skip to content

Commit 1cf89ec

Browse files
authored
Owls 103231 - Changes to retry the failed patch operation in ItKubernetesDomainEvents tests and explicitly get the v8 version of domain (#3510)
* changes to retry the domain custom resource patch operation in ItKubernetesDomainEvents tests. * Changes to explicitly get the v8 version of domain to support the interop (hybrid) environment.
1 parent 97f68c7 commit 1cf89ec

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void testDomainK8sEventsScaleBelowMin() {
460460
+ "]";
461461
logger.info("Updating replicas in cluster {0} using patch string: {1}", cluster1Name, patchStr);
462462
V1Patch patch = new V1Patch(patchStr);
463-
assertTrue(patchDomainCustomResource(domainUid, domainNamespace3, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
463+
assertTrue(patchDomainCustomResource(domainUid, domainNamespace3, patch, V1Patch.PATCH_FORMAT_JSON_PATCH, 5),
464464
"Failed to patch domain");
465465

466466
// No event will be created for this
@@ -476,7 +476,7 @@ void testDomainK8sEventsScaleBelowMin() {
476476
+ "]";
477477
logger.info("Updating replicas in cluster {0} using patch string: {1}", cluster1Name, patchStr);
478478
V1Patch patch = new V1Patch(patchStr);
479-
assertTrue(patchDomainCustomResource(domainUid, domainNamespace3, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
479+
assertTrue(patchDomainCustomResource(domainUid, domainNamespace3, patch, V1Patch.PATCH_FORMAT_JSON_PATCH, 5),
480480
"Failed to patch domain");
481481
}
482482
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/Domain.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,23 @@ public static oracle.weblogic.domain.Domain getDomainCustomResource(String domai
192192
*/
193193
public static boolean patchDomainCustomResource(String domainUid, String namespace, V1Patch patch,
194194
String patchFormat) {
195-
return Kubernetes.patchDomainCustomResource(domainUid, namespace, patch, patchFormat);
195+
return Kubernetes.patchDomainCustomResource(domainUid, namespace, patch, patchFormat, 0);
196+
}
197+
198+
/**
199+
* Patch the Domain Custom Resource.
200+
*
201+
* @param domainUid unique domain identifier
202+
* @param namespace name of namespace
203+
* @param patch patch data in format matching the specified media type
204+
* @param patchFormat one of the following types used to identify patch document:
205+
* "application/json-patch+json", "application/merge-patch+json",
206+
* @param maxRetryCount Max retry count.
207+
* @return true if successful, false otherwise
208+
*/
209+
public static boolean patchDomainCustomResource(String domainUid, String namespace, V1Patch patch,
210+
String patchFormat, int maxRetryCount) {
211+
return Kubernetes.patchDomainCustomResource(domainUid, namespace, patch, patchFormat, maxRetryCount);
196212
}
197213

198214
/**

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Map;
2121
import java.util.Optional;
2222
import java.util.concurrent.Callable;
23+
import java.util.concurrent.atomic.AtomicBoolean;
24+
import java.util.concurrent.atomic.AtomicInteger;
2325

2426
import com.google.gson.Gson;
2527
import com.google.gson.JsonElement;
@@ -91,6 +93,7 @@
9193
import static java.util.concurrent.TimeUnit.MINUTES;
9294
import static java.util.concurrent.TimeUnit.SECONDS;
9395
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_VERSION;
96+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
9497
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
9598
import static org.awaitility.Awaitility.with;
9699
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -290,7 +293,6 @@ private static void initializeGenericKubernetesApiClients() {
290293
);
291294
deleteOptions = new DeleteOptions();
292295
deleteOptions.setGracePeriodSeconds(0L);
293-
deleteOptions.setPropagationPolicy(FOREGROUND);
294296
}
295297

296298
// ------------------------ deployments -----------------------------------
@@ -1358,23 +1360,37 @@ public static boolean patchCustomResourceDomainJsonMergePatch(String domainUid,
13581360
*/
13591361
public static boolean patchDomainCustomResource(String domainUid, String namespace,
13601362
V1Patch patch, String patchFormat) {
1363+
return patchDomainCustomResource(domainUid, namespace, patch, patchFormat, 0);
1364+
}
13611365

1362-
// GenericKubernetesApi uses CustomObjectsApi calls
1363-
KubernetesApiResponse<Domain> response = crdClient.patch(
1364-
namespace, // name of namespace
1365-
domainUid, // name of custom resource domain
1366-
patchFormat, // "application/json-patch+json" or "application/merge-patch+json"
1367-
patch // patch data
1368-
);
1369-
1370-
if (!response.isSuccess()) {
1371-
getLogger().warning(
1372-
"Failed to patch " + domainUid + " in namespace " + namespace + " using patch format: "
1373-
+ patchFormat);
1374-
return false;
1375-
}
1366+
/**
1367+
* Patch the Domain Custom Resource.
1368+
*
1369+
* @param domainUid unique domain identifier
1370+
* @param namespace name of namespace
1371+
* @param patch patch data in format matching the specified media type
1372+
* @param patchFormat one of the following types used to identify patch document:
1373+
* "application/json-patch+json", "application/merge-patch+json",
1374+
* @param maxRetryCount Max retry count.
1375+
* @return true if successful, false otherwise
1376+
*/
1377+
public static boolean patchDomainCustomResource(String domainUid, String namespace,
1378+
V1Patch patch, String patchFormat, int maxRetryCount) {
1379+
1380+
final AtomicBoolean result = new AtomicBoolean(false);
1381+
final AtomicInteger retryCount = new AtomicInteger(0);
1382+
testUntil(() -> {
1383+
KubernetesApiResponse<Domain> response = crdClient.patch(
1384+
namespace, // name of namespace
1385+
domainUid, // name of custom resource domain
1386+
patchFormat, // "application/json-patch+json" or "application/merge-patch+json"
1387+
patch // patch data
1388+
);
1389+
result.set(response.isSuccess());
1390+
return response.isSuccess() || retryCount.incrementAndGet() > maxRetryCount;
1391+
}, getLogger(), "Retrying the domain resource patch operation until successful.");
13761392

1377-
return true;
1393+
return result.get();
13781394
}
13791395

13801396
/**
@@ -2954,4 +2970,4 @@ public InputStream getInputStream() {
29542970
return new ByteArrayInputStream(copy.toByteArray());
29552971
}
29562972
}
2957-
}
2973+
}

kubernetes/samples/scripts/create-weblogic-domain/model-in-image/utils/wl-pod-wait.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function getDomainValue() {
179179
local ljpath="{$1}"
180180
local __retvar=$2
181181
set +e
182-
attvalue=$(kubectl -n ${DOMAIN_NAMESPACE} get domain ${DOMAIN_UID} -o=jsonpath="$ljpath" 2>&1)
182+
attvalue=$(kubectl -n ${DOMAIN_NAMESPACE} get domain.v8.weblogic.oracle ${DOMAIN_UID} -o=jsonpath="$ljpath" 2>&1)
183183
if [ $? -ne 0 ]; then
184184
if [ $expected -ne 0 ]; then
185185
echo "@@ Error: Could not obtain '$1' from '${DOMAIN_UID}' in namespace '${DOMAIN_NAMESPACE}'. Is your domain resource deployed? Err='$attvalue'"
@@ -202,7 +202,7 @@ function getDomainAIImages() {
202202
set +e
203203
attvalue=$(
204204
kubectl \
205-
get domain ${DOMAIN_UID} \
205+
get domain.v8.weblogic.oracle ${DOMAIN_UID} \
206206
-n ${DOMAIN_NAMESPACE} \
207207
-o=jsonpath="{range .spec.serverPod.auxiliaryImages[*]}{.image}{','}{end}" \
208208
2>&1

0 commit comments

Comments
 (0)