|
10 | 10 |
|
11 | 11 | import io.fabric8.kubernetes.api.model.*;
|
12 | 12 | import io.fabric8.kubernetes.client.*;
|
13 |
| -import io.fabric8.kubernetes.client.extended.run.RunConfigBuilder; |
14 | 13 | import io.javaoperatorsdk.operator.config.runtime.DefaultConfigurationService;
|
15 | 14 | import io.javaoperatorsdk.operator.junit.AbstractOperatorExtension;
|
16 | 15 | import io.javaoperatorsdk.operator.junit.E2EOperatorExtension;
|
| 16 | +import io.javaoperatorsdk.operator.junit.InClusterCurl; |
17 | 17 | import io.javaoperatorsdk.operator.junit.OperatorExtension;
|
18 | 18 |
|
19 | 19 | import static java.util.concurrent.TimeUnit.MINUTES;
|
@@ -107,42 +107,15 @@ public void test() {
|
107 | 107 |
|
108 | 108 | String url =
|
109 | 109 | "http://" + tomcat.getMetadata().getName() + "/" + webapp1.getSpec().getContextPath() + "/";
|
| 110 | + var inClusterCurl = new InClusterCurl(client, operator.getNamespace()); |
110 | 111 | log.info("Starting curl Pod and waiting 5 minutes for GET of {} to return 200", url);
|
111 | 112 |
|
112 | 113 | await("wait-for-webapp").atMost(6, MINUTES).untilAsserted(() -> {
|
113 | 114 | try {
|
114 |
| - |
115 |
| - log.info("Starting curl Pod to test if webapp was deployed correctly"); |
116 |
| - Pod curlPod = client.run().inNamespace(operator.getNamespace()) |
117 |
| - .withRunConfig(new RunConfigBuilder() |
118 |
| - .withArgs("-s", "-o", "/dev/null", "-w", "%{http_code}", url) |
119 |
| - .withName("curl") |
120 |
| - .withImage("curlimages/curl:7.78.0") |
121 |
| - .withRestartPolicy("Never") |
122 |
| - .build()) |
123 |
| - .done(); |
124 |
| - log.info("Waiting for curl Pod to finish running"); |
125 |
| - await("wait-for-curl-pod-run").atMost(2, MINUTES) |
126 |
| - .until(() -> { |
127 |
| - String phase = |
128 |
| - client.pods().inNamespace(operator.getNamespace()).withName("curl").get() |
129 |
| - .getStatus().getPhase(); |
130 |
| - return phase.equals("Succeeded") || phase.equals("Failed"); |
131 |
| - }); |
132 |
| - |
133 |
| - String curlOutput = |
134 |
| - client.pods().inNamespace(operator.getNamespace()) |
135 |
| - .withName(curlPod.getMetadata().getName()).getLog(); |
136 |
| - log.info("Output from curl: '{}'", curlOutput); |
| 115 | + var curlOutput = inClusterCurl.checkUrl(url); |
137 | 116 | assertThat(curlOutput, equalTo("200"));
|
138 | 117 | } catch (KubernetesClientException ex) {
|
139 | 118 | throw new AssertionError(ex);
|
140 |
| - } finally { |
141 |
| - log.info("Deleting curl Pod"); |
142 |
| - client.pods().inNamespace(operator.getNamespace()).withName("curl").delete(); |
143 |
| - await("wait-for-curl-pod-stop").atMost(1, MINUTES) |
144 |
| - .until(() -> client.pods().inNamespace(operator.getNamespace()).withName("curl") |
145 |
| - .get() == null); |
146 | 119 | }
|
147 | 120 | });
|
148 | 121 | }
|
|
0 commit comments