Skip to content

Commit b485ed6

Browse files
committed
Liveness probe tests
1 parent 6a19717 commit b485ed6

File tree

7 files changed

+334
-158
lines changed

7 files changed

+334
-158
lines changed

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

Lines changed: 233 additions & 131 deletions
Large diffs are not rendered by default.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,22 @@ public static boolean restartManagedServerUsingServerStartPolicy(String domainUi
889889

890890
return serverStopped && serverStarted;
891891
}
892+
893+
/**
894+
* Get the container's restart count in the pod.
895+
* @param namespace name of the pod's namespace
896+
* @param labelSelector in the format "weblogic.domainUID in (%s)"
897+
* @param podName name of the pod
898+
* @param containerName name of the container, if null looks for first container
899+
* @return restart count of the container
900+
* @throws ApiException if Kubernetes client API call fails
901+
*/
902+
public static int getContainerRestartCount(
903+
String namespace, String labelSelector, String podName, String containerName)
904+
throws ApiException {
905+
return Kubernetes.getContainerRestartCount(namespace, labelSelector, podName, containerName);
906+
}
907+
892908
// ------------------------ where does this go -------------------------
893909

894910
/**

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import io.kubernetes.client.openapi.models.V1ClusterRoleList;
4444
import io.kubernetes.client.openapi.models.V1ConfigMap;
4545
import io.kubernetes.client.openapi.models.V1ConfigMapList;
46+
import io.kubernetes.client.openapi.models.V1ContainerStatus;
4647
import io.kubernetes.client.openapi.models.V1Deployment;
4748
import io.kubernetes.client.openapi.models.V1DeploymentList;
4849
import io.kubernetes.client.openapi.models.V1Event;
@@ -501,6 +502,41 @@ public static DateTime getPodCreationTimestamp(String namespace, String labelSel
501502
}
502503
}
503504

505+
/**
506+
* Get the container's restart count in the pod.
507+
* @param namespace name of the pod's namespace
508+
* @param labelSelector in the format "weblogic.domainUID in (%s)"
509+
* @param podName name of the pod
510+
* @param containerName name of the container, null if there is only one container
511+
* @return restart count of the container
512+
* @throws ApiException if Kubernetes client API call fails
513+
*/
514+
public static int getContainerRestartCount(
515+
String namespace, String labelSelector, String podName, String containerName)
516+
throws ApiException {
517+
518+
V1Pod pod = getPod(namespace, labelSelector, podName);
519+
if (pod != null && pod.getStatus() != null) {
520+
List<V1ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses();
521+
// if containerName is null, get first container restart count
522+
if (containerName == null && containerStatuses.size() >= 1) {
523+
return containerStatuses.get(0).getRestartCount();
524+
} else {
525+
for (V1ContainerStatus containerStatus : containerStatuses) {
526+
if (containerName.equals(containerStatus.getName())) {
527+
return containerStatus.getRestartCount();
528+
}
529+
}
530+
logger.severe("Container {0} status doesn't exist or pod's container statuses is empty in namespace {1}",
531+
containerName, namespace);
532+
}
533+
} else {
534+
logger.severe("Pod {0} doesn't exist or pod status is null in namespace {1}",
535+
podName, namespace);
536+
}
537+
return 0;
538+
}
539+
504540
/**
505541
* Get the weblogic.domainRestartVersion label from a given pod.
506542
*
@@ -567,6 +603,23 @@ public static void copyDirectoryFromPod(V1Pod pod, String srcPath, Path destinat
567603
copy.copyDirectoryFromPod(pod, srcPath, destination);
568604
}
569605

606+
/**
607+
* Copy a file from local filesystem to Kubernetes pod.
608+
* @param namespace namespace of the pod
609+
* @param pod name of the pod where the file is copied to
610+
* @param container name of the container
611+
* @param srcPath source file location
612+
* @param destPath destination file location on pod
613+
* @throws IOException when copy fails
614+
* @throws ApiException when pod interaction fails
615+
*/
616+
public static void copyFileToPod(
617+
String namespace, String pod, String container, Path srcPath, Path destPath)
618+
throws IOException, ApiException {
619+
Copy copy = new Copy();
620+
copy.copyFileToPod(namespace, pod, container, srcPath, destPath);
621+
}
622+
570623
// --------------------------- namespaces -----------------------------------
571624
/**
572625
* Create a Kubernetes namespace.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public static boolean isJobComplete(String namespace, String labelSelectors, Str
574574
if (jobCondition.getType().equalsIgnoreCase("failed")) {
575575
logger.severe("Job {0} failed", jobName);
576576
} else if (jobCondition.getType().equalsIgnoreCase("complete")) {
577-
logger.severe("Job {0} completed successfully ", jobName);
577+
logger.info("Job {0} completed successfully ", jobName);
578578
}
579579
}
580580
}

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,39 @@ public void beforeAll(ExtensionContext context) {
108108
assertFalse(operatorImage.isEmpty(), "Image name can not be empty");
109109
assertTrue(Operator.buildImage(operatorImage));
110110

111-
// build basic wdt-domain-in-image image
112-
wdtBasicImage = WDT_BASIC_IMAGE_NAME + ":" + WDT_BASIC_IMAGE_TAG;
113-
assertTrue(createBasicImage(WDT_BASIC_IMAGE_NAME, WDT_BASIC_IMAGE_TAG, WDT_BASIC_MODEL_FILE,
114-
WDT_BASIC_MODEL_PROPERTIES_FILE, WDT_BASIC_APP_NAME, WDT_BASIC_IMAGE_DOMAINTYPE),
115-
String.format("Failed to create the image %s using WebLogic Image Tool",
116-
wdtBasicImage));
117-
118-
119-
/* Check image exists using docker images | grep image tag.
120-
* Tag name is unique as it contains date and timestamp.
121-
* This is a workaround for the issue on Jenkins machine
122-
* as docker images imagename:imagetag is not working and
123-
* the test fails even though the image exists.
124-
*/
125-
assertTrue(doesImageExist(WDT_BASIC_IMAGE_TAG),
126-
String.format("Image %s doesn't exist", wdtBasicImage));
127-
128-
if (!REPO_USERNAME.equals(REPO_DUMMY_VALUE)) {
129-
logger.info("docker login");
130-
assertTrue(dockerLogin(REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD), "docker login failed");
111+
if (System.getenv("SKIP_BASIC_IMAGE_BUILD") == null) {
112+
// build basic wdt-domain-in-image image
113+
wdtBasicImage = WDT_BASIC_IMAGE_NAME + ":" + WDT_BASIC_IMAGE_TAG;
114+
assertTrue(createBasicImage(WDT_BASIC_IMAGE_NAME, WDT_BASIC_IMAGE_TAG, WDT_BASIC_MODEL_FILE,
115+
WDT_BASIC_MODEL_PROPERTIES_FILE, WDT_BASIC_APP_NAME, WDT_BASIC_IMAGE_DOMAINTYPE),
116+
String.format("Failed to create the image %s using WebLogic Image Tool",
117+
wdtBasicImage));
118+
119+
120+
/* Check image exists using docker images | grep image tag.
121+
* Tag name is unique as it contains date and timestamp.
122+
* This is a workaround for the issue on Jenkins machine
123+
* as docker images imagename:imagetag is not working and
124+
* the test fails even though the image exists.
125+
*/
126+
assertTrue(doesImageExist(WDT_BASIC_IMAGE_TAG),
127+
String.format("Image %s doesn't exist", wdtBasicImage));
128+
129+
if (!REPO_USERNAME.equals(REPO_DUMMY_VALUE)) {
130+
logger.info("docker login");
131+
assertTrue(dockerLogin(REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD), "docker login failed");
132+
}
131133
}
132134

133135
// push the image
134136
if (!REPO_NAME.isEmpty()) {
135137
logger.info("docker push image {0} to {1}", operatorImage, REPO_NAME);
136138
assertTrue(dockerPush(operatorImage), String.format("docker push failed for image %s", operatorImage));
137139

138-
logger.info("docker push wdt basic domain in image {0} to registry", wdtBasicImage);
139-
assertTrue(dockerPush(wdtBasicImage), String.format("docker push failed for image %s", wdtBasicImage));
140-
140+
if (System.getenv("SKIP_BASIC_IMAGE_BUILD") == null) {
141+
logger.info("docker push wdt basic domain in image {0} to registry", wdtBasicImage);
142+
assertTrue(dockerPush(wdtBasicImage), String.format("docker push failed for image %s", wdtBasicImage));
143+
}
141144
}
142145
// The following code is for pulling WLS images if running tests in Kind cluster
143146
if (KIND_REPO != null) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,9 +1029,9 @@ public static DateTime getPodCreationTime(String namespace, String podName) {
10291029
assertDoesNotThrow(() -> getPodCreationTimestamp(namespace, "", podName),
10301030
String.format("Couldn't get PodCreationTimestamp for pod %s", podName));
10311031
assertNotNull(podCreationTime, "Got null PodCreationTimestamp");
1032-
logger.info("PodCreationTimestamp for pod ${0} in namespace ${1} is {2}",
1033-
namespace,
1032+
logger.info("PodCreationTimestamp for pod {0} in namespace {1} is {2}",
10341033
podName,
1034+
namespace,
10351035
podCreationTime);
10361036
return podCreationTime;
10371037
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static boolean callWebAppAndCheckForServerNameInResponse(
4848
if (managedServers.containsValue(false)) {
4949
try {
5050
// sometimes the pod is not ready even the condition check is ready, sleep a little bit
51-
Thread.sleep(100);
51+
Thread.sleep(1000);
5252
} catch (InterruptedException ignore) {
5353
// ignore
5454
}
@@ -57,6 +57,8 @@ public static boolean callWebAppAndCheckForServerNameInResponse(
5757
result = ExecCommand.exec(curlCmd, true);
5858

5959
String response = result.stdout().trim();
60+
logger.info("Response for iteration {0}: exitValue {1}, stdout {2}, stderr {3}",
61+
i, result.exitValue(), response, result.stderr());
6062
managedServers.keySet().forEach(key -> {
6163
if (response.contains(key)) {
6264
managedServers.put(key, true);

0 commit comments

Comments
 (0)