Search in sources :

Example 41 with DeploymentBuilder

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

the class ServiceAccountEnricher method create.

@Override
public void create(PlatformMode mode, KubernetesListBuilder builder) {
    Map<String, String> deploymentToSaPair = new HashMap<>();
    List<ServiceAccount> serviceAccounts = new ArrayList<>();
    // Check XML config and see if there are any service accounts specified
    ResourceConfig xmlResourceConfig = getConfiguration().getResource();
    if (xmlResourceConfig != null && xmlResourceConfig.getServiceAccounts() != null) {
        for (ServiceAccountConfig serviceAccountConfig : xmlResourceConfig.getServiceAccounts()) {
            if (serviceAccountConfig.getName() != null) {
                serviceAccounts.add(createServiceAccount(builder, serviceAccountConfig.getName()));
            }
            if (serviceAccountConfig.getDeploymentRef() != null) {
                deploymentToSaPair.put(serviceAccountConfig.getDeploymentRef(), serviceAccountConfig.getName());
            }
        }
    }
    // If any service account is referenced in deployment spec, then
    // create sa on fly.
    builder.accept(new TypedVisitor<DeploymentBuilder>() {

        @Override
        public void visit(DeploymentBuilder deploymentBuilder) {
            String serviceAccountName = getServiceAccountNameFromSpec(deploymentBuilder);
            if (serviceAccountName != null && getServiceAccountFromList(builder, serviceAccountName) == null) {
                serviceAccounts.add(createServiceAccount(builder, serviceAccountName));
            }
            if (deploymentToSaPair.containsKey(deploymentBuilder.buildMetadata().getName())) {
                deploymentBuilder.editSpec().editTemplate().editSpec().withServiceAccountName(deploymentToSaPair.get(deploymentBuilder.buildMetadata().getName())).endSpec().endTemplate().endSpec();
            }
        }
    });
    builder.addAllToServiceAccountItems(serviceAccounts);
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceAccountConfig(org.eclipse.jkube.kit.config.resource.ServiceAccountConfig) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Example 42 with DeploymentBuilder

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

the class ImageEnricherTest method checkEnrichDeployment.

@Test
public void checkEnrichDeployment() throws Exception {
    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentBuilder().build());
    imageEnricher.create(PlatformMode.kubernetes, builder);
    assertCorrectlyGeneratedResources(builder.build(), "Deployment", "MY_KEY", "MY_VALUE");
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Example 43 with DeploymentBuilder

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

the class ImageEnricherTest method create_whenEnvironmentVariableAbsent_thenAddsEnvironmentVariable.

@Test
public void create_whenEnvironmentVariableAbsent_thenAddsEnvironmentVariable() throws JsonProcessingException {
    // Given
    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentBuilder().build());
    // When
    imageEnricher.create(PlatformMode.kubernetes, builder);
    // Then
    assertCorrectlyGeneratedResources(builder.build(), "Deployment", "MY_KEY", "MY_VALUE");
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Example 44 with DeploymentBuilder

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

the class MavenIssueManagementEnricherTest method testMavenIssueManagementOnlyUrl.

@Test
public void testMavenIssueManagementOnlyUrl() {
    final JavaProject project = JavaProject.builder().build();
    project.setIssueManagementUrl("https://github.com/fabric8org.eclipse.jkube-maven-plugin/issues/");
    // 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 45 with DeploymentBuilder

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

the class MavenIssueManagementEnricherTest method testMavenIssueManagementAll.

@Test
public void testMavenIssueManagementAll() {
    final JavaProject project = JavaProject.builder().build();
    project.setIssueManagementUrl("https://github.com/reactiverse/vertx-maven-plugin/issues/");
    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);
    Assert.assertEquals(2, scmAnnotations.size());
    assertEquals("GitHub", scmAnnotations.get(JKubeAnnotations.ISSUE_SYSTEM.value()));
    assertEquals("https://github.com/reactiverse/vertx-maven-plugin/issues/", scmAnnotations.get(JKubeAnnotations.ISSUE_TRACKER_URL.value()));
}
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)

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