Search in sources :

Example 51 with ImageConfiguration

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

the class DefaultServiceEnricherTest method setupExpectations.

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

        {
            Configuration configuration = Configuration.builder().image(imageConfiguration).processorConfig(new ProcessorConfig(null, null, Collections.singletonMap("jkube-service", config))).build();
            context.getConfiguration();
            result = configuration;
            imageConfiguration.getBuildConfiguration();
            result = initBuildConfig(withPorts);
        }
    };
}
Also used : Expectations(mockit.Expectations) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Configuration(org.eclipse.jkube.kit.enricher.api.model.Configuration) TreeMap(java.util.TreeMap) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig)

Example 52 with ImageConfiguration

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

Example 53 with ImageConfiguration

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

the class ContainerHandlerTest method getImageNameTest.

@Test
public void getImageNameTest() {
    ContainerHandler handler = createContainerHandler(project);
    // Image Configuration with name and without registry
    ImageConfiguration imageConfiguration2 = ImageConfiguration.builder().name("test").alias("test-app").build(buildImageConfiguration1).build();
    // Image Configuration without name and with registry
    ImageConfiguration imageConfiguration3 = ImageConfiguration.builder().alias("test-app").build(buildImageConfiguration1).registry("docker.io").build();
    // Image Configuration without name and registry
    ImageConfiguration imageConfiguration4 = ImageConfiguration.builder().alias("test-app").build(buildImageConfiguration1).registry("docker.io").build();
    images.clear();
    images.add(imageConfiguration1);
    images.add(imageConfiguration2);
    images.add(imageConfiguration3);
    images.add(imageConfiguration4);
    containers = handler.getContainers(config1, images);
    assertEquals("docker.io/test:latest", containers.get(0).getImage());
    assertEquals("test:latest", containers.get(1).getImage());
    assertNull(containers.get(2).getImage());
    assertNull(containers.get(3).getImage());
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Test(org.junit.Test)

Example 54 with ImageConfiguration

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

the class DeploymentConfigHandlerTest method get_withNoImages_shouldReturnConfigWithNoContainers.

@Test
public void get_withNoImages_shouldReturnConfigWithNoContainers() {
    // Given
    final ResourceConfig resourceConfig = resourceConfigBuilder.controllerName("controller").build();
    final List<ImageConfiguration> images = Collections.emptyList();
    // When
    final DeploymentConfig result = deploymentConfigHandler.get(resourceConfig, images);
    // Then
    assertThat(result).hasFieldOrPropertyWithValue("metadata.name", "controller").extracting("spec.template.spec.containers").asList().isEmpty();
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test)

Example 55 with ImageConfiguration

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

the class DeploymentHandlerTest method before.

@Before
public void before() {
    // volume config with name and multiple mount
    mounts.add("/path/system");
    mounts.add("/path/sys");
    ports.add("8080");
    ports.add("9090");
    tags.add("latest");
    tags.add("test");
    VolumeConfig volumeConfig1 = VolumeConfig.builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
    volumes1.add(volumeConfig1);
    // container name with alias
    final BuildConfiguration buildImageConfiguration = BuildConfiguration.builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compressionString("gzip").build();
    ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("test").alias("test-app").build(buildImageConfiguration).registry("docker.io").build();
    images.add(imageConfiguration);
    deploymentHandler = new DeploymentHandler(new PodTemplateHandler(new ContainerHandler(project.getProperties(), new GroupArtifactVersion("g", "a", "v"), probeHandler)));
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) GroupArtifactVersion(org.eclipse.jkube.kit.config.resource.GroupArtifactVersion) VolumeConfig(org.eclipse.jkube.kit.config.resource.VolumeConfig) Before(org.junit.Before)

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