Skip to content

Commit d549bf2

Browse files
committed
fix
1 parent a5564fb commit d549bf2

File tree

1 file changed

+0
-98
lines changed
  • spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client

1 file changed

+0
-98
lines changed

spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.time.Duration;
2121
import java.util.List;
2222
import java.util.Map;
23-
import java.util.Optional;
24-
import java.util.Set;
2523
import java.util.concurrent.TimeUnit;
2624

2725
import io.fabric8.kubernetes.api.model.ConfigMap;
@@ -32,17 +30,13 @@
3230
import io.fabric8.kubernetes.api.model.Service;
3331
import io.fabric8.kubernetes.api.model.ServiceAccount;
3432
import io.fabric8.kubernetes.api.model.apps.Deployment;
35-
import io.fabric8.kubernetes.api.model.apps.DeploymentList;
3633
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
3734
import io.fabric8.kubernetes.api.model.networking.v1.IngressLoadBalancerIngress;
38-
import io.fabric8.kubernetes.api.model.rbac.ClusterRole;
3935
import io.fabric8.kubernetes.api.model.rbac.Role;
4036
import io.fabric8.kubernetes.api.model.rbac.RoleBinding;
4137
import io.fabric8.kubernetes.client.Config;
4238
import io.fabric8.kubernetes.client.KubernetesClient;
4339
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
44-
import io.fabric8.kubernetes.client.dsl.base.PatchContext;
45-
import io.fabric8.kubernetes.client.dsl.base.PatchType;
4640
import io.fabric8.kubernetes.client.utils.Serialization;
4741
import jakarta.annotation.Nullable;
4842
import org.apache.commons.logging.Log;
@@ -53,7 +47,6 @@
5347
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
5448

5549
import static org.awaitility.Awaitility.await;
56-
import static org.junit.jupiter.api.Assertions.fail;
5750
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.loadImage;
5851
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pomVersion;
5952
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pullImage;
@@ -228,40 +221,6 @@ public void deleteNamespace(String name) {
228221

229222
}
230223

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-
265224
public void createAndWait(String namespace, @Nullable ConfigMap configMap, @Nullable Secret secret) {
266225
if (configMap != null) {
267226
client.configMaps().resource(configMap).create();
@@ -469,59 +428,6 @@ public void waitForIngress(String namespace, Ingress ingress) {
469428

470429
}
471430

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-
525431
private void innerSetup(String namespace, InputStream serviceAccountAsStream, InputStream roleBindingAsStream,
526432
InputStream roleAsStream) {
527433
ServiceAccount serviceAccountFromStream = client.serviceAccounts()
@@ -574,8 +480,4 @@ private String secretName(Secret secret) {
574480
return secret.getMetadata().getName();
575481
}
576482

577-
public KubernetesClient client() {
578-
return client;
579-
}
580-
581483
}

0 commit comments

Comments
 (0)