Search in sources :

Example 31 with DeploymentBuilder

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());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test)

Example 32 with DeploymentBuilder

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("");
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test)

Example 33 with DeploymentBuilder

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());
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test)

Example 34 with DeploymentBuilder

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"));
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 35 with DeploymentBuilder

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());
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Properties(java.util.Properties) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Aggregations

DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)153 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)80 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)60 Test (org.junit.Test)60 Test (org.junit.jupiter.api.Test)32 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)26 Expectations (mockit.Expectations)26 Test (org.testng.annotations.Test)22 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)17 ArrayList (java.util.ArrayList)17 Container (io.fabric8.kubernetes.api.model.Container)16 HashMap (java.util.HashMap)16 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)15 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)15 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)14 Properties (java.util.Properties)14 Pod (io.fabric8.kubernetes.api.model.Pod)13 PodTemplateSpecBuilder (io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder)13 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)12 InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)12