cleanup after fabric IT refactor (#1832)
* cleanup * checkstyle * fix test
This commit is contained in:
@@ -23,9 +23,6 @@ import java.util.Set;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.awaitility.Awaitility;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.util.retry.Retry;
|
||||
import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.EndpointNameAndNamespace;
|
||||
@@ -34,11 +31,12 @@ import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_cl
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.builder;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.retrySpec;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
@@ -116,12 +114,4 @@ final class TestAssertions {
|
||||
|
||||
}
|
||||
|
||||
private static WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
private static RetryBackoffSpec retrySpec() {
|
||||
return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.util.retry.Retry;
|
||||
import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.boot.test.json.BasicJsonTester;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
@@ -33,12 +29,13 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static java.util.AbstractMap.SimpleEntry;
|
||||
import static java.util.Map.Entry;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.builder;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.retrySpec;
|
||||
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
|
||||
|
||||
/**
|
||||
@@ -321,12 +318,4 @@ final class TestAssertions {
|
||||
.until(() -> output.getOut().contains(message));
|
||||
}
|
||||
|
||||
private static WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
private static RetryBackoffSpec retrySpec() {
|
||||
return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
package org.springframework.cloud.kubernetes.fabric8.client.istio;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.Service;
|
||||
import io.fabric8.kubernetes.api.model.apps.Deployment;
|
||||
@@ -31,18 +29,17 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.Container;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.util.retry.Retry;
|
||||
import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.builder;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.retrySpec;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@@ -133,14 +130,6 @@ class Fabric8IstioIT {
|
||||
|
||||
}
|
||||
|
||||
private WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
private RetryBackoffSpec retrySpec() {
|
||||
return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
private static String istioctlPodName() {
|
||||
try {
|
||||
return K3S
|
||||
|
||||
@@ -22,10 +22,17 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.kubernetes</groupId>
|
||||
<artifactId>client-java-extended</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>kubernetes-client</artifactId>
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -38,10 +39,15 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.testcontainers.containers.Container;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.util.retry.Retry;
|
||||
import reactor.util.retry.RetryBackoffSpec;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.Constants.KUBERNETES_VERSION_FILE;
|
||||
@@ -264,6 +270,14 @@ public final class Commons {
|
||||
|
||||
}
|
||||
|
||||
public static WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
public static RetryBackoffSpec retrySpec() {
|
||||
return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
private static void loadImageFromPath(String tarName, K3sContainer container) {
|
||||
await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(1)).until(() -> {
|
||||
Container.ExecResult result = container.execInContainer("ctr", "i", "import", TMP_IMAGES + "/" + tarName);
|
||||
|
||||
@@ -20,8 +20,6 @@ import java.io.InputStream;
|
||||
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.APIService;
|
||||
@@ -33,17 +31,13 @@ import io.fabric8.kubernetes.api.model.Secret;
|
||||
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;
|
||||
@@ -54,7 +48,6 @@ import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
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;
|
||||
@@ -245,40 +238,6 @@ public final class Util {
|
||||
|
||||
}
|
||||
|
||||
public void setUpClusterWide(String serviceAccountNamespace, Set<String> 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();
|
||||
@@ -486,59 +445,6 @@ public final class Util {
|
||||
|
||||
}
|
||||
|
||||
public void patchWithReplace(String imageName, String deploymentName, String namespace, String patchBody,
|
||||
Map<String, String> 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<String, String> 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<String, String> 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()
|
||||
|
||||
Reference in New Issue
Block a user