Search in sources :

Example 51 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project xp-operator by enonic.

the class OperatorIngressLabel method setStatus.

private void setStatus(final Ingress ingress) {
    // Collect all nodegroup vhost states
    Map<String, Xp7ConfigStatus.State> states = searchers.xp7Config().stream().filter(inSameNamespaceAs(ingress)).filter(isDeleted().negate()).filter(this::isVHostConfig).collect(Collectors.toMap(c -> c.getSpec().getNodeGroup(), c -> c.getStatus().getState()));
    // Set all nodeGroups state
    if (states.values().stream().anyMatch(s -> !s.equals(Xp7ConfigStatus.State.READY))) {
        states.put(cfgStr("operator.charts.values.allNodesKey"), Xp7ConfigStatus.State.PENDING);
    } else {
        states.put(cfgStr("operator.charts.values.allNodesKey"), Xp7ConfigStatus.State.READY);
    }
    // Figure out state
    boolean loaded = true;
    for (IngressRule r : ingress.getSpec().getRules()) {
        for (HTTPIngressPath p : r.getHttp().getPaths()) {
            Xp7ConfigStatus.State pathState = states.get(p.getBackend().getService().getName());
            if (pathState != null && !pathState.equals(Xp7ConfigStatus.State.READY)) {
                loaded = false;
                break;
            }
        }
    }
    // Update if true
    if (loaded) {
        K8sLogHelper.logEdit(clients.k8s().network().ingress().inNamespace(ingress.getMetadata().getNamespace()).withName(ingress.getMetadata().getName()), i -> {
            Map<String, String> labels = i.getMetadata().getLabels();
            if (labels == null) {
                labels = new HashMap<>();
            }
            labels.put(cfgStr("operator.charts.values.labelKeys.ingressVhostLoaded"), "true");
            i.getMetadata().setLabels(labels);
            return i;
        });
    }
}
Also used : Clients(com.enonic.kubernetes.kubernetes.Clients) Predicates.isDeleted(com.enonic.kubernetes.kubernetes.Predicates.isDeleted) Predicates.inSameNamespaceAs(com.enonic.kubernetes.kubernetes.Predicates.inSameNamespaceAs) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) Xp7Config(com.enonic.kubernetes.client.v1.xp7config.Xp7Config) Searchers(com.enonic.kubernetes.kubernetes.Searchers) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Predicates.onCondition(com.enonic.kubernetes.kubernetes.Predicates.onCondition) Informers(com.enonic.kubernetes.kubernetes.Informers) K8sLogHelper(com.enonic.kubernetes.kubernetes.commands.K8sLogHelper) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Xp7ConfigStatus(com.enonic.kubernetes.client.v1.xp7config.Xp7ConfigStatus) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Observes(javax.enterprise.event.Observes) Map(java.util.Map) Configuration.cfgStr(com.enonic.kubernetes.common.Configuration.cfgStr) Predicates.matchLabel(com.enonic.kubernetes.kubernetes.Predicates.matchLabel) InformerEventHandler(com.enonic.kubernetes.operator.helpers.InformerEventHandler) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StartupEvent(io.quarkus.runtime.StartupEvent) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Xp7ConfigStatus(com.enonic.kubernetes.client.v1.xp7config.Xp7ConfigStatus) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)

Example 52 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project dekorate by dekorateio.

the class Feat547Test method shouldHaveMatchingLabels.

@Test
public void shouldHaveMatchingLabels() {
    KubernetesList list = Serialization.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
    assertNotNull(list);
    Ingress i = findFirst(list, Ingress.class).orElseThrow(() -> new IllegalStateException());
    assertTrue(i.getSpec().getRules().stream().flatMap(r -> r.getHttp().getPaths().stream()).anyMatch(p -> p.getPath().equals("/app")));
    assertFalse(i.getMetadata().getLabels().isEmpty());
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Container(io.fabric8.kubernetes.api.model.Container) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Serialization(io.dekorate.utils.Serialization) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.jupiter.api.Test)

Example 53 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project dekorate by dekorateio.

the class ThorntailAnnotationlessTest method shouldContainKubernetesIngress.

@Test
void shouldContainKubernetesIngress() {
    KubernetesList list = Serialization.unmarshalAsList(ThorntailAnnotationlessTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
    assertNotNull(list);
    Optional<Ingress> ingress = findFirst(list, Ingress.class);
    assertTrue(ingress.isPresent());
    assertNotNull(ingress.get().getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getName());
    assertNull(ingress.get().getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getNumber());
}
Also used : Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.jupiter.api.Test)

Example 54 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project dekorate by dekorateio.

the class Issue545Test method shouldHaveMatchingPath.

@Test
public void shouldHaveMatchingPath() {
    KubernetesList list = Serialization.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
    assertNotNull(list);
    Deployment d = findFirst(list, Deployment.class).orElseThrow(() -> new IllegalStateException());
    assertNotNull(d);
    Container c = d.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertNotNull(c);
    assertTrue(c.getPorts().stream().filter(p -> "http".equals(p.getName())).findAny().isPresent());
    Ingress i = findFirst(list, Ingress.class).orElseThrow(() -> new IllegalStateException());
    assertTrue(i.getSpec().getRules().stream().flatMap(r -> r.getHttp().getPaths().stream()).anyMatch(p -> p.getPath().equals("/app")));
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Container(io.fabric8.kubernetes.api.model.Container) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Serialization(io.dekorate.utils.Serialization) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Container(io.fabric8.kubernetes.api.model.Container) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.jupiter.api.Test)

Example 55 with Ingress

use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project jkube by eclipse.

the class ApplyServiceTest method testApplyToMultipleNamespaceNoNamespaceConfigured.

@Test
public void testApplyToMultipleNamespaceNoNamespaceConfigured() throws InterruptedException {
    // Given
    ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("cm1").withNamespace("ns1").endMetadata().build();
    Ingress ingress = new IngressBuilder().withNewMetadata().withName("ing1").withNamespace("ns2").endMetadata().build();
    ServiceAccount serviceAccount = new ServiceAccountBuilder().withNewMetadata().withName("sa1").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/ns1/configmaps").andReply(collector.record("configmap-ns1-create").andReturn(HTTP_OK, configMap)).once();
    mockServer.expect().post().withPath("/apis/networking.k8s.io/v1/namespaces/ns2/ingresses").andReply(collector.record("ingress-ns2-create").andReturn(HTTP_OK, ingress)).once();
    mockServer.expect().post().withPath("/api/v1/namespaces/default/serviceaccounts").andReply(collector.record("serviceaccount-default-create").andReturn(HTTP_OK, serviceAccount)).once();
    String configuredNamespace = applyService.getNamespace();
    applyService.setNamespace(null);
    applyService.setFallbackNamespace("default");
    // When
    applyService.applyEntities(null, entities, log, 5);
    // Then
    collector.assertEventsRecordedInOrder("configmap-ns1-create", "serviceaccount-default-create", "ingress-ns2-create");
    assertEquals(5, mockServer.getOpenShiftMockServer().getRequestCount());
    applyService.setFallbackNamespace(null);
    applyService.setNamespace(configuredNamespace);
}
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)

Aggregations

Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)158 Service (io.fabric8.kubernetes.api.model.Service)47 Test (org.junit.jupiter.api.Test)42 Test (org.testng.annotations.Test)36 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)31 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)28 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)25 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)24 ArrayList (java.util.ArrayList)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)21 HashMap (java.util.HashMap)21 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)16 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)14 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)14 ServiceBackendPort (io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort)14 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)14 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)14 Reconciliation (io.strimzi.operator.common.Reconciliation)14 IngressOperator (io.strimzi.operator.common.operator.resource.IngressOperator)14