use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project kubernetes-client by fabric8io.
the class NetworkingV1beta1IngressTest method testCreateOrReplaceWhenAnnotationUpdated.
@Test
void testCreateOrReplaceWhenAnnotationUpdated() {
// Given
Ingress ingressFromServer = new IngressBuilder().withNewMetadata().withName("ing1").endMetadata().build();
Ingress ingressUpdated = new IngressBuilder(ingressFromServer).editOrNewMetadata().addToAnnotations("nginx.ingress.kubernetes.io/rewrite-target", "/").endMetadata().build();
server.expect().post().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses").andReturn(HttpURLConnection.HTTP_CONFLICT, ingressFromServer).once();
server.expect().get().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses/ing1").andReturn(HttpURLConnection.HTTP_OK, ingressFromServer).times(2);
server.expect().put().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses/ing1").andReturn(HttpURLConnection.HTTP_OK, ingressUpdated).once();
// When
ingressUpdated = client.network().ingresses().inNamespace("ns1").createOrReplace(ingressUpdated);
// Then
assertNotNull(ingressUpdated);
assertNotNull(ingressUpdated.getMetadata());
assertTrue(ingressUpdated.getMetadata().getAnnotations().containsKey("nginx.ingress.kubernetes.io/rewrite-target"));
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project kubernetes-client by fabric8io.
the class NetworkingV1beta1IngressTest method testGet.
@Test
void testGet() {
server.expect().withPath("/apis/networking.k8s.io/v1beta1/namespaces/test/ingresses/ingress1").andReturn(200, new IngressBuilder().build()).once();
server.expect().withPath("/apis/networking.k8s.io/v1beta1/namespaces/ns1/ingresses/ingress2").andReturn(200, new IngressBuilder().build()).once();
Ingress ingress = client.network().ingress().withName("ingress1").get();
assertNotNull(ingress);
ingress = client.network().ingress().withName("ingress2").get();
assertNull(ingress);
ingress = client.network().ingress().inNamespace("ns1").withName("ingress2").get();
assertNotNull(ingress);
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project ingress-access-operator by neo9.
the class ServiceExposerReconciler method reconcileOnDelete.
public void reconcileOnDelete(Service service) {
String serviceNamespaceAndName = getResourceNamespaceAndName(service);
log.trace("start working with deleted service {}", serviceNamespaceAndName);
Ingress oldIngress = ingressRepository.get(service.getMetadata().getNamespace(), service.getMetadata().getName());
if (nonNull(oldIngress) && !isManagedByOperator(oldIngress)) {
throw new ResourceNotManagedByOperatorException(getResourceNamespaceAndName(oldIngress));
}
if (nonNull(oldIngress)) {
log.info("deleting ingress {} due to service deletion {}", getResourceNamespaceAndName(oldIngress), serviceNamespaceAndName);
ingressRepository.delete(oldIngress.getMetadata().getNamespace(), oldIngress.getMetadata().getName());
}
log.trace("end of working with deleted service {}", serviceNamespaceAndName);
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress 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 com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress 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