use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder in project kubernetes-client by fabric8io.
the class IngressTest method testDeleteWithNamespaceMismatch.
@Test
public void testDeleteWithNamespaceMismatch() {
Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build();
Boolean deleted = client.extensions().ingress().inNamespace("test1").delete(ingress1);
assertFalse(deleted);
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder in project kubernetes-client by fabric8io.
the class IngressTest method testCreateWithNameMismatch.
@Test
public void testCreateWithNameMismatch() {
Assertions.assertThrows(KubernetesClientException.class, () -> {
Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build();
Ingress ingress2 = new IngressBuilder().withNewMetadata().withName("ingress2").withNamespace("ns1").and().build();
client.extensions().ingress().inNamespace("test1").withName("myingress1").create(ingress1);
});
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder in project kubernetes-client by fabric8io.
the class IngressTest method testDeleteMulti.
@Test
public void testDeleteMulti() {
Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build();
Ingress ingress2 = new IngressBuilder().withNewMetadata().withName("ingress2").withNamespace("ns1").and().build();
Ingress ingress3 = new IngressBuilder().withNewMetadata().withName("ingress3").withNamespace("any").and().build();
server.expect().withPath("/apis/extensions/v1beta1/namespaces/test/ingresses/ingress1").andReturn(200, ingress1).once();
server.expect().withPath("/apis/extensions/v1beta1/namespaces/ns1/ingresses/ingress2").andReturn(200, ingress2).once();
Boolean deleted = client.extensions().ingress().inAnyNamespace().delete(ingress1, ingress2);
assertTrue(deleted);
deleted = client.extensions().ingress().inAnyNamespace().delete(ingress3);
assertFalse(deleted);
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder in project ingress-access-operator by neo9.
the class ServiceExposerReconciler method reconcile.
public void reconcile(Service service) {
String serviceNamespaceAndName = getResourceNamespaceAndName(service);
log.trace("start working with service {}", serviceNamespaceAndName);
Ingress oldIngress = ingressRepository.get(service.getMetadata().getNamespace(), service.getMetadata().getName());
if (nonNull(oldIngress) && !isManagedByOperator(oldIngress)) {
throw new ResourceNotManagedByOperatorException(getResourceNamespaceAndName(oldIngress));
}
String hostname = generateHostname(service);
log.debug("generating ingress for hostname : {}", hostname);
Map<String, String> ingressAnnotations = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_ANNOTATIONS, service, ""));
Map<String, String> ingressLabels = rawBlockToMap(getAnnotationValue(EXPOSE_INGRESS_ADDITIONAL_LABELS, service, ""));
SpecNested<IngressBuilder> ingressBuilderSpecNested = new IngressBuilder().withNewMetadata().withNamespace(service.getMetadata().getNamespace()).withName(service.getMetadata().getName()).addToAnnotations(ingressAnnotations).addToLabels(ingressLabels).addToLabels(MANAGED_BY_OPERATOR_KEY, MANAGED_BY_OPERATOR_VALUE).endMetadata().withNewSpec().withRules(new IngressRuleBuilder().withHost(hostname).withHttp(new HTTPIngressRuleValueBuilder().withPaths(new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withBackend(new IngressBackendBuilder().withService(new IngressServiceBackendBuilder().withName(service.getMetadata().getName()).withPort(new ServiceBackendPortBuilder().withNumber(service.getSpec().getPorts().get(0).getPort()).build()).build()).build()).build()).build()).build());
if (shouldEnableTls(ingressAnnotations)) {
ingressBuilderSpecNested = ingressBuilderSpecNested.withTls(new IngressTLSBuilder().addToHosts(hostname).withSecretName(String.format("%s-tls", service.getMetadata().getName())).build());
}
Ingress ingress = ingressBuilderSpecNested.endSpec().build();
ingressRepository.createOrReplace(ingress);
log.trace("end of working with service {}", serviceNamespaceAndName);
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder in project ingress-access-operator by neo9.
the class ServiceExposerReconcilerTest method shouldNotEnableTlsIfAnnotationIsDetected.
@Test
public void shouldNotEnableTlsIfAnnotationIsDetected() {
// given
Ingress ingress = new IngressBuilder().withNewMetadata().withNamespace("mynamespace").withName("myname").addToAnnotations(EXPOSE_INGRESS_HOSTNAME, "hello.{{domain}}").addToAnnotations("cert-manager.io/cluster-issuer", "my-issuer").endMetadata().build();
// when
boolean shouldEnableTls = serviceExposerReconciler.shouldEnableTls(ingress.getMetadata().getAnnotations());
// then
assertThat(shouldEnableTls).isTrue();
}
Aggregations