Search in sources :

Example 31 with ResourceConfig

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

the class PodTemplateHandlerTest method getPodTemplate_withRestartPolicyAndResourceConfig_shouldGeneratePodTemplateWithConfiguredRestartPolicy.

@Test
public void getPodTemplate_withRestartPolicyAndResourceConfig_shouldGeneratePodTemplateWithConfiguredRestartPolicy() {
    // Given
    ResourceConfig config = ResourceConfig.builder().build();
    // When
    PodTemplateSpec podTemplateSpec = podTemplateHandler.getPodTemplate(config, "Always", images);
    // Then
    assertThat(podTemplateSpec).hasFieldOrPropertyWithValue("spec.restartPolicy", "Always");
}
Also used : PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 32 with ResourceConfig

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

the class PodTemplateHandlerTest method podWithoutVolumeTemplateHandlerTest.

@Test
public void podWithoutVolumeTemplateHandlerTest() {
    // Pod without Volume Config
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).build();
    PodTemplateSpec podTemplateSpec = podTemplateHandler.getPodTemplate(config, null, images);
    // Assertion
    assertEquals("test-account", podTemplateSpec.getSpec().getServiceAccountName());
    assertTrue(podTemplateSpec.getSpec().getVolumes().isEmpty());
    assertNotNull(podTemplateSpec.getSpec().getContainers());
    assertEquals("test-app", podTemplateSpec.getSpec().getContainers().get(0).getName());
    assertEquals("docker.io/test:latest", podTemplateSpec.getSpec().getContainers().get(0).getImage());
    assertEquals("IfNotPresent", podTemplateSpec.getSpec().getContainers().get(0).getImagePullPolicy());
}
Also used : PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 33 with ResourceConfig

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

the class PodTemplateHandlerTest method podWithVolumeTemplateHandlerTest.

@Test
public void podWithVolumeTemplateHandlerTest() {
    // Config with Volume Config and ServiceAccount
    // valid type
    VolumeConfig volumeConfig1 = VolumeConfig.builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
    volumes1.clear();
    volumes1.add(volumeConfig1);
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
    PodTemplateSpec podTemplateSpec = podTemplateHandler.getPodTemplate(config, null, images);
    // Assertion
    assertEquals("test-account", podTemplateSpec.getSpec().getServiceAccountName());
    assertFalse(podTemplateSpec.getSpec().getVolumes().isEmpty());
    assertEquals("test", podTemplateSpec.getSpec().getVolumes().get(0).getName());
    assertEquals("/test/path", podTemplateSpec.getSpec().getVolumes().get(0).getHostPath().getPath());
    assertNotNull(podTemplateSpec.getSpec().getContainers());
}
Also used : PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) VolumeConfig(org.eclipse.jkube.kit.config.resource.VolumeConfig) Test(org.junit.Test)

Example 34 with ResourceConfig

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

the class PodTemplateHandlerTest method podWithInvalidVolumeTypeTemplateHandlerTest.

@Test
public void podWithInvalidVolumeTypeTemplateHandlerTest() {
    // invalid type
    VolumeConfig volumeConfig1 = VolumeConfig.builder().name("test").mounts(mounts).type("hoStPath").path("/test/path").build();
    volumes1.clear();
    volumes1.add(volumeConfig1);
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
    PodTemplateSpec podTemplateSpec = podTemplateHandler.getPodTemplate(config, null, images);
    // Assertion
    assertEquals("test-account", podTemplateSpec.getSpec().getServiceAccountName());
    assertTrue(podTemplateSpec.getSpec().getVolumes().isEmpty());
    assertNotNull(podTemplateSpec.getSpec().getContainers());
}
Also used : PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) VolumeConfig(org.eclipse.jkube.kit.config.resource.VolumeConfig) Test(org.junit.Test)

Example 35 with ResourceConfig

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

the class AbstractDockerMojo method buildServiceConfigBuilder.

protected BuildServiceConfig.BuildServiceConfigBuilder buildServiceConfigBuilder() {
    return BuildServiceConfig.builder().buildRecreateMode(BuildRecreateMode.fromParameter(buildRecreate)).jKubeBuildStrategy(getJKubeBuildStrategy()).forcePull(forcePull).imagePullManager(ImagePullManager.createImagePullManager(imagePullPolicy, autoPull, project.getProperties())).buildDirectory(project.getBuild().getDirectory()).resourceConfig(resources).resourceDir(resourceDir).attacher((classifier, destFile) -> {
        if (destFile.exists()) {
            projectHelper.attachArtifact(project, "yml", classifier, destFile);
        }
    }).enricherTask(builder -> {
        DefaultEnricherManager enricherManager = new DefaultEnricherManager(getEnricherContext(), useProjectClasspath ? javaProject.getCompileClassPathElements() : Collections.emptyList());
        enricherManager.enrich(PlatformMode.kubernetes, builder);
        enricherManager.enrich(PlatformMode.openshift, builder);
    });
}
Also used : ResourceUtil(org.eclipse.jkube.kit.common.util.ResourceUtil) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Ansi(org.fusesource.jansi.Ansi) ProfileUtil(org.eclipse.jkube.kit.profile.ProfileUtil) Enumeration(java.util.Enumeration) URL(java.net.URL) DEFAULT_MAX_CONNECTIONS(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory.DockerAccessContext.DEFAULT_MAX_CONNECTIONS) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Parameter(org.apache.maven.plugins.annotations.Parameter) KitLoggerProvider(org.eclipse.jkube.maven.plugin.mojo.KitLoggerProvider) ImageConfigResolver(org.eclipse.jkube.kit.build.service.docker.config.handler.ImageConfigResolver) Settings(org.apache.maven.settings.Settings) DockerMachineConfiguration(org.eclipse.jkube.kit.build.service.docker.config.DockerMachineConfiguration) MavenProject(org.apache.maven.project.MavenProject) AnsiLogger(org.eclipse.jkube.kit.common.util.AnsiLogger) EnvUtil(org.eclipse.jkube.kit.common.util.EnvUtil) Map(java.util.Map) ConfigHelper(org.eclipse.jkube.kit.build.service.docker.helper.ConfigHelper) Method(java.lang.reflect.Method) WatchMode(org.eclipse.jkube.kit.config.image.WatchMode) BuildRecreateMode(org.eclipse.jkube.kit.config.resource.BuildRecreateMode) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) RuntimeMode(org.eclipse.jkube.kit.config.resource.RuntimeMode) MojoExecution(org.apache.maven.plugin.MojoExecution) ImagePullManager(org.eclipse.jkube.kit.build.service.docker.ImagePullManager) JKubeEnricherContext(org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext) LineNumberReader(java.io.LineNumberReader) ContainerNamingUtil(org.eclipse.jkube.kit.build.service.docker.helper.ContainerNamingUtil) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageUtils(org.apache.maven.shared.utils.logging.MessageUtils) DockerServiceHub(org.eclipse.jkube.kit.build.service.docker.DockerServiceHub) List(java.util.List) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Optional(java.util.Optional) LogOutputSpecFactory(org.eclipse.jkube.kit.build.service.docker.access.log.LogOutputSpecFactory) ClusterConfiguration(org.eclipse.jkube.kit.config.access.ClusterConfiguration) DockerAccess(org.eclipse.jkube.kit.build.service.docker.access.DockerAccess) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) Context(org.codehaus.plexus.context.Context) AbstractMojo(org.apache.maven.plugin.AbstractMojo) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) MavenProjectHelper(org.apache.maven.project.MavenProjectHelper) GeneratorManager(org.eclipse.jkube.generator.api.GeneratorManager) SecDispatcher(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher) BuildReferenceDateUtil.getBuildTimestamp(org.eclipse.jkube.kit.common.util.BuildReferenceDateUtil.getBuildTimestamp) LogDispatcher(org.eclipse.jkube.kit.build.service.docker.access.log.LogDispatcher) Component(org.apache.maven.plugins.annotations.Component) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) RegistryAuthConfiguration(org.eclipse.jkube.kit.config.image.build.RegistryAuthConfiguration) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) GavLabel(org.eclipse.jkube.kit.build.core.GavLabel) PlexusConstants(org.codehaus.plexus.PlexusConstants) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AuthConfigFactory(org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Contextualizable(org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable) ContextException(org.codehaus.plexus.context.ContextException) DEFAULT_LOG_PREFIX(org.eclipse.jkube.maven.plugin.mojo.build.AbstractJKubeMojo.DEFAULT_LOG_PREFIX) JavaProject(org.eclipse.jkube.kit.common.JavaProject) MavenSession(org.apache.maven.execution.MavenSession) DockerAccessFactory(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory) MavenUtil(org.eclipse.jkube.kit.common.util.MavenUtil) KubernetesClientUtil.updateResourceConfigNamespace(org.eclipse.jkube.kit.config.service.kubernetes.KubernetesClientUtil.updateResourceConfigNamespace) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) BuildReferenceDateUtil.getBuildTimestampFile(org.eclipse.jkube.kit.common.util.BuildReferenceDateUtil.getBuildTimestampFile) KitLogger(org.eclipse.jkube.kit.common.KitLogger) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultEnricherManager(org.eclipse.jkube.kit.enricher.api.DefaultEnricherManager) EnricherContext(org.eclipse.jkube.kit.enricher.api.EnricherContext) Collections(java.util.Collections) DefaultEnricherManager(org.eclipse.jkube.kit.enricher.api.DefaultEnricherManager)

Aggregations

ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)69 Test (org.junit.Test)60 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)17 Properties (java.util.Properties)10 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)9 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)7 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)7 ArrayList (java.util.ArrayList)5 Expectations (mockit.Expectations)5 File (java.io.File)4 IngressRulePathResourceConfig (org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 Service (io.fabric8.kubernetes.api.model.Service)3 IOException (java.io.IOException)3 List (java.util.List)3 Optional (java.util.Optional)3 KitLogger (org.eclipse.jkube.kit.common.KitLogger)3 JKubeServiceHub (org.eclipse.jkube.kit.config.service.JKubeServiceHub)3 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2