Skip to content

Commit da0c0f0

Browse files
committed
fix the check pod status methods
1 parent 481bb43 commit da0c0f0

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,7 @@ public void testAdminServerRestartVersion() throws Exception {
325325
Assume.assumeFalse(QUICKTEST);
326326
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
327327
logTestBegin(testMethodName);
328-
K8sTestUtils testUtil = new K8sTestUtils();
329-
final String domainUid = domain.getDomainUid();
330-
final String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", domainUid);
331-
final String podName = domain.getDomainUid() + "-" + domain.getAdminServerName();
328+
String podName = domainUid + "-" + domain.getAdminServerName();
332329

333330
try {
334331
// Modify the original domain yaml to include restartVersion in admin server node
@@ -349,22 +346,18 @@ public void testAdminServerRestartVersion() throws Exception {
349346
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
350347
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
351348
logger.info(exec.stdout());
352-
logger.info("Verifying if the admin server is restarted");
353-
for (int i = 0; i < 120000; i = i + 10000) {
354-
String podStatus =
355-
testUtil.getPodStatus(domain.getDomainNS(), domain1LabelSelector, podName);
356-
Thread.sleep(10000);
357-
}
349+
350+
logger.info("Verifying if the admin server is terminating");
351+
verifyPodStatus(podName, "Terminating");
352+
verifyPodStatus(podName, "Running");
353+
358354
} finally {
359355
logger.log(
360356
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
361357
TestUtils.exec("kubectl apply -f " + originalYaml);
362-
logger.info("Verifying if the admin server is restarted");
363-
for (int i = 0; i < 120000; i = i + 10000) {
364-
String podStatus =
365-
testUtil.getPodStatus(domain.getDomainNS(), domain1LabelSelector, podName);
366-
Thread.sleep(10000);
367-
}
358+
logger.info("Verifying if the admin server is terminating");
359+
verifyPodStatus(podName, "Terminating");
360+
verifyPodStatus(podName, "Running");
368361
}
369362
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
370363
}
@@ -499,4 +492,27 @@ private static void destroyPodsRestartdomain() throws Exception {
499492
domain.destroy();
500493
}
501494
}
495+
496+
private void verifyPodStatus(String podName, String podStatusExpected)
497+
throws InterruptedException {
498+
K8sTestUtils testUtil = new K8sTestUtils();
499+
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", domainUid);
500+
String namespace = domain.getDomainNS();
501+
boolean gotExpected = false;
502+
for (int i = 0; i < 12; i++) {
503+
if (podStatusExpected.equals("Terminating")) {
504+
if (testUtil.isPodTerminating(namespace, domain1LabelSelector, podName)) {
505+
gotExpected = true;
506+
break;
507+
}
508+
} else if (podStatusExpected.equals("Running")) {
509+
if (testUtil.isPodRunning(namespace, domain1LabelSelector, podName)) {
510+
gotExpected = true;
511+
break;
512+
}
513+
}
514+
Thread.sleep(10000);
515+
}
516+
Assert.assertTrue("Didn't get the expected pod status", gotExpected);
517+
}
502518
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/K8sTestUtils.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.kubernetes.client.models.V1ConfigMapList;
2323
import io.kubernetes.client.models.V1DeploymentList;
2424
import io.kubernetes.client.models.V1JobList;
25+
import io.kubernetes.client.models.V1ObjectMeta;
2526
import io.kubernetes.client.models.V1PersistentVolumeClaimList;
2627
import io.kubernetes.client.models.V1PersistentVolumeList;
2728
import io.kubernetes.client.models.V1Pod;
@@ -372,18 +373,24 @@ public V1PodList getPods(String namespace, String labelSelectors) {
372373
return v1PodList;
373374
}
374375

375-
public String getPodStatus(String namespace, String labelSelectors, String podName) {
376-
String status = null;
376+
public V1Pod getPod(String namespace, String labelSelectors, String podName) {
377377
List<V1Pod> pods = getPods(namespace, labelSelectors).getItems();
378378
for (V1Pod pod : pods) {
379-
logger.log(
380-
Level.INFO,
381-
"POD NAME:{0} POD STATUS :{1}",
382-
new Object[] {pod.getMetadata().getName(), pod.getStatus().getPhase()});
383379
if (pod.getMetadata().getName().equals(podName)) {
384-
status = pod.getStatus().getPhase();
380+
return pod;
385381
}
386382
}
387-
return status;
383+
logger.info("POD NOT FOUND");
384+
return null;
385+
}
386+
387+
public boolean isPodTerminating(String namespace, String labelSelectors, String podName) {
388+
V1ObjectMeta metadata = getPod(namespace, labelSelectors, podName).getMetadata();
389+
logger.info(metadata.toString());
390+
return metadata.getDeletionTimestamp() != null;
391+
}
392+
393+
public boolean isPodRunning(String namespace, String labelSelectors, String podName) {
394+
return !isPodTerminating(namespace, labelSelectors, podName);
388395
}
389396
}

0 commit comments

Comments
 (0)