Search in sources :

Example 61 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project flink-kubernetes-operator by apache.

the class IngressUtils method updateIngressRules.

public static void updateIngressRules(FlinkDeployment flinkDeployment, Configuration effectiveConfig, String operatorNamespace, KubernetesClient client, boolean remove) {
    if (flinkDeployment.getSpec().getIngressDomain() != null) {
        final IngressRule ingressRule = fromDeployment(flinkDeployment, effectiveConfig);
        getIngress(operatorNamespace, client).ifPresent(ingress -> {
            Ingress updated;
            if (remove) {
                updated = new IngressBuilder(ingress).editSpec().removeFromRules(ingressRule).endSpec().build();
            } else {
                updated = new IngressBuilder(ingress).editSpec().addToRules(ingressRule).endSpec().build();
            }
            LOG.info("Updating ingress rules {}", ingress);
            client.resourceList(updated).inNamespace(operatorNamespace).createOrReplace();
        });
    }
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress)

Example 62 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project jkube by eclipse.

the class ApplyServiceTest method testApplyToMultipleNamespacesOverriddenWhenNamespaceConfigured.

@Test
public void testApplyToMultipleNamespacesOverriddenWhenNamespaceConfigured() throws InterruptedException {
    // Given
    ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("cm1").withNamespace("default").endMetadata().build();
    Ingress ingress = new IngressBuilder().withNewMetadata().withName("ing1").withNamespace("default").endMetadata().build();
    ServiceAccount serviceAccount = new ServiceAccountBuilder().withNewMetadata().withName("default").endMetadata().build();
    List<HasMetadata> entities = new ArrayList<>();
    entities.add(configMap);
    entities.add(serviceAccount);
    entities.add(ingress);
    WebServerEventCollector collector = new WebServerEventCollector();
    mockServer.expect().post().withPath("/api/v1/namespaces/default/configmaps").andReply(collector.record("configmap-default-ns-create").andReturn(HTTP_OK, configMap)).once();
    mockServer.expect().post().withPath("/apis/networking.k8s.io/v1/namespaces/default/ingresses").andReply(collector.record("ingress-default-ns-create").andReturn(HTTP_OK, ingress)).once();
    mockServer.expect().post().withPath("/api/v1/namespaces/default/serviceaccounts").andReply(collector.record("serviceaccount-default-ns-create").andReturn(HTTP_OK, serviceAccount)).once();
    // When
    applyService.applyEntities(null, entities, log, 5);
    // Then
    collector.assertEventsRecordedInOrder("configmap-default-ns-create", "serviceaccount-default-ns-create", "ingress-default-ns-create");
    assertEquals(5, mockServer.getOpenShiftMockServer().getRequestCount());
    applyService.setFallbackNamespace(null);
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ArrayList(java.util.ArrayList) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) WebServerEventCollector(org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector) Test(org.junit.Test)

Example 63 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project jkube by eclipse.

the class ExtensionsV1Beta1IngressConverterTest method testConvert.

@Test
public void testConvert() {
    // Given
    io.fabric8.kubernetes.api.model.networking.v1.Ingress networkV1Ingress = new IngressBuilder().withNewMetadata().withName("test-ing").endMetadata().withNewSpec().withIngressClassName("external-lb").addNewTl().withHosts("test-svc.org.eclipse.jkube").withSecretName("test-jkube-ingress").endTl().addNewRule().withHost("test-svc.org.eclipse.jkube").withNewHttp().addNewPath().withPath("/testpath").withPathType("Prefix").withNewBackend().withNewService().withName("test").withNewPort().withNumber(80).endPort().endService().withNewResource("k8s.example.com", "StorageBucket", "icon-assets").endBackend().endPath().endHttp().endRule().endSpec().build();
    // When
    Ingress ingress = ExtensionsV1beta1IngressConverter.convert(networkV1Ingress);
    // Then
    assertThat(ingress).hasFieldOrPropertyWithValue("metadata.name", "test-ing").hasFieldOrPropertyWithValue("spec.ingressClassName", "external-lb").satisfies(ir -> assertThat(ir.getSpec().getTls()).asList().hasSize(1).element(0).hasFieldOrPropertyWithValue("secretName", "test-jkube-ingress").extracting("hosts").asList().hasSize(1).element(0).isEqualTo("test-svc.org.eclipse.jkube")).extracting("spec.rules").asList().hasSize(1).element(0).hasFieldOrPropertyWithValue("host", "test-svc.org.eclipse.jkube").extracting("http.paths").asList().element(0).hasFieldOrPropertyWithValue("path", "/testpath").hasFieldOrPropertyWithValue("pathType", "Prefix").hasFieldOrPropertyWithValue("backend.serviceName", "test").hasFieldOrPropertyWithValue("backend.servicePort", new IntOrString(80)).hasFieldOrPropertyWithValue("backend.resource.apiGroup", "k8s.example.com").hasFieldOrPropertyWithValue("backend.resource.kind", "StorageBucket").hasFieldOrPropertyWithValue("backend.resource.name", "icon-assets");
}
Also used : IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Test(org.junit.Test) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Test(org.junit.Test)

Example 64 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project jkube by eclipse.

the class ExtensionsV1Beta1IngressConverterTest method testConvertWithNullSpec.

@Test
public void testConvertWithNullSpec() {
    // Given
    final io.fabric8.kubernetes.api.model.networking.v1.Ingress from = new IngressBuilder().withNewMetadata().withName("ingress").endMetadata().build();
    // When
    final Ingress result = ExtensionsV1beta1IngressConverter.convert(from);
    // Then
    assertThat(result).hasFieldOrPropertyWithValue("spec", null).hasFieldOrPropertyWithValue("metadata.name", "ingress");
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Test(org.junit.Test)

Example 65 with IngressBuilder

use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project jkube by eclipse.

the class NetworkingV1IngressGenerator method generate.

protected static Ingress generate(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder, String routeDomainPostfix, String host, List<IngressRuleConfig> ingressRuleConfigs, List<IngressTlsConfig> ingressTlsConfigs, KitLogger log) {
    ObjectMeta serviceMetadata = serviceBuilder.buildMetadata();
    if (serviceMetadata == null) {
        log.info("No Metadata for service! ");
    }
    if (isExposedService(serviceMetadata) && shouldCreateExternalURLForService(serviceBuilder, log)) {
        Objects.requireNonNull(serviceMetadata);
        String serviceName = serviceMetadata.getName();
        if (!hasIngress(listBuilder, serviceName)) {
            Integer servicePort = getServicePort(serviceBuilder);
            if (servicePort != null) {
                return new IngressBuilder().withMetadata(getIngressMetadata(serviceMetadata)).withSpec(getIngressSpec(routeDomainPostfix, host, serviceName, servicePort, ingressRuleConfigs, ingressTlsConfigs)).build();
            }
        }
    }
    return null;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)

Aggregations

IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)39 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)31 Test (org.junit.jupiter.api.Test)28 IngressBuilder (io.fabric8.kubernetes.api.model.extensions.IngressBuilder)13 ArrayList (java.util.ArrayList)13 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)11 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)11 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)9 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)9 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)8 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)8 Test (org.junit.Test)8 IngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder)7 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder)6 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)5 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)5 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPathBuilder)5 Ingress (io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress)5 HashMap (java.util.HashMap)5 HTTPIngressPath (io.fabric8.kubernetes.api.model.extensions.HTTPIngressPath)4