Search in sources :

Example 21 with ResourceConfig

use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.

the class ReplicaSetHandlerTest method replicaSetHandlerTest.

@Test
public void replicaSetHandlerTest() {
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
    ReplicaSet replicaSet = replicaSetHandler.get(config, images);
    // Assertion
    assertNotNull(replicaSet.getSpec());
    assertNotNull(replicaSet.getMetadata());
    assertEquals(5, replicaSet.getSpec().getReplicas().intValue());
    assertNotNull(replicaSet.getSpec().getTemplate());
    assertEquals("testing", replicaSet.getMetadata().getName());
    assertEquals("test-account", replicaSet.getSpec().getTemplate().getSpec().getServiceAccountName());
    assertFalse(replicaSet.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
    assertEquals("test", replicaSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
    assertEquals("/test/path", replicaSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
    assertNotNull(replicaSet.getSpec().getTemplate().getSpec().getContainers());
}
Also used : ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.Test)

Example 22 with ResourceConfig

use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.

the class ReplicationControllerHandlerTest method replicationControllerHandlerWithoutControllerTest.

@Test(expected = IllegalArgumentException.class)
public void replicationControllerHandlerWithoutControllerTest() {
    // without controller name
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
    replicationControllerHandler.get(config, images);
}
Also used : ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 23 with ResourceConfig

use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.

the class ReplicationControllerHandlerTest method replicationControllerHandlerTest.

@Test
public void replicationControllerHandlerTest() {
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
    ReplicationController replicationController = replicationControllerHandler.get(config, images);
    // Assertion
    assertNotNull(replicationController.getSpec());
    assertNotNull(replicationController.getMetadata());
    assertEquals(5, replicationController.getSpec().getReplicas().intValue());
    assertNotNull(replicationController.getSpec().getTemplate());
    assertEquals("testing", replicationController.getMetadata().getName());
    assertEquals("test-account", replicationController.getSpec().getTemplate().getSpec().getServiceAccountName());
    assertFalse(replicationController.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
    assertEquals("test", replicationController.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
    assertEquals("/test/path", replicationController.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
    assertNotNull(replicationController.getSpec().getTemplate().getSpec().getContainers());
}
Also used : ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 24 with ResourceConfig

use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.

the class StatefulSetHandlerTest method statefulSetHandlerTest.

@Test
public void statefulSetHandlerTest() {
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
    StatefulSet statefulSet = statefulSetHandler.get(config, images);
    // Assertion
    assertNotNull(statefulSet.getSpec());
    assertNotNull(statefulSet.getMetadata());
    assertEquals(5, statefulSet.getSpec().getReplicas().intValue());
    assertNotNull(statefulSet.getSpec().getTemplate());
    assertEquals("testing", statefulSet.getMetadata().getName());
    assertEquals("testing", statefulSet.getSpec().getServiceName());
    assertEquals("test-account", statefulSet.getSpec().getTemplate().getSpec().getServiceAccountName());
    assertFalse(statefulSet.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
    assertEquals("test", statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
    assertEquals("/test/path", statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
    assertNotNull(statefulSet.getSpec().getTemplate().getSpec().getContainers());
}
Also used : ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Test(org.junit.Test)

Example 25 with ResourceConfig

use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.

the class ControllerViaPluginConfigurationEnricher method create.

@Override
public void create(PlatformMode platformMode, KubernetesListBuilder builder) {
    final String name = getConfig(Config.NAME, JKubeProjectUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId()));
    ResourceConfig xmlResourceConfig = getConfiguration().getResource();
    final ResourceConfig config = ResourceConfig.builder().controllerName(name).imagePullPolicy(getImagePullPolicy(xmlResourceConfig, getConfig(Config.PULL_POLICY))).replicas(getReplicaCount(builder, xmlResourceConfig, Configs.asInt(getConfig(Config.REPLICA_COUNT)))).build();
    final List<ImageConfiguration> images = getImages();
    // Check if at least a replica set is added. If not add a default one
    if (KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
        // At least one image must be present, otherwise the resulting config will be invalid
        if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
            final StatefulSetSpec spec = statefulSetHandler.get(config, images).getSpec();
            if (spec != null) {
                builder.accept(new TypedVisitor<StatefulSetBuilder>() {

                    @Override
                    public void visit(StatefulSetBuilder statefulSetBuilder) {
                        statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                        mergeStatefulSetSpec(statefulSetBuilder, spec);
                    }
                });
                if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                    final PodSpec podSpec = spec.getTemplate().getSpec();
                    builder.accept(new TypedVisitor<PodSpecBuilder>() {

                        @Override
                        public void visit(PodSpecBuilder builder) {
                            String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
                            if (defaultApplicationContainerName != null) {
                                setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
                            }
                        }
                    });
                }
            }
        } else {
            final DeploymentSpec spec = deployHandler.get(config, images).getSpec();
            if (spec != null) {
                builder.accept(new TypedVisitor<DeploymentBuilder>() {

                    @Override
                    public void visit(DeploymentBuilder deploymentBuilder) {
                        deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                        mergeDeploymentSpec(deploymentBuilder, spec);
                    }
                });
                if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                    final PodSpec podSpec = spec.getTemplate().getSpec();
                    builder.accept(new TypedVisitor<PodSpecBuilder>() {

                        @Override
                        public void visit(PodSpecBuilder builder) {
                            String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
                            if (defaultApplicationContainerName != null) {
                                setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
                            }
                        }
                    });
                }
            }
        }
    }
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetSpec(io.fabric8.kubernetes.api.model.apps.StatefulSetSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Aggregations

ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)69 Test (org.junit.Test)60 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)17 Properties (java.util.Properties)10 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)9 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)7 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)7 ArrayList (java.util.ArrayList)5 Expectations (mockit.Expectations)5 File (java.io.File)4 IngressRulePathResourceConfig (org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 Service (io.fabric8.kubernetes.api.model.Service)3 IOException (java.io.IOException)3 List (java.util.List)3 Optional (java.util.Optional)3 KitLogger (org.eclipse.jkube.kit.common.KitLogger)3 JKubeServiceHub (org.eclipse.jkube.kit.config.service.JKubeServiceHub)3 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2