8000 keep restarting curl pod until it succeeds · java-operator-sdk/samples@a0dc153 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Commit a0dc153

Browse files
committed
keep restarting curl pod until it succeeds
1 parent 1fbc377 commit a0dc153

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

tomcat/src/test/java/io/javaoperatorsdk/operator/sample/IntegrationTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313

14-
import static java.util.concurrent.TimeUnit.MINUTES;
14+
import static java.util.concurrent.TimeUnit.*;
1515
import static org.awaitility.Awaitility.await;
1616
import static org.hamcrest.CoreMatchers.equalTo;
1717
import static org.hamcrest.CoreMatchers.is;
@@ -86,19 +86,30 @@ public void test() {
8686

8787
String url = "http://" + tomcat.getMetadata().getName() + "/" + webapp1.getSpec().getContextPath() + "/";
8888
log.info("Starting curl Pod and waiting 5 minutes for GET of {} to return 200", url);
89-
Pod curlPod = client.run().inNamespace(TEST_NS)
90-
.withRunConfig(new RunConfigBuilder()
91-
.withArgs("-s", "-o", "/dev/null", "-w", "%{http_code}", url)
92-
.withName("curl")
93-
.withImage("curlimages/curl:7.78.0")
94-
.withRestartPolicy("Never")
95-
.build()).done();
96-
await().atMost(5, MINUTES).untilAsserted(() -> {
89+
90+
int timeoutMinutes = 5;
91+
await().atMost(timeoutMinutes, MINUTES).untilAsserted(() -> {
9792
try {
93+
log.info("Starting curl Pod to test if webapp was deployed correctly");
94+
Pod curlPod = client.run().inNamespace(TEST_NS)
95+
.withRunConfig(new RunConfigBuilder()
96+
.withArgs("-s", "-o", "/dev/null", "-w", "%{http_code}", url)
97+
.withName("curl")
98+
.withImage("curlimages/curl:7.78.0")
99+
.withRestartPolicy("Never")
100+
.build()).done();
101+
log.info("Waiting for curl Pod to finish running");
102+
await().atMost(timeoutMinutes, MINUTES).until(() -> client.pods().inNamespace(TEST_NS).withName("curl").get().getStatus().getPhase().equals("Succeeded"));
103+
98104
String curlOutput = client.pods().inNamespace(TEST_NS).withName(curlPod.getMetadata().getName()).getLog();
105+
log.info("Output from curl: '{}'", curlOutput);
99106
assertThat(curlOutput, equalTo("200"));
100107
} catch (KubernetesClientException ex) {
101108
throw new AssertionError(ex);
109+
} finally {
110+
client.pods().inNamespace(TEST_NS).withName("curl").delete();
111+
log.info("Waiting for curl Pod to be deleted");
112+
await().atMost(timeoutMinutes, MINUTES).until(() -> client.pods().inNamespace(TEST_NS).withName("curl").get() == null);
102113
}
103114
});
104115

0 commit comments

Comments
 (0)
0