|
20 | 20 | import java.time.Duration; |
21 | 21 | import java.util.List; |
22 | 22 | import java.util.Map; |
23 | | -import java.util.Optional; |
24 | | -import java.util.Set; |
25 | 23 | import java.util.concurrent.TimeUnit; |
26 | 24 |
|
27 | 25 | import io.fabric8.kubernetes.api.model.ConfigMap; |
|
32 | 30 | import io.fabric8.kubernetes.api.model.Service; |
33 | 31 | import io.fabric8.kubernetes.api.model.ServiceAccount; |
34 | 32 | import io.fabric8.kubernetes.api.model.apps.Deployment; |
35 | | -import io.fabric8.kubernetes.api.model.apps.DeploymentList; |
36 | 33 | import io.fabric8.kubernetes.api.model.networking.v1.Ingress; |
37 | 34 | import io.fabric8.kubernetes.api.model.networking.v1.IngressLoadBalancerIngress; |
38 | | -import io.fabric8.kubernetes.api.model.rbac.ClusterRole; |
39 | 35 | import io.fabric8.kubernetes.api.model.rbac.Role; |
40 | 36 | import io.fabric8.kubernetes.api.model.rbac.RoleBinding; |
41 | 37 | import io.fabric8.kubernetes.client.Config; |
42 | 38 | import io.fabric8.kubernetes.client.KubernetesClient; |
43 | 39 | import io.fabric8.kubernetes.client.KubernetesClientBuilder; |
44 | | -import io.fabric8.kubernetes.client.dsl.base.PatchContext; |
45 | | -import io.fabric8.kubernetes.client.dsl.base.PatchType; |
46 | 40 | import io.fabric8.kubernetes.client.utils.Serialization; |
47 | 41 | import jakarta.annotation.Nullable; |
48 | 42 | import org.apache.commons.logging.Log; |
|
53 | 47 | import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; |
54 | 48 |
|
55 | 49 | import static org.awaitility.Awaitility.await; |
56 | | -import static org.junit.jupiter.api.Assertions.fail; |
57 | 50 | import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.loadImage; |
58 | 51 | import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pomVersion; |
59 | 52 | import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pullImage; |
@@ -228,40 +221,6 @@ public void deleteNamespace(String name) { |
228 | 221 |
|
229 | 222 | } |
230 | 223 |
|
231 | | - public void setUpClusterWide(String serviceAccountNamespace, Set<String> namespaces) { |
232 | | - InputStream clusterRoleBindingAsStream = inputStream("cluster/cluster-role.yaml"); |
233 | | - InputStream serviceAccountAsStream = inputStream("cluster/service-account.yaml"); |
234 | | - InputStream roleBindingAsStream = inputStream("cluster/role-binding.yaml"); |
235 | | - |
236 | | - ClusterRole clusterRole = client.rbac().clusterRoles().load(clusterRoleBindingAsStream).item(); |
237 | | - if (client.rbac().clusterRoles().withName(clusterRole.getMetadata().getName()).get() == null) { |
238 | | - client.rbac().clusterRoles().resource(clusterRole).create(); |
239 | | - } |
240 | | - |
241 | | - ServiceAccount serviceAccountFromStream = client.serviceAccounts().load(serviceAccountAsStream).item(); |
242 | | - serviceAccountFromStream.getMetadata().setNamespace(serviceAccountNamespace); |
243 | | - if (client.serviceAccounts() |
244 | | - .inNamespace(serviceAccountNamespace) |
245 | | - .withName(serviceAccountFromStream.getMetadata().getName()) |
246 | | - .get() == null) { |
247 | | - client.serviceAccounts().inNamespace(serviceAccountNamespace).resource(serviceAccountFromStream).create(); |
248 | | - } |
249 | | - |
250 | | - RoleBinding roleBindingFromStream = client.rbac().roleBindings().load(roleBindingAsStream).item(); |
251 | | - namespaces.forEach(namespace -> { |
252 | | - roleBindingFromStream.getMetadata().setNamespace(namespace); |
253 | | - |
254 | | - if (client.rbac() |
255 | | - .roleBindings() |
256 | | - .inNamespace(namespace) |
257 | | - .withName(roleBindingFromStream.getMetadata().getName()) |
258 | | - .get() == null) { |
259 | | - client.rbac().roleBindings().inNamespace(namespace).resource(roleBindingFromStream).create(); |
260 | | - } |
261 | | - }); |
262 | | - |
263 | | - } |
264 | | - |
265 | 224 | public void createAndWait(String namespace, @Nullable ConfigMap configMap, @Nullable Secret secret) { |
266 | 225 | if (configMap != null) { |
267 | 226 | client.configMaps().resource(configMap).create(); |
@@ -469,59 +428,6 @@ public void waitForIngress(String namespace, Ingress ingress) { |
469 | 428 |
|
470 | 429 | } |
471 | 430 |
|
472 | | - public void patchWithReplace(String imageName, String deploymentName, String namespace, String patchBody, |
473 | | - Map<String, String> labels) { |
474 | | - String body = patchBody.replace("image_name_here", imageName); |
475 | | - |
476 | | - client.apps() |
477 | | - .deployments() |
478 | | - .inNamespace(namespace) |
479 | | - .withName(deploymentName) |
480 | | - .patch(PatchContext.of(PatchType.JSON_MERGE), body); |
481 | | - |
482 | | - waitForDeploymentAfterPatch(deploymentName, namespace, labels); |
483 | | - } |
484 | | - |
485 | | - private void waitForDeploymentAfterPatch(String deploymentName, String namespace, Map<String, String> labels) { |
486 | | - try { |
487 | | - await().pollDelay(Duration.ofSeconds(4)) |
488 | | - .pollInterval(Duration.ofSeconds(3)) |
489 | | - .atMost(60, TimeUnit.SECONDS) |
490 | | - .until(() -> isDeploymentReadyAfterPatch(deploymentName, namespace, labels)); |
491 | | - } |
492 | | - catch (Exception e) { |
493 | | - throw new RuntimeException(e); |
494 | | - } |
495 | | - |
496 | | - } |
497 | | - |
498 | | - private boolean isDeploymentReadyAfterPatch(String deploymentName, String namespace, Map<String, String> labels) { |
499 | | - |
500 | | - DeploymentList deployments = client.apps().deployments().inNamespace(namespace).list(); |
501 | | - |
502 | | - if (deployments.getItems().isEmpty()) { |
503 | | - fail("No deployment with name " + deploymentName); |
504 | | - } |
505 | | - |
506 | | - Deployment deployment = deployments.getItems() |
507 | | - .stream() |
508 | | - .filter(x -> x.getMetadata().getName().equals(deploymentName)) |
509 | | - .findFirst() |
510 | | - .orElseThrow(); |
511 | | - // if no replicas are defined, it means only 1 is needed |
512 | | - int replicas = Optional.ofNullable(deployment.getSpec().getReplicas()).orElse(1); |
513 | | - |
514 | | - int numberOfPods = client.pods().inNamespace(namespace).withLabels(labels).list().getItems().size(); |
515 | | - |
516 | | - if (numberOfPods != replicas) { |
517 | | - LOG.info("number of pods not yet stabilized"); |
518 | | - return false; |
519 | | - } |
520 | | - |
521 | | - return replicas == Optional.ofNullable(deployment.getStatus().getReadyReplicas()).orElse(0); |
522 | | - |
523 | | - } |
524 | | - |
525 | 431 | private void innerSetup(String namespace, InputStream serviceAccountAsStream, InputStream roleBindingAsStream, |
526 | 432 | InputStream roleAsStream) { |
527 | 433 | ServiceAccount serviceAccountFromStream = client.serviceAccounts() |
@@ -574,8 +480,4 @@ private String secretName(Secret secret) { |
574 | 480 | return secret.getMetadata().getName(); |
575 | 481 | } |
576 | 482 |
|
577 | | - public KubernetesClient client() { |
578 | | - return client; |
579 | | - } |
580 | | - |
581 | 483 | } |
0 commit comments