Search in sources :

Example 16 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class AutoTLSEnricherTest method testAdapt.

@Test
public void testAdapt() throws Exception {
    final AdaptTestConfig[] data = new AdaptTestConfig[] { new AdaptTestConfig(PlatformMode.kubernetes, null, null, null, null, null, null, null, null), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", "tls-a", "tls-a", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", "jks-b", "jks-b"), new AdaptTestConfig(PlatformMode.openshift, "test-container-name", "test-container-name", "image/123", "image/123", "tls-a", "tls-a", "jks-b", "jks-b") };
    for (final AdaptTestConfig tc : data) {
        TreeMap configMap = new TreeMap() {

            {
                put(AutoTLSEnricher.Config.pemToJKSInitContainerName.name(), tc.initContainerNameConfig);
                put(AutoTLSEnricher.Config.pemToJKSInitContainerImage.name(), tc.initContainerImageConfig);
                put(AutoTLSEnricher.Config.tlsSecretVolumeName.name(), tc.tlsSecretVolumeNameConfig);
                put(AutoTLSEnricher.Config.jksVolumeName.name(), tc.jksVolumeNameConfig);
            }
        };
        final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, configMap));
        final Properties projectProps = new Properties();
        projectProps.put(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
        // Setup mock behaviour
        new Expectations() {

            {
                project.getProperties();
                result = projectProps;
                project.getArtifactId();
                result = "projectA";
                minTimes = 0;
                context.getProject();
                result = project;
                context.getConfig();
                result = config;
            }
        };
        AutoTLSEnricher enricher = new AutoTLSEnricher(context);
        KubernetesListBuilder klb = new KubernetesListBuilder().addNewPodTemplateItem().withNewMetadata().and().withNewTemplate().withNewMetadata().and().withNewSpec().and().and().and();
        enricher.adapt(klb);
        PodTemplate pt = (PodTemplate) klb.getItems().get(0);
        String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
        assertEquals(tc.mode == PlatformMode.openshift, initContainers != null);
        if (tc.mode == PlatformMode.kubernetes) {
            continue;
        }
        JSONArray ja = new JSONArray(initContainers);
        assertEquals(1, ja.length());
        JSONObject jo = ja.getJSONObject(0);
        assertEquals(tc.initContainerName, jo.get("name"));
        assertEquals(tc.initContainerImage, jo.get("image"));
        JSONArray mounts = jo.getJSONArray("volumeMounts");
        assertEquals(2, mounts.length());
        JSONObject mount = mounts.getJSONObject(0);
        assertEquals(tc.tlsSecretVolumeName, mount.get("name"));
        mount = mounts.getJSONObject(1);
        assertEquals(tc.jksVolumeName, mount.get("name"));
    }
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Test(org.junit.Test)

Example 17 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class PrometheusEnricherTest method testCustomPrometheusPort.

// *******************************
// Tests
// *******************************
@Test
public void testCustomPrometheusPort() throws Exception {
    final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(PrometheusEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(Config.prometheusPort.name(), "1234"))));
    // Setup mock behaviour
    new Expectations() {

        {
            context.getConfig();
            result = config;
        }
    };
    PrometheusEnricher enricher = new PrometheusEnricher(context);
    Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
    assertEquals(2, annotations.size());
    assertEquals("1234", annotations.get(Annotations.Management.PROMETHEUS_PORT));
    assertEquals("true", annotations.get(Annotations.Management.PROMETHEUS_SCRAPE));
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 18 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class PrometheusEnricherTest method testDetectPrometheusPort.

@Test
public void testDetectPrometheusPort() throws Exception {
    final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(PrometheusEnricher.ENRICHER_NAME, new TreeMap()));
    final BuildImageConfiguration imageConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList(PrometheusEnricher.PROMETHEUS_PORT)).build();
    // Setup mock behaviour
    new Expectations() {

        {
            context.getConfig();
            result = config;
            imageConfiguration.getBuildConfiguration();
            result = imageConfig;
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
    PrometheusEnricher enricher = new PrometheusEnricher(context);
    Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
    assertEquals(2, annotations.size());
    assertEquals("9779", annotations.get(Annotations.Management.PROMETHEUS_PORT));
    assertEquals("true", annotations.get(Annotations.Management.PROMETHEUS_SCRAPE));
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 19 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class DefaultServiceEnricherTest method setupExpectations.

private void setupExpectations(final boolean withPorts, String... configParams) {
    // Setup mock behaviour
    final TreeMap config = new TreeMap();
    for (int i = 0; i < configParams.length; i += 2) {
        config.put(configParams[i], configParams[i + 1]);
    }
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-service", config));
            imageConfiguration.getBuildConfiguration();
            result = getBuildConfig(withPorts);
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 20 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class VolumePermissionEnricherTest method testAdapt.

@Test
public void testAdapt() throws Exception {
    final TestConfig[] data = new TestConfig[] { new TestConfig(null, null), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA"), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA", "volumeB") };
    for (final TestConfig tc : data) {
        final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(VolumePermissionEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(VolumePermissionEnricher.Config.permission.name(), tc.permission))));
        // Setup mock behaviour
        new Expectations() {

            {
                context.getConfig();
                result = config;
            }
        };
        VolumePermissionEnricher enricher = new VolumePermissionEnricher(context);
        PodTemplateBuilder ptb = createEmptyPodTemplate();
        for (String vn : tc.volumeNames) {
            ptb = addVolume(ptb, vn);
        }
        KubernetesListBuilder klb = new KubernetesListBuilder().addToPodTemplateItems(ptb.build());
        enricher.adapt(klb);
        PodTemplate pt = (PodTemplate) klb.buildItem(0);
        String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
        boolean shouldHaveInitContainer = tc.volumeNames.length > 0;
        assertEquals(shouldHaveInitContainer, initContainers != null);
        if (!shouldHaveInitContainer) {
            continue;
        }
        JSONArray ja = new JSONArray(initContainers);
        assertEquals(1, ja.length());
        JSONObject jo = ja.getJSONObject(0);
        assertEquals(tc.initContainerName, jo.get("name"));
        String permission = Strings.isNullOrBlank(tc.permission) ? "777" : tc.permission;
        JSONArray chmodCmd = new JSONArray();
        chmodCmd.put("chmod");
        chmodCmd.put(permission);
        for (String vn : tc.volumeNames) {
            chmodCmd.put("/tmp/" + vn);
        }
        assertEquals(chmodCmd.toString(), jo.getJSONArray("command").toString());
    }
}
Also used : Expectations(mockit.Expectations) JSONArray(org.json.JSONArray) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Aggregations

ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)27 Test (org.junit.Test)21 Expectations (mockit.Expectations)17 TreeMap (java.util.TreeMap)10 Probe (io.fabric8.kubernetes.api.model.Probe)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 ArrayList (java.util.ArrayList)3 MavenProject (org.apache.maven.project.MavenProject)3 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)2 Logger (io.fabric8.maven.docker.util.Logger)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 PodTemplate (io.fabric8.kubernetes.api.model.PodTemplate)1 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)1 PlatformMode (io.fabric8.maven.core.config.PlatformMode)1 Profile (io.fabric8.maven.core.config.Profile)1 Generator (io.fabric8.maven.generator.api.Generator)1 Watcher (io.fabric8.maven.watcher.api.Watcher)1