Search in sources :

Example 41 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class AbstractSpringBootHealthCheckEnricherSupport method testCustomPropertiesForLivenessAndReadiness.

@Test
public void testCustomPropertiesForLivenessAndReadiness() {
    Map<String, TreeMap> globalConfig = new HashMap<>();
    TreeMap<String, String> enricherConfig = new TreeMap<>();
    globalConfig.put(SpringBootHealthCheckEnricher.ENRICHER_NAME, enricherConfig);
    enricherConfig.put("readinessProbeInitialDelaySeconds", "30");
    enricherConfig.put("readinessProbePeriodSeconds", "40");
    enricherConfig.put("livenessProbeInitialDelaySeconds", "460");
    enricherConfig.put("livenessProbePeriodSeconds", "50");
    final ProcessorConfig config = new ProcessorConfig(null, null, globalConfig);
    new Expectations() {

        {
            context.getConfig();
            result = config;
        }
    };
    withAllRequiredClasses();
    withProjectProperties(new Properties());
    SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
    Probe probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(30, probe.getInitialDelaySeconds().intValue());
    assertEquals(40, probe.getPeriodSeconds().intValue());
    probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(460, probe.getInitialDelaySeconds().intValue());
    assertEquals(50, probe.getPeriodSeconds().intValue());
}
Also used : Expectations(mockit.Expectations) Probe(io.fabric8.kubernetes.api.model.Probe) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 42 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class AbstractSpringBootHealthCheckEnricherSupport method testCustomInitialDelayForLivenessAndReadiness.

@Test
public void testCustomInitialDelayForLivenessAndReadiness() {
    Map<String, TreeMap> globalConfig = new HashMap<>();
    TreeMap<String, String> enricherConfig = new TreeMap<>();
    globalConfig.put(SpringBootHealthCheckEnricher.ENRICHER_NAME, enricherConfig);
    enricherConfig.put("readinessProbeInitialDelaySeconds", "20");
    enricherConfig.put("livenessProbeInitialDelaySeconds", "360");
    final ProcessorConfig config = new ProcessorConfig(null, null, globalConfig);
    new Expectations() {

        {
            context.getConfig();
            result = config;
        }
    };
    withAllRequiredClasses();
    withProjectProperties(new Properties());
    SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
    Probe probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(20, probe.getInitialDelaySeconds().intValue());
    assertNull(probe.getPeriodSeconds());
    probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(360, probe.getInitialDelaySeconds().intValue());
    assertNull(probe.getPeriodSeconds());
}
Also used : Expectations(mockit.Expectations) Probe(io.fabric8.kubernetes.api.model.Probe) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 43 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testLivenessDisabledAndReadinessEnabledUsingConfig.

@Test
public void testLivenessDisabledAndReadinessEnabledUsingConfig() {
    final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap("vertx-health-check", new TreeMap(ImmutableMap.of(VertxHealthCheckEnricher.Config.readiness.name(), "/ping", VertxHealthCheckEnricher.Config.path.name(), ""))));
    new Expectations() {

        {
            context.getConfig();
            result = config;
        }
    };
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getPath(), "/ping");
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) Probe(io.fabric8.kubernetes.api.model.Probe) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 44 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
    final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).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 (!Lists.isNullOrEmpty(images)) {
            String type = getConfig(Config.type);
            if ("deployment".equalsIgnoreCase(type)) {
                log.info("Adding a default Deployment");
                builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
            } else if ("statefulSet".equalsIgnoreCase(type)) {
                log.info("Adding a default StatefulSet");
                builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
            } else if ("daemonSet".equalsIgnoreCase(type)) {
                log.info("Adding a default DaemonSet");
                builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
            } else if ("replicaSet".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicaSet");
                builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
            } else if ("replicationController".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicationController");
                builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
            } else if ("job".equalsIgnoreCase(type)) {
                log.info("Adding a default Job");
                builder.addToJobItems(jobHandler.getJob(config, images));
            }
        }
    } else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
        final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(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) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    } else {
        final DeploymentSpec spec = deployHandler.getDeployment(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) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    }
}
Also used : TypedVisitor(io.fabric8.kubernetes.api.builder.TypedVisitor) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 45 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class ProfileUtilTest method multiple.

@Test
public void multiple() throws IOException {
    InputStream is = getClass().getResourceAsStream("/fabric8/config/ProfileUtilTest-multiple.yml");
    assertNotNull(is);
    List<Profile> profiles = ProfileUtil.fromYaml(is);
    assertEquals(2, profiles.size());
}
Also used : InputStream(java.io.InputStream) Profile(io.fabric8.maven.core.config.Profile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)128 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)44 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)43 IOException (java.io.IOException)41 HashMap (java.util.HashMap)40 File (java.io.File)31 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)28 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)28 Map (java.util.Map)28 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)24 ArrayList (java.util.ArrayList)24 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)23 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)21 Expectations (mockit.Expectations)20 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)19 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)17 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)16 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)12