Search in sources :

Example 11 with ProcessorConfig

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

the class MicronautHealthCheckEnricherTest method setUp.

@Before
public void setUp() {
    properties = new Properties();
    processorConfig = new ProcessorConfig();
    klb = new KubernetesListBuilder();
    klb.addToItems(new ServiceBuilder().withNewMetadata().withName("make-it-real").endMetadata().build());
    // @formatter:off
    new Expectations() {

        {
            context.getProperties();
            result = properties;
            context.getConfiguration().getProcessorConfig();
            result = processorConfig;
        }
    };
    // @formatter:on
    micronautHealthCheckEnricher = new MicronautHealthCheckEnricher(context);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Expectations(mockit.Expectations) Properties(java.util.Properties) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Before(org.junit.Before)

Example 12 with ProcessorConfig

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

the class IngressEnricherTest method testNetworkingV1IngressIsGenerated.

@Test
public void testNetworkingV1IngressIsGenerated() {
    // Given
    final TreeMap<String, Object> config = new TreeMap<>();
    config.put("host", "test.192.168.39.25.nip.io");
    config.put("targetApiVersion", "networking.k8s.io/v1");
    new Expectations() {

        {
            Configuration configuration = Configuration.builder().image(imageConfiguration).processorConfig(new ProcessorConfig(null, null, Collections.singletonMap("jkube-ingress", config))).build();
            context.getConfiguration();
            result = configuration;
            context.getProperty("jkube.createExternalUrls");
            result = "true";
        }
    };
    KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder();
    kubernetesListBuilder.addToItems(initTestService().build());
    // When
    ingressEnricher.create(PlatformMode.kubernetes, kubernetesListBuilder);
    // Then
    assertThat(kubernetesListBuilder).extracting(KubernetesListBuilder::buildItems).asList().hasSize(2).element(1).extracting("spec.rules").asList().extracting("host").containsExactly("test.192.168.39.25.nip.io");
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Configuration(org.eclipse.jkube.kit.enricher.api.model.Configuration) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) TreeMap(java.util.TreeMap) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) Test(org.junit.Test)

Example 13 with ProcessorConfig

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

the class VolumePermissionEnricherTest method testAdapt.

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

            {
                context.getConfiguration();
                result = Configuration.builder().processorConfig(config).build();
            }
        };
        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.enrich(PlatformMode.kubernetes, klb);
        PodTemplate pt = (PodTemplate) klb.buildItem(0);
        List<Container> initContainers = pt.getTemplate().getSpec().getInitContainers();
        boolean shouldHaveInitContainer = tc.volumeNames.length > 0;
        assertEquals(shouldHaveInitContainer, !initContainers.isEmpty());
        if (!shouldHaveInitContainer) {
            continue;
        }
        Gson gson = new Gson();
        JsonArray ja = new JsonParser().parse(gson.toJson(initContainers, new TypeToken<Collection<Container>>() {
        }.getType())).getAsJsonArray();
        assertEquals(1, ja.size());
        JsonObject jo = ja.get(0).getAsJsonObject();
        assertEquals(tc.initContainerName, jo.get("name").getAsString());
        assertEquals(tc.imageName, jo.get("image").getAsString());
        String permission = StringUtils.isBlank(tc.permission) ? "777" : tc.permission;
        JsonArray chmodCmd = new JsonArray();
        chmodCmd.add("chmod");
        chmodCmd.add(permission);
        for (String vn : tc.volumeNames) {
            chmodCmd.add("/tmp/" + vn);
        }
        assertEquals(chmodCmd.toString(), jo.getAsJsonArray("command").toString());
    }
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) JsonArray(com.google.gson.JsonArray) Container(io.fabric8.kubernetes.api.model.Container) TypeToken(com.google.common.reflect.TypeToken) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Example 14 with ProcessorConfig

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

the class EnricherConfigTest method simple.

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void simple(@Mocked EnricherContext context) {
    Map<String, Map<String, Object>> configMap = Collections.singletonMap("default.service", Collections.singletonMap("TYPE", "LoadBalancer"));
    // @formatter:off
    new Expectations() {

        {
            context.getConfiguration().getProcessorConfig();
            result = new ProcessorConfig(null, null, configMap);
        }
    };
    // @formatter:on
    EnricherConfig config = new EnricherConfig("default.service", context);
    assertEquals("LoadBalancer", config.get(EnricherConfigTest.Config.TYPE));
}
Also used : Expectations(mockit.Expectations) Map(java.util.Map) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) Test(org.junit.Test)

Example 15 with ProcessorConfig

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

the class DebugEnricherTest method setUp.

@Before
public void setUp() {
    properties = new Properties();
    processorConfig = new ProcessorConfig();
    klb = new KubernetesListBuilder();
    // @formatter:off
    klb.addToItems(new DeploymentBuilder().editOrNewSpec().editOrNewTemplate().editOrNewMetadata().withName("template-name").endMetadata().editOrNewSpec().addNewContainer().withImage("container/image").endContainer().endSpec().endTemplate().endSpec().build());
    new Expectations() {

        {
            context.getProperties();
            result = properties;
            context.getConfiguration().getProcessorConfig();
            result = processorConfig;
        }
    };
// @formatter:on
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Expectations(mockit.Expectations) Properties(java.util.Properties) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) Before(org.junit.Before)

Aggregations

ProcessorConfig (org.eclipse.jkube.kit.config.resource.ProcessorConfig)33 Expectations (mockit.Expectations)22 Before (org.junit.Before)14 Test (org.junit.Test)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)12 Properties (java.util.Properties)12 TreeMap (java.util.TreeMap)6 Configuration (org.eclipse.jkube.kit.enricher.api.model.Configuration)6 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)4 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)4 ArrayList (java.util.ArrayList)4 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)4 File (java.io.File)3 URLClassLoader (java.net.URLClassLoader)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ProjectClassLoaders (org.eclipse.jkube.kit.common.util.ProjectClassLoaders)3 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)3 TypeToken (com.google.common.reflect.TypeToken)2 Gson (com.google.gson.Gson)2