Search in sources :

Example 41 with ResourceConfig

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

the class BaseEnricherGetReplicaCountTest method withEmptyListBuilderAndEmptyResourceConfigShouldReturnDefault.

@Test
public void withEmptyListBuilderAndEmptyResourceConfigShouldReturnDefault() {
    // When
    final int result = getReplicaCount(new KubernetesListBuilder().addToItems(new ConfigMapBuilder()), new ResourceConfig(), 1337);
    // Then
    assertThat(result).isEqualTo(1337);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 42 with ResourceConfig

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

the class KubernetesResourceTask method initJKubeServiceHubBuilder.

@Override
protected JKubeServiceHub.JKubeServiceHubBuilder initJKubeServiceHubBuilder() {
    JKubeServiceHub.JKubeServiceHubBuilder builder = super.initJKubeServiceHubBuilder();
    ResourceConfig resourceConfig = kubernetesExtension.resources;
    if (kubernetesExtension.getNamespaceOrNull() != null) {
        resourceConfig = ResourceConfig.toBuilder(resourceConfig).namespace(kubernetesExtension.getNamespaceOrNull()).build();
    }
    final ResourceServiceConfig resourceServiceConfig = ResourceServiceConfig.builder().project(kubernetesExtension.javaProject).resourceDir(resolveResourceSourceDirectory()).targetDir(kubernetesExtension.getResourceTargetDirectoryOrDefault()).resourceFileType(kubernetesExtension.getResourceFileTypeOrDefault()).resourceConfig(resourceConfig).interpolateTemplateParameters(kubernetesExtension.getInterpolateTemplateParametersOrDefault()).resourceFilesProcessor(this::gradleFilterFiles).build();
    builder.resourceService(new LazyBuilder<>(() -> new DefaultResourceService(resourceServiceConfig)));
    return builder;
}
Also used : DefaultResourceService(org.eclipse.jkube.kit.resource.service.DefaultResourceService) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) ResourceServiceConfig(org.eclipse.jkube.kit.config.resource.ResourceServiceConfig) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub)

Example 43 with ResourceConfig

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

the class IngressEnricherTest method testCreateIngressFromXMLConfigWithConfiguredServiceName.

@Test
public void testCreateIngressFromXMLConfigWithConfiguredServiceName() {
    // Given
    ResourceConfig resourceConfig = ResourceConfig.builder().ingress(IngressConfig.builder().ingressRule(IngressRuleConfig.builder().host("foo.bar.com").path(IngressRulePathConfig.builder().pathType("ImplementationSpecific").path("/icons").serviceName("hello-k8s").servicePort(80).build()).build()).ingressRule(IngressRuleConfig.builder().host("*.foo.com").path(IngressRulePathConfig.builder().path("/icons-storage").pathType("Exact").resource(IngressRulePathResourceConfig.builder().apiGroup("k8s.example.com").kind("StorageBucket").name("icon-assets").build()).build()).build()).ingressTlsConfig(IngressTlsConfig.builder().host("https-example.foo.com").secretName("testsecret-tls").build()).build()).build();
    // @formatter:off
    new Expectations() {

        {
            // Enable creation of Ingress for Service of type LoadBalancer
            context.getProperty(CREATE_EXTERNAL_URLS);
            result = "true";
            context.getConfiguration().getResource();
            result = resourceConfig;
        }
    };
    // @formatter:on
    Service providedService = initTestService().build();
    KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(providedService);
    // When
    ingressEnricher.create(PlatformMode.kubernetes, kubernetesListBuilder);
    // Then
    assertThat(kubernetesListBuilder).extracting(KubernetesListBuilder::buildItems).asList().hasSize(2).element(1).asInstanceOf(InstanceOfAssertFactories.type(Ingress.class)).hasFieldOrPropertyWithValue("apiVersion", "networking.k8s.io/v1").hasFieldOrPropertyWithValue("metadata.name", providedService.getMetadata().getName()).extracting(Ingress::getSpec).satisfies(is -> assertThat(is).extracting("tls").asList().element(0).hasFieldOrPropertyWithValue("secretName", "testsecret-tls").extracting("hosts").asList().containsExactly("https-example.foo.com")).extracting(IngressSpec::getRules).satisfies(r -> assertThat(r).asList().element(0).hasFieldOrPropertyWithValue("host", "foo.bar.com").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/icons").hasFieldOrPropertyWithValue("pathType", "ImplementationSpecific").hasFieldOrPropertyWithValue("backend.service.name", "hello-k8s").hasFieldOrPropertyWithValue("backend.service.port.number", 80)).satisfies(r -> assertThat(r).asList().element(1).hasFieldOrPropertyWithValue("host", "*.foo.com").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/icons-storage").hasFieldOrPropertyWithValue("pathType", "Exact").hasFieldOrPropertyWithValue("backend.resource.apiGroup", "k8s.example.com").hasFieldOrPropertyWithValue("backend.resource.kind", "StorageBucket").hasFieldOrPropertyWithValue("backend.resource.name", "icon-assets"));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Expectations(mockit.Expectations) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) Configuration(org.eclipse.jkube.kit.enricher.api.model.Configuration) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) IngressRulePathConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathConfig) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) IngressRuleConfig(org.eclipse.jkube.kit.config.resource.IngressRuleConfig) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) Service(io.fabric8.kubernetes.api.model.Service) IngressRulePathResourceConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) IngressTlsConfig(org.eclipse.jkube.kit.config.resource.IngressTlsConfig) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Before(org.junit.Before) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JKubeEnricherContext(org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext) Test(org.junit.Test) CREATE_EXTERNAL_URLS(org.eclipse.jkube.kit.enricher.api.BaseEnricher.CREATE_EXTERNAL_URLS) KitLogger(org.eclipse.jkube.kit.common.KitLogger) List(java.util.List) TreeMap(java.util.TreeMap) IngressConfig(org.eclipse.jkube.kit.config.resource.IngressConfig) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Collections(java.util.Collections) Mocked(mockit.Mocked) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) IngressRulePathResourceConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig) Test(org.junit.Test)

Example 44 with ResourceConfig

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

the class IngressEnricherTest method testGetIngressRuleXMLConfigWithNonNullResourceConfig.

@Test
public void testGetIngressRuleXMLConfigWithNonNullResourceConfig() {
    // Given
    ResourceConfig resourceConfig = ResourceConfig.builder().ingress(IngressConfig.builder().ingressRule(IngressRuleConfig.builder().host("host1").build()).build()).build();
    // When
    List<IngressRuleConfig> ingressRuleXMLConfig = IngressEnricher.getIngressRuleXMLConfig(resourceConfig);
    // Then
    assertThat(ingressRuleXMLConfig).asList().hasSize(1);
}
Also used : IngressRuleConfig(org.eclipse.jkube.kit.config.resource.IngressRuleConfig) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) IngressRulePathResourceConfig(org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig) Test(org.junit.Test)

Example 45 with ResourceConfig

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

the class DefaultNamespaceEnricherTest method enrichWithNamespaceFragmentWithNoStatus.

@Test
public void enrichWithNamespaceFragmentWithNoStatus() {
    // Given
    setExpectations(new Properties(), new ResourceConfig());
    final KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder();
    kubernetesListBuilder.addToItems(new NamespaceBuilder().withNewMetadata().withName("test-jkube").endMetadata().build());
    // When
    new DefaultNamespaceEnricher(context).enrich(PlatformMode.kubernetes, kubernetesListBuilder);
    // Then
    assertThat(kubernetesListBuilder.build().getItems()).hasSize(1);
    assertThat(kubernetesListBuilder.build().getItems().iterator().next()).hasFieldOrPropertyWithValue("metadata.name", "test-jkube");
    assertNull(kubernetesListBuilder.build().getItems().get(0).getMetadata().getNamespace());
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Properties(java.util.Properties) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) 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