Search in sources :

Example 46 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.

the class MavenIssueManagementEnricherTest method testMavenIssueManagementOnlySystem.

@Test
public void testMavenIssueManagementOnlySystem() {
    final JavaProject project = JavaProject.builder().build();
    project.setIssueManagementSystem("GitHub");
    // Setup mock behaviour
    new Expectations() {

        {
            {
                context.getProject();
                result = project;
            }
        }
    };
    MavenIssueManagementEnricher enricher = new MavenIssueManagementEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
    enricher.create(PlatformMode.kubernetes, builder);
    Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
    assertNotNull(scmAnnotations);
    assertTrue(scmAnnotations.isEmpty());
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JavaProject(org.eclipse.jkube.kit.common.JavaProject) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Example 47 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.

the class MavenProjectEnricherTest method testGeneratedResources.

@Test
public void testGeneratedResources() {
    ProjectLabelEnricher projectEnricher = new ProjectLabelEnricher(context);
    KubernetesListBuilder builder = createListWithDeploymentConfig();
    projectEnricher.enrich(PlatformMode.kubernetes, builder);
    KubernetesList list = builder.build();
    Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels();
    assertNotNull(labels);
    assertEquals("groupId", labels.get("group"));
    assertEquals("artifactId", labels.get("app"));
    assertEquals("version", labels.get("version"));
    assertNull(labels.get("project"));
    builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().build());
    projectEnricher.create(PlatformMode.kubernetes, builder);
    Deployment deployment = (Deployment) builder.buildFirstItem();
    Map<String, String> selectors = deployment.getSpec().getSelector().getMatchLabels();
    assertEquals("groupId", selectors.get("group"));
    assertEquals("artifactId", selectors.get("app"));
    assertNull(selectors.get("version"));
    assertNull(selectors.get("project"));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Example 48 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.

the class PodAnnotationEnricherTest method enrich_withDeployment_shouldAddAnnotationsToPodTemplateSpec.

@Test
public void enrich_withDeployment_shouldAddAnnotationsToPodTemplateSpec() {
    // Given
    klb.addToItems(new DeploymentBuilder().withMetadata(createResourceMetadata()).withNewSpec().withNewTemplate().withMetadata(createPodTemplateSpecMetadata()).endTemplate().endSpec());
    // When
    podAnnotationEnricher.enrich(PlatformMode.kubernetes, klb);
    // Then
    KubernetesList kubernetesList = klb.build();
    assertThat(kubernetesList.getItems()).hasSize(1).first().isInstanceOf(Deployment.class);
    Deployment deployment = (Deployment) kubernetesList.getItems().get(0);
    assertThat(deployment).extracting(Deployment::getSpec).extracting(DeploymentSpec::getTemplate).extracting(PodTemplateSpec::getMetadata).extracting(ObjectMeta::getAnnotations).hasFieldOrPropertyWithValue("key1", "value1").hasFieldOrPropertyWithValue("key2", "value2");
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Example 49 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.

the class ProjectLabelEnricherTest method testEmptyCustomAppName.

@Test
public void testEmptyCustomAppName() {
    // Setup
    properties.setProperty("jkube.enricher.jkube-project-label.app", "");
    KubernetesListBuilder builder = createListWithDeploymentConfig();
    projectLabelEnricher.enrich(PlatformMode.kubernetes, builder);
    KubernetesList list = builder.build();
    Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels();
    assertNotNull(labels);
    assertEquals("groupId", labels.get("group"));
    assertEquals("", labels.get("app"));
    assertEquals("version", labels.get("version"));
    assertNull(labels.get("project"));
    builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().build());
    projectLabelEnricher.create(PlatformMode.kubernetes, builder);
    Deployment deployment = (Deployment) builder.buildFirstItem();
    Map<String, String> selectors = deployment.getSpec().getSelector().getMatchLabels();
    assertEquals("groupId", selectors.get("group"));
    assertEquals("", selectors.get("app"));
    assertNull(selectors.get("version"));
    assertNull(selectors.get("project"));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Example 50 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.

the class RevisionHistoryEnricherTest method testDefaultRevisionHistoryLimit.

@Test
public void testDefaultRevisionHistoryLimit() throws JsonProcessingException {
    // Given
    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentBuilder().build());
    RevisionHistoryEnricher enricher = new RevisionHistoryEnricher(context);
    // When
    enricher.create(PlatformMode.kubernetes, builder);
    // Then
    assertRevisionHistory(builder.build(), 2);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) 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