Java Code Examples for io.fabric8.kubernetes.api.model.KubernetesListBuilder#buildFirstItem()

The following examples show how to use io.fabric8.kubernetes.api.model.KubernetesListBuilder#buildFirstItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenProjectEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@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"));
}
 
Example 2
Source File: ConfigMapEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void should_materialize_file_content_from_annotation() throws Exception {
    final ConfigMap baseConfigMap = createAnnotationConfigMap("test-application.properties", "src/test/resources/test-application.properties");
    final KubernetesListBuilder builder = new KubernetesListBuilder()
            .addToConfigMapItems(baseConfigMap);
    new ConfigMapEnricher(context).create(PlatformMode.kubernetes, builder);

    final ConfigMap configMap = (ConfigMap) builder.buildFirstItem();

    final Map<String, String> data = configMap.getData();
    assertThat(data)
            .containsEntry("test-application.properties", readFileContentsAsString("src/test/resources/test-application.properties"));

    final Map<String, String> annotations = configMap.getMetadata().getAnnotations();
    assertThat(annotations)
            .isEmpty();
}
 
Example 3
Source File: ConfigMapEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void should_materialize_binary_file_content_from_annotation() throws Exception {
    final ConfigMap baseConfigMap = createAnnotationConfigMap("test.bin", "src/test/resources/test.bin");
    final KubernetesListBuilder builder = new KubernetesListBuilder()
            .addToConfigMapItems(baseConfigMap);
    new ConfigMapEnricher(context).create(PlatformMode.kubernetes, builder);

    final ConfigMap configMap = (ConfigMap) builder.buildFirstItem();

    final Map<String, String> data = configMap.getData();
    assertThat(data)
            .isEmpty();

    final Map<String, String> binaryData = configMap.getBinaryData();
    assertThat(binaryData)
            .containsEntry("test.bin", "wA==");

    final Map<String, String> annotations = configMap.getMetadata().getAnnotations();
    assertThat(annotations)
            .isEmpty();
}
 
Example 4
Source File: DeploymentConfigEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConversionFromAppsV1Deployment() {
    // Given
    DeploymentConfigEnricher deploymentConfigEnricher = new DeploymentConfigEnricher(context);
    io.fabric8.kubernetes.api.model.apps.Deployment appsV1Deployment = new io.fabric8.kubernetes.api.model.apps.DeploymentBuilder()
            .withNewMetadata().withName("test-app").addToLabels("app", "test-app").endMetadata()
            .withNewSpec()
            .withReplicas(3)
            .withRevisionHistoryLimit(2)
            .withNewSelector().addToMatchLabels("app", "test-app").endSelector()
            .withNewTemplate()
            .withNewMetadata().addToLabels("app", "test-app").endMetadata()
            .withNewSpec()
            .addNewContainer()
            .withName("test-container")
            .withImage("test-image:1.0.0")
            .addNewPort()
            .withContainerPort(80)
            .endPort()
            .endContainer()
            .endSpec()
            .endTemplate()
            .withNewStrategy()
            .withType("Rolling")
            .withNewRollingUpdate().withMaxSurge(new IntOrString(5)).endRollingUpdate()
            .endStrategy()
            .endSpec()
            .build();
    KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(appsV1Deployment);

    // When
    deploymentConfigEnricher.create(PlatformMode.openshift, kubernetesListBuilder);

    // Then
    assertEquals(1, kubernetesListBuilder.buildItems().size());
    HasMetadata result = kubernetesListBuilder.buildFirstItem();
    assertTrue(result instanceof DeploymentConfig);
    assertDeploymentConfig((DeploymentConfig) result, "Rolling");
}
 
Example 5
Source File: DeploymentConfigEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConversionFromAppsV1DeploymentWithRecreateStrategy() {
    // Given
    DeploymentConfigEnricher deploymentConfigEnricher = new DeploymentConfigEnricher(context);
    io.fabric8.kubernetes.api.model.apps.Deployment appsV1Deployment = new io.fabric8.kubernetes.api.model.apps.DeploymentBuilder()
            .withNewMetadata().withName("test-app").addToLabels("app", "test-app").endMetadata()
            .withNewSpec()
            .withReplicas(3)
            .withRevisionHistoryLimit(2)
            .withNewSelector().addToMatchLabels("app", "test-app").endSelector()
            .withNewTemplate()
            .withNewMetadata().addToLabels("app", "test-app").endMetadata()
            .withNewSpec()
            .addNewContainer()
            .withName("test-container")
            .withImage("test-image:1.0.0")
            .addNewPort()
            .withContainerPort(80)
            .endPort()
            .endContainer()
            .endSpec()
            .endTemplate()
            .withNewStrategy()
            .withType("Recreate")
            .endStrategy()
            .endSpec()
            .build();
    KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(appsV1Deployment);

    // When
    deploymentConfigEnricher.create(PlatformMode.openshift, kubernetesListBuilder);

    // Then
    assertEquals(1, kubernetesListBuilder.buildItems().size());
    HasMetadata result = kubernetesListBuilder.buildFirstItem();
    assertTrue(result instanceof DeploymentConfig);
    assertDeploymentConfig((DeploymentConfig) result, "Recreate");
}
 
Example 6
Source File: DeploymentConfigEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConvertionFromExtensionsV1beta1Deployment() {
    // Given
    DeploymentConfigEnricher deploymentConfigEnricher = new DeploymentConfigEnricher(context);
    io.fabric8.kubernetes.api.model.extensions.Deployment appsV1Deployment = new io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder()
            .withNewMetadata().withName("test-app").addToLabels("app", "test-app").endMetadata()
            .withNewSpec()
            .withReplicas(3)
            .withRevisionHistoryLimit(2)
            .withNewSelector().addToMatchLabels("app", "test-app").endSelector()
            .withNewTemplate()
            .withNewMetadata().addToLabels("app", "test-app").endMetadata()
            .withNewSpec()
            .addNewContainer()
            .withName("test-container")
            .withImage("test-image:1.0.0")
            .addNewPort()
            .withContainerPort(80)
            .endPort()
            .endContainer()
            .endSpec()
            .endTemplate()
            .withNewStrategy()
            .withType("Rolling")
            .withNewRollingUpdate().withMaxSurge(new IntOrString(5)).endRollingUpdate()
            .endStrategy()
            .endSpec()
            .build();
    KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(appsV1Deployment);

    // When
    deploymentConfigEnricher.create(PlatformMode.openshift, kubernetesListBuilder);

    // Then
    assertEquals(1, kubernetesListBuilder.buildItems().size());
    HasMetadata result = kubernetesListBuilder.buildFirstItem();
    assertTrue(result instanceof DeploymentConfig);
    assertDeploymentConfig((DeploymentConfig) result, "Rolling");
}