From d549bf2fa4c898136aba9e4b7d450c7cf8c8282b Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 21 Dec 2024 11:47:36 +0200 Subject: [PATCH] fix --- .../tests/commons/fabric8_client/Util.java | 98 ------------------- 1 file changed, 98 deletions(-) diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java index 8d98a078e..dd9cd37c4 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java @@ -20,8 +20,6 @@ import java.time.Duration; import java.util.List; import java.util.Map; -import java.util.Optional; -import java.util.Set; import java.util.concurrent.TimeUnit; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -32,17 +30,13 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceAccount; import io.fabric8.kubernetes.api.model.apps.Deployment; -import io.fabric8.kubernetes.api.model.apps.DeploymentList; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.fabric8.kubernetes.api.model.networking.v1.IngressLoadBalancerIngress; -import io.fabric8.kubernetes.api.model.rbac.ClusterRole; import io.fabric8.kubernetes.api.model.rbac.Role; import io.fabric8.kubernetes.api.model.rbac.RoleBinding; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; -import io.fabric8.kubernetes.client.dsl.base.PatchContext; -import io.fabric8.kubernetes.client.dsl.base.PatchType; import io.fabric8.kubernetes.client.utils.Serialization; import jakarta.annotation.Nullable; import org.apache.commons.logging.Log; @@ -53,7 +47,6 @@ import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; import static org.awaitility.Awaitility.await; -import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.loadImage; import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pomVersion; import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pullImage; @@ -228,40 +221,6 @@ public void deleteNamespace(String name) { } - public void setUpClusterWide(String serviceAccountNamespace, Set namespaces) { - InputStream clusterRoleBindingAsStream = inputStream("cluster/cluster-role.yaml"); - InputStream serviceAccountAsStream = inputStream("cluster/service-account.yaml"); - InputStream roleBindingAsStream = inputStream("cluster/role-binding.yaml"); - - ClusterRole clusterRole = client.rbac().clusterRoles().load(clusterRoleBindingAsStream).item(); - if (client.rbac().clusterRoles().withName(clusterRole.getMetadata().getName()).get() == null) { - client.rbac().clusterRoles().resource(clusterRole).create(); - } - - ServiceAccount serviceAccountFromStream = client.serviceAccounts().load(serviceAccountAsStream).item(); - serviceAccountFromStream.getMetadata().setNamespace(serviceAccountNamespace); - if (client.serviceAccounts() - .inNamespace(serviceAccountNamespace) - .withName(serviceAccountFromStream.getMetadata().getName()) - .get() == null) { - client.serviceAccounts().inNamespace(serviceAccountNamespace).resource(serviceAccountFromStream).create(); - } - - RoleBinding roleBindingFromStream = client.rbac().roleBindings().load(roleBindingAsStream).item(); - namespaces.forEach(namespace -> { - roleBindingFromStream.getMetadata().setNamespace(namespace); - - if (client.rbac() - .roleBindings() - .inNamespace(namespace) - .withName(roleBindingFromStream.getMetadata().getName()) - .get() == null) { - client.rbac().roleBindings().inNamespace(namespace).resource(roleBindingFromStream).create(); - } - }); - - } - public void createAndWait(String namespace, @Nullable ConfigMap configMap, @Nullable Secret secret) { if (configMap != null) { client.configMaps().resource(configMap).create(); @@ -469,59 +428,6 @@ public void waitForIngress(String namespace, Ingress ingress) { } - public void patchWithReplace(String imageName, String deploymentName, String namespace, String patchBody, - Map labels) { - String body = patchBody.replace("image_name_here", imageName); - - client.apps() - .deployments() - .inNamespace(namespace) - .withName(deploymentName) - .patch(PatchContext.of(PatchType.JSON_MERGE), body); - - waitForDeploymentAfterPatch(deploymentName, namespace, labels); - } - - private void waitForDeploymentAfterPatch(String deploymentName, String namespace, Map labels) { - try { - await().pollDelay(Duration.ofSeconds(4)) - .pollInterval(Duration.ofSeconds(3)) - .atMost(60, TimeUnit.SECONDS) - .until(() -> isDeploymentReadyAfterPatch(deploymentName, namespace, labels)); - } - catch (Exception e) { - throw new RuntimeException(e); - } - - } - - private boolean isDeploymentReadyAfterPatch(String deploymentName, String namespace, Map labels) { - - DeploymentList deployments = client.apps().deployments().inNamespace(namespace).list(); - - if (deployments.getItems().isEmpty()) { - fail("No deployment with name " + deploymentName); - } - - Deployment deployment = deployments.getItems() - .stream() - .filter(x -> x.getMetadata().getName().equals(deploymentName)) - .findFirst() - .orElseThrow(); - // if no replicas are defined, it means only 1 is needed - int replicas = Optional.ofNullable(deployment.getSpec().getReplicas()).orElse(1); - - int numberOfPods = client.pods().inNamespace(namespace).withLabels(labels).list().getItems().size(); - - if (numberOfPods != replicas) { - LOG.info("number of pods not yet stabilized"); - return false; - } - - return replicas == Optional.ofNullable(deployment.getStatus().getReadyReplicas()).orElse(0); - - } - private void innerSetup(String namespace, InputStream serviceAccountAsStream, InputStream roleBindingAsStream, InputStream roleAsStream) { ServiceAccount serviceAccountFromStream = client.serviceAccounts() @@ -574,8 +480,4 @@ private String secretName(Secret secret) { return secret.getMetadata().getName(); } - public KubernetesClient client() { - return client; - } - }