Search in sources :

Example 46 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration 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 47 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class DefaultServiceEnricher method extractPorts.

// ========================================================================================================
// Port handling
private List<ServicePort> extractPorts(List<ImageConfiguration> images) {
    List<ServicePort> ret = new ArrayList<>();
    boolean isMultiPort = Boolean.parseBoolean(getConfig(Config.MULTI_PORT));
    List<ServicePort> configuredPorts = extractPortsFromConfig();
    for (ImageConfiguration image : images) {
        Map<String, String> labels = extractLabelsFromConfig(image);
        List<String> podPorts = getPortsFromBuildConfiguration(image);
        List<String> portsFromImageLabels = getLabelWithService(labels);
        if (podPorts.isEmpty()) {
            continue;
        }
        // Extract first port and remove first element
        if (portsFromImageLabels == null || portsFromImageLabels.isEmpty()) {
            addPortIfNotNull(ret, extractPortsFromImageSpec(image.getName(), podPorts.remove(0), shiftOrNull(configuredPorts), null));
        } else {
            for (String imageLabelPort : portsFromImageLabels) {
                addPortIfNotNull(ret, extractPortsFromImageSpec(image.getName(), podPorts.remove(0), shiftOrNull(configuredPorts), imageLabelPort));
            }
        }
        // Remaining port specs if multi-port is selected
        if (isMultiPort) {
            for (String port : podPorts) {
                addPortIfNotNull(ret, extractPortsFromImageSpec(image.getName(), port, shiftOrNull(configuredPorts), null));
            }
        }
    }
    // If there are still ports configured add them directly
    if (isMultiPort) {
        ret.addAll(mirrorMissingTargetPorts(configuredPorts));
    } else if (ret.isEmpty() && !configuredPorts.isEmpty()) {
        ret.addAll(mirrorMissingTargetPorts(Collections.singletonList(configuredPorts.get(0))));
    }
    return ret;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 48 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class ImageEnricher method mergeImageConfigurationWithContainerSpec.

// Add missing information to the given containers as found
// configured
private void mergeImageConfigurationWithContainerSpec(List<Container> containers) {
    int idx = 0;
    for (ImageConfiguration image : getImages()) {
        Container container = getContainer(idx, containers);
        mergeImagePullPolicy(image, container);
        mergeImage(image, container);
        mergeContainerName(image, container);
        mergeEnvVariables(container);
        idx++;
    }
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration)

Example 49 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class KubernetesResourceUtilTest method extractContainerName.

@Test
public void extractContainerName() {
    // Given
    final ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("dummy-image").registry("example.com/someregistry").name("test").build();
    // When
    final String result = KubernetesResourceUtil.extractContainerName(new GroupArtifactVersion("io.fabric8-test-", "fabric8-maven-plugin-dummy", "0"), imageConfiguration);
    // Then
    assertThat(result).isEqualTo("iofabric8-test--fabric8-maven-plugin-dummy");
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) GroupArtifactVersion(org.eclipse.jkube.kit.config.resource.GroupArtifactVersion) Test(org.junit.Test)

Example 50 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class ContainerHandlerTest method getRegistryTest.

@Test
public void getRegistryTest() {
    ContainerHandler handler = createContainerHandler(project1);
    ImageConfiguration imageConfig = ImageConfiguration.builder().name("test").alias("test-app").build(buildImageConfiguration1).build();
    images.clear();
    images.add(imageConfig);
    Properties properties = project1.getProperties();
    properties.setProperty("jkube.docker.pull.registry", "push.me");
    project1.setProperties(properties);
    containers = handler.getContainers(config1, images);
    project1.getProperties().remove("jkube.docker.pull.registry");
    assertEquals("push.me/test:latest", containers.get(0).getImage());
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)109 Test (org.junit.Test)75 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)29 RunImageConfiguration (org.eclipse.jkube.kit.config.image.RunImageConfiguration)28 File (java.io.File)26 ArrayList (java.util.ArrayList)19 Expectations (mockit.Expectations)15 GroupArtifactVersion (org.eclipse.jkube.kit.config.resource.GroupArtifactVersion)11 Before (org.junit.Before)11 IOException (java.io.IOException)9 Properties (java.util.Properties)8 KitLogger (org.eclipse.jkube.kit.common.KitLogger)8 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)7 JKubeServiceException (org.eclipse.jkube.kit.config.service.JKubeServiceException)7 WatchImageConfiguration (org.eclipse.jkube.kit.config.image.WatchImageConfiguration)6 ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)6 List (java.util.List)5 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)5 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)5 Container (io.fabric8.kubernetes.api.model.Container)4