use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class DeploymentTest method testListFromServer.
@Test
void testListFromServer() {
DeploymentBuilder deploymentBuilder = new DeploymentBuilder().withNewMetadata().withNamespace("test").withName("deployment1").endMetadata();
Deployment clientDeployment = deploymentBuilder.build();
Deployment serverDeployment = deploymentBuilder.editMetadata().withResourceVersion("1").endMetadata().withNewStatus().addNewCondition().withType("Ready").withStatus("True").endCondition().endStatus().build();
server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, serverDeployment).once();
List<HasMetadata> resources = client.resourceList(clientDeployment).fromServer().get();
assertNotNull(resources);
assertEquals(1, resources.size());
assertNotNull(resources.get(0));
assertTrue(resources.get(0) instanceof Deployment);
Deployment fromServerDeployment = (Deployment) resources.get(0);
assertNotNull(fromServerDeployment.getMetadata());
assertEquals("1", fromServerDeployment.getMetadata().getResourceVersion());
assertNotNull(fromServerDeployment.getStatus());
assertNotNull(fromServerDeployment.getStatus().getConditions());
assertEquals(1, fromServerDeployment.getStatus().getConditions().size());
assertEquals("Ready", fromServerDeployment.getStatus().getConditions().get(0).getType());
assertEquals("True", fromServerDeployment.getStatus().getConditions().get(0).getStatus());
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class DeploymentTest method testRollingUpdate.
@Test
void testRollingUpdate() {
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("ns1").endMetadata().withNewSpec().withReplicas(1).withNewSelector().withMatchLabels(Collections.singletonMap("service", "http-server")).endSelector().withNewStrategy().withType("RollingUpdate").withNewRollingUpdate().withNewMaxSurge(1).withNewMaxUnavailable(1).endRollingUpdate().endStrategy().withMinReadySeconds(5).withNewTemplate().withNewMetadata().withLabels(Collections.singletonMap("service", "http-server")).endMetadata().withNewSpec().addToContainers(new ContainerBuilder().withName("nginx").withImage("nginx:1.10.2").withImagePullPolicy("IfNotPresent").withPorts(Collections.singletonList(new ContainerPortBuilder().withContainerPort(80).build())).build()).endSpec().endTemplate().endSpec().build();
server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment1").andReturn(200, deployment).always();
server.expect().withPath("/api/v1/namespaces/ns1/pods?labelSelector=service%3Dhttp-server").andReturn(200, new KubernetesListBuilder().build()).once();
server.expect().post().withPath("/apis/apps/v1/namespaces/ns1/deployments").andReturn(201, deployment).times(2);
client.apps().deployments().inNamespace("ns1").withName("deployment1").rolling().withTimeout(5, TimeUnit.MINUTES).updateImage("");
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class DeploymentTest method testCreate.
@Test
void testCreate() {
Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata().withNewSpec().withReplicas(1).endSpec().build();
server.expect().post().withPath("/apis/apps/v1/namespaces/test/deployments").andReturn(200, deployment1).once();
Deployment result = client.apps().deployments().inNamespace("test").create(deployment1);
assertNotNull(result);
assertEquals("deployment1", result.getMetadata().getName());
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project kubernetes-client by fabric8io.
the class DeploymentCrudTest method testReplace.
@Test
@DisplayName("Should replace Deployment in CRUD server")
void testReplace() {
// Given
Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("d1").withNamespace("ns1").addToLabels("testKey", "testValue").endMetadata().withNewSpec().endSpec().build();
deployment1 = client.apps().deployments().inNamespace("ns1").create(deployment1);
// When
deployment1.getMetadata().getLabels().put("testKey", "one");
client.apps().deployments().inNamespace("ns1").withName("d1").replace(deployment1);
Deployment replacedDeployment = client.apps().deployments().inNamespace("ns1").withName("d1").get();
// Then
assertNotNull(replacedDeployment);
assertFalse(replacedDeployment.getMetadata().getLabels().isEmpty());
assertEquals("one", replacedDeployment.getMetadata().getLabels().get("testKey"));
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.
the class AbstractHealthCheckEnricherTest method enrichSpecificContainers.
@Test
public void enrichSpecificContainers() {
final Properties properties = new Properties();
properties.put(AbstractHealthCheckEnricher.ENRICH_CONTAINERS, "app2,app3");
KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("app").withImage("app:latest").endContainer().addNewContainer().withName("app2").withImage("app2:latest").endContainer().addNewContainer().withName("app3").withImage("app3:latest").endContainer().endSpec().endTemplate().endSpec().build());
createEnricher(properties, Collections.emptyMap()).create(PlatformMode.kubernetes, list);
final AtomicInteger containerFound = new AtomicInteger(0);
list.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
switch(container.getName()) {
case "app":
assertNull(container.build().getLivenessProbe());
assertNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
break;
case "app2":
case "app3":
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
break;
}
}
});
assertEquals(3, containerFound.get());
}
Aggregations