use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project kubernetes-client by fabric8io.
the class NetworkingV1IngressTest method testCreateWithNameMismatch.
@Test
void testCreateWithNameMismatch() {
Ingress ingress1 = new IngressBuilder().withNewMetadata().withName("ingress1").withNamespace("test").and().build();
Resource<Ingress> ingressOp = client.network().v1().ingresses().inNamespace("test1").withName("myingress1");
Assertions.assertThrows(KubernetesClientException.class, () -> ingressOp.create(ingress1));
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project kubernetes-client by fabric8io.
the class NetworkingV1IngressTest 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/v1/namespaces/ns1/ingresses").andReturn(HttpURLConnection.HTTP_CONFLICT, ingressFromServer).once();
server.expect().get().withPath("/apis/networking.k8s.io/v1/namespaces/ns1/ingresses/ing1").andReturn(HttpURLConnection.HTTP_OK, ingressFromServer).times(2);
server.expect().put().withPath("/apis/networking.k8s.io/v1/namespaces/ns1/ingresses/ing1").andReturn(HttpURLConnection.HTTP_OK, ingressUpdated).once();
// When
ingressUpdated = client.network().v1().ingresses().inNamespace("ns1").createOrReplace(ingressUpdated);
// Then
assertNotNull(ingressUpdated);
assertNotNull(ingressUpdated.getMetadata());
assertTrue(ingressUpdated.getMetadata().getAnnotations().containsKey("nginx.ingress.kubernetes.io/rewrite-target"));
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder in project kubernetes-client by fabric8io.
the class NetworkingV1beta1IngressTest method testDelete.
@Test
void testDelete() {
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();
Boolean deleted = client.network().ingress().withName("ingress1").delete();
assertTrue(deleted);
deleted = client.network().ingress().withName("ingress2").delete();
assertFalse(deleted);
deleted = client.network().ingress().inNamespace("ns1").withName("ingress2").delete();
assertTrue(deleted);
}
use of io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder 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 io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder 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);
}
Aggregations