Skip to content

Commit 8be0898

Browse files
authored
Use kubectl exec to fix a test hanging issue (#1834)
* use kubectl exec * cleanup
1 parent 59f4e59 commit 8be0898

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
import static oracle.weblogic.kubernetes.actions.TestActions.dockerLogin;
8181
import static oracle.weblogic.kubernetes.actions.TestActions.dockerPush;
8282
import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource;
83-
import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod;
83+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPodKubectl;
8484
import static oracle.weblogic.kubernetes.assertions.TestAssertions.appNotAccessibleInPod;
8585
import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist;
8686
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainResourceImagePatched;
@@ -956,7 +956,7 @@ private void checkAppIsRunning(
956956
namespace,
957957
condition.getElapsedTimeInMS(),
958958
condition.getRemainingTimeInMS()))
959-
.until(() -> appAccessibleInPod(
959+
.until(() -> appAccessibleInPodKubectl(
960960
namespace,
961961
podName,
962962
internalPort,
@@ -1051,7 +1051,7 @@ private static void collectAppAvaiability(
10511051
while (!v2AppAvailable) {
10521052
v2AppAvailable = true;
10531053
for (int i = 1; i <= replicaCount; i++) {
1054-
v2AppAvailable = v2AppAvailable && appAccessibleInPod(
1054+
v2AppAvailable = v2AppAvailable && appAccessibleInPodKubectl(
10551055
namespace,
10561056
managedServerPrefix + i,
10571057
internalPort,
@@ -1061,7 +1061,7 @@ private static void collectAppAvaiability(
10611061

10621062
int count = 0;
10631063
for (int i = 1; i <= replicaCount; i++) {
1064-
if (appAccessibleInPod(
1064+
if (appAccessibleInPodKubectl(
10651065
namespace,
10661066
managedServerPrefix + i,
10671067
internalPort,

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,27 @@ public static boolean appAccessibleInPod(
389389
return Application.appAccessibleInPod(namespace, podName, port, appPath, expectedResponse);
390390
}
391391

392+
/**
393+
* Check if an application is accessible inside a WebLogic server pod using
394+
* "kubectl exec" command.
395+
*
396+
* @param namespace Kubernetes namespace where the WebLogic server pod is running
397+
* @param podName name of the WebLogic server pod
398+
* @param port internal port of the managed server running in the pod
399+
* @param appPath path to access the application
400+
* @param expectedResponse the expected response from the application
401+
* @return true if the command succeeds
402+
*/
403+
public static boolean appAccessibleInPodKubectl(
404+
String namespace,
405+
String podName,
406+
String port,
407+
String appPath,
408+
String expectedResponse
409+
) {
410+
return Application.appAccessibleInPodKubectl(namespace, podName, port, appPath, expectedResponse);
411+
}
412+
392413
/**
393414
* Check if an application is Not running inside a WebLogic server pod.
394415
* .

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.IOException;
77

88
import io.kubernetes.client.openapi.ApiException;
9+
import oracle.weblogic.kubernetes.actions.impl.primitive.Command;
10+
import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams;
911
import oracle.weblogic.kubernetes.utils.ExecResult;
1012

1113
import static oracle.weblogic.kubernetes.actions.TestActions.execCommand;
@@ -78,6 +80,42 @@ public static boolean appAccessibleInPod(
7880
getLogger().warning(String.format("Failed to find pod %s to check the app", podName));
7981
return false;
8082
}
81-
}
83+
}
84+
85+
/**
86+
* Check if an application is accessible inside a WebLogic server pod.
87+
*
88+
* @param namespace Kubernetes namespace where the WebLogic server pod is running
89+
* @param podName name of the WebLogic server pod
90+
* @param port internal port of the managed server running in the pod
91+
* @param appPath path to access the application
92+
* @param expectedResponse expected response from the app
93+
* @return true if the command succeeds
94+
*/
95+
public static boolean appAccessibleInPodKubectl(
96+
String namespace,
97+
String podName,
98+
String port,
99+
String appPath,
100+
String expectedResponse
101+
) {
102+
103+
// calling "kubectl exec" command to access the app inside a pod
104+
String cmd = String.format(
105+
"kubectl -n %s exec -it %s -- /bin/bash -c 'curl http://%s:%s/%s'",
106+
namespace,
107+
podName,
108+
podName,
109+
port,
110+
appPath);
111+
112+
CommandParams params = Command
113+
.defaultCommandParams()
114+
.command(cmd)
115+
.saveResults(true)
116+
.redirect(false)
117+
.verbose(false);
118+
return Command.withParams(params).executeAndVerify(expectedResponse);
119+
}
82120

83121
}

0 commit comments

Comments
 (0)