Search in sources :

Example 36 with ResourceConfig

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

the class DefaultResourceService method generateAppResources.

private KubernetesListBuilder generateAppResources(PlatformMode platformMode, EnricherManager enricherManager, KitLogger log) throws IOException {
    final ResourceConfig resourceConfig = resourceServiceConfig.getResourceConfig();
    final File resourceDir = resourceServiceConfig.getResourceDir();
    try {
        File[] resourceFiles = listResourceFragments(resourceDir, resourceConfig != null ? resourceConfig.getRemotes() : null, log);
        log.info("Using resource templates from %s", resourceDir);
        final File[] processedResource = processResourceFiles(resourceFiles);
        KubernetesListBuilder builder = processResourceFragments(platformMode, processedResource);
        // Create default resources for app resources only
        enricherManager.createDefaultResources(platformMode, builder);
        // Enrich descriptors
        enricherManager.enrich(platformMode, builder);
        return builder;
    } catch (ConstraintViolationException e) {
        String message = ValidationUtil.createValidationMessage(e.getConstraintViolations());
        log.error("ConstraintViolationException: %s", message);
        throw new IOException(message, e);
    }
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ConstraintViolationException(javax.validation.ConstraintViolationException) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) IOException(java.io.IOException) File(java.io.File)

Example 37 with ResourceConfig

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

the class WatchMojoTest method executeInternal_whenNamespaceConfiguredInResourceConfig_shouldDelegateToWatcherManagerWithClusterAccessNamespace.

@Test
public void executeInternal_whenNamespaceConfiguredInResourceConfig_shouldDelegateToWatcherManagerWithClusterAccessNamespace() throws MojoExecutionException {
    // Given
    ResourceConfig mockedResourceConfig = mock(ResourceConfig.class);
    when(mockedResourceConfig.getNamespace()).thenReturn("namespace-from-resourceconfig");
    watchMojo = new WatchMojo() {

        {
            project = mavenProject;
            settings = mavenSettings;
            kubernetesManifest = kubernetesManifestFile;
            imageConfigResolver = mockedImageConfigResolver;
            dockerAccessFactory = mockedDockerAccessFactory;
            kubernetesClient = defaultKubernetesClient;
            javaProject = mockedJavaProject;
            jkubeServiceHub = mockedJKubeServiceHub;
            clusterAccess = mockedClusterAccess;
            resources = mockedResourceConfig;
        }
    };
    // When
    watchMojo.executeInternal();
    // Then
    watcherManagerMockedStatic.verify(() -> WatcherManager.watch(any(), eq("namespace-from-resourceconfig"), any(), any()), times(1));
}
Also used : ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 38 with ResourceConfig

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

the class KubernetesUndeployServiceTest method undeployWithManifestShouldDeleteAllEntities.

@Test
public void undeployWithManifestShouldDeleteAllEntities(@Mocked File file) throws Exception {
    // Given
    final ResourceConfig resourceConfig = ResourceConfig.builder().namespace("default").build();
    final Namespace namespace = new NamespaceBuilder().withNewMetadata().withName("default").endMetadata().build();
    final Pod pod = new PodBuilder().withNewMetadata().withName("MrPoddington").endMetadata().build();
    final Service service = new Service();
    // @formatter:off
    new Expectations() {

        {
            file.exists();
            result = true;
            file.isFile();
            result = true;
            kubernetesHelper.loadResources(file);
            result = Arrays.asList(namespace, pod, service);
        }
    };
    // @formatter:on
    // When
    kubernetesUndeployService.undeploy(null, resourceConfig, file);
    // Then
    // @formatter:off
    new Verifications() {

        {
            kubernetesHelper.getKind((HasMetadata) any);
            times = 3;
            jKubeServiceHub.getClient().resource(pod).inNamespace("default").withPropagationPolicy(DeletionPropagation.BACKGROUND).delete();
            times = 1;
            jKubeServiceHub.getClient().resource(service).inNamespace("default").withPropagationPolicy(DeletionPropagation.BACKGROUND).delete();
            times = 1;
            jKubeServiceHub.getClient().resource(namespace).inNamespace("default").withPropagationPolicy(DeletionPropagation.BACKGROUND).delete();
            times = 1;
        }
    };
// @formatter:on
}
Also used : Expectations(mockit.Expectations) Pod(io.fabric8.kubernetes.api.model.Pod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Service(io.fabric8.kubernetes.api.model.Service) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Verifications(mockit.Verifications) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) Test(org.junit.Test)

Example 39 with ResourceConfig

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

the class OpenshiftBuildServiceIntegrationTest method init.

@Before
public void init() throws Exception {
    final KitLogger logger = new KitLogger.StdoutLogger();
    baseDirectory = temporaryFolder.newFolder("openshift-build-service");
    target = temporaryFolder.newFolder("openshift-build-service", "target");
    final File emptyDockerBuildTar = new File(target, "docker-build.tar");
    FileUtils.touch(emptyDockerBuildTar);
    baseDir = baseDirectory.getAbsolutePath();
    projectName = "myapp";
    FileUtils.deleteDirectory(new File(baseDir, projectName));
    final File dockerFile = new File(baseDir, "Docker.tar");
    FileUtils.touch(dockerFile);
    openshiftHelper = mockStatic(OpenshiftHelper.class);
    openshiftHelper.when(() -> OpenshiftHelper.isOpenShift(eq(mockServer.getOpenshiftClient()))).thenReturn(true);
    jKubeBuildTarArchiver = mockConstruction(JKubeBuildTarArchiver.class, (mock, ctx) -> when(mock.createArchive(any(File.class), any(BuildDirs.class), eq(ArchiveCompression.none))).thenReturn(emptyDockerBuildTar));
    mockedResourceConfig = mock(ResourceConfig.class, RETURNS_DEEP_STUBS);
    when(mockedResourceConfig.getNamespace()).thenReturn("ns1");
    jKubeServiceHub = mock(JKubeServiceHub.class, RETURNS_DEEP_STUBS);
    when(jKubeServiceHub.getClusterAccess().createDefaultClient()).thenReturn(mockServer.getOpenshiftClient());
    when(jKubeServiceHub.getLog()).thenReturn(logger);
    when(jKubeServiceHub.getDockerServiceHub().getArchiveService()).thenReturn(new ArchiveService(AssemblyManager.getInstance(), logger));
    when(jKubeServiceHub.getBuildServiceConfig().getBuildDirectory()).thenReturn(target.getAbsolutePath());
    when(jKubeServiceHub.getConfiguration()).thenReturn(JKubeConfiguration.builder().outputDirectory(target.getAbsolutePath()).project(JavaProject.builder().baseDirectory(baseDirectory).buildDirectory(target).build()).registryConfig(RegistryConfig.builder().build()).build());
    image = ImageConfiguration.builder().name(projectName).build(BuildConfiguration.builder().from(projectName).build()).build();
    defaultConfig = BuildServiceConfig.builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-s2i-suffix2").resourceConfig(mockedResourceConfig).jKubeBuildStrategy(JKubeBuildStrategy.s2i);
    defaultConfigSecret = defaultConfig.build().toBuilder().openshiftPullSecret("pullsecret-fabric8");
    dockerImageConfig = defaultConfig.build().toBuilder().buildOutputKind("DockerImage");
    dockerImageConfigSecret = defaultConfig.build().toBuilder().openshiftPullSecret("pullsecret-fabric8").openshiftPushSecret("pushsecret-fabric8").buildOutputKind("DockerImage");
    Serialization.jsonMapper().disable(SerializationFeature.INDENT_OUTPUT);
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Quantity(io.fabric8.kubernetes.api.model.Quantity) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) AssemblyManager(org.eclipse.jkube.kit.build.api.assembly.AssemblyManager) Map(java.util.Map) After(org.junit.After) Mockito.mockConstruction(org.mockito.Mockito.mockConstruction) Build(io.fabric8.openshift.api.model.Build) MockedConstruction(org.mockito.MockedConstruction) ArchiveCompression(org.eclipse.jkube.kit.common.archive.ArchiveCompression) ImmutableMap(com.google.common.collect.ImmutableMap) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) BuildRecreateMode(org.eclipse.jkube.kit.config.resource.BuildRecreateMode) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) StandardCharsets(java.nio.charset.StandardCharsets) MockedStatic(org.mockito.MockedStatic) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OpenshiftHelper(org.eclipse.jkube.kit.common.util.OpenshiftHelper) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) Assert.assertThrows(org.junit.Assert.assertThrows) Mockito.mockStatic(org.mockito.Mockito.mockStatic) HashMap(java.util.HashMap) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) Serialization(io.fabric8.kubernetes.client.utils.Serialization) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) JavaProject(org.eclipse.jkube.kit.common.JavaProject) ImageStream(io.fabric8.openshift.api.model.ImageStream) Before(org.junit.Before) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) JKubeBuildTarArchiver(org.eclipse.jkube.kit.build.api.assembly.JKubeBuildTarArchiver) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) WatchEvent(io.fabric8.kubernetes.api.model.WatchEvent) Assert.assertTrue(org.junit.Assert.assertTrue) ArchiveService(org.eclipse.jkube.kit.build.service.docker.ArchiveService) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) File(java.io.File) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) KitLogger(org.eclipse.jkube.kit.common.KitLogger) Rule(org.junit.Rule) OpenShiftServer(io.fabric8.openshift.client.server.mock.OpenShiftServer) Assembly(org.eclipse.jkube.kit.common.Assembly) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) OpenshiftBuildConfig(org.eclipse.jkube.kit.config.resource.OpenshiftBuildConfig) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) KitLogger(org.eclipse.jkube.kit.common.KitLogger) ArchiveService(org.eclipse.jkube.kit.build.service.docker.ArchiveService) OpenshiftHelper(org.eclipse.jkube.kit.common.util.OpenshiftHelper) JKubeBuildTarArchiver(org.eclipse.jkube.kit.build.api.assembly.JKubeBuildTarArchiver) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) File(java.io.File) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Before(org.junit.Before)

Example 40 with ResourceConfig

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

the class BaseEnricherGetReplicaCountTest method withDeploymentConfigAndDeploymentInListBuilderAndEmptyResourceConfigShouldReturnValueInFirstItem.

@Test
public void withDeploymentConfigAndDeploymentInListBuilderAndEmptyResourceConfigShouldReturnValueInFirstItem() {
    // Given
    final KubernetesListBuilder klb = new KubernetesListBuilder().addToItems(new DeploymentBuilder().withNewSpec().withReplicas(2).endSpec()).addToItems(new DeploymentConfigBuilder().withNewSpec().withReplicas(1).endSpec());
    final ResourceConfig resourceConfig = ResourceConfig.builder().replicas(313373).build();
    // When
    final int result = getReplicaCount(klb, resourceConfig, 1337);
    // Then
    assertThat(result).isEqualTo(2);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

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