Search in sources :

Example 1 with WebServerEventCollector

use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector 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)

Example 2 with WebServerEventCollector

use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.

the class ApplyServiceTest method testCreateRouteInServiceOnlyMode.

@Test
public void testCreateRouteInServiceOnlyMode() {
    Route route = buildRoute();
    WebServerEventCollector collector = new WebServerEventCollector();
    mockServer.expect().get().withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route").andReply(collector.record("get-route").andReturn(HTTP_NOT_FOUND, "")).always();
    applyService.setServicesOnlyMode(true);
    applyService.apply(route, "route.yml");
    collector.assertEventsNotRecorded("get-route");
    assertEquals(0, mockServer.getOpenShiftMockServer().getRequestCount());
}
Also used : WebServerEventCollector(org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector) Route(io.fabric8.openshift.api.model.Route) Test(org.junit.Test)

Example 3 with WebServerEventCollector

use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.

the class ApplyServiceTest method testUpdateRoute.

@Test
public void testUpdateRoute() {
    Route oldRoute = buildRoute();
    Route newRoute = new RouteBuilder().withNewMetadataLike(oldRoute.getMetadata()).addToAnnotations("haproxy.router.openshift.io/balance", "roundrobin").endMetadata().withSpec(oldRoute.getSpec()).build();
    WebServerEventCollector collector = new WebServerEventCollector();
    mockServer.expect().get().withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route").andReply(collector.record("get-route").andReturn(HTTP_OK, oldRoute)).always();
    mockServer.expect().patch().withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route").andReply(collector.record("patch-route").andReturn(HTTP_OK, new RouteBuilder().withMetadata(newRoute.getMetadata()).withSpec(oldRoute.getSpec()).build())).once();
    applyService.apply(newRoute, "route.yml");
    collector.assertEventsRecordedInOrder("get-route", "patch-route");
}
Also used : RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) WebServerEventCollector(org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector) Route(io.fabric8.openshift.api.model.Route) Test(org.junit.Test)

Example 4 with WebServerEventCollector

use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.

the class ApplyServiceTest method testProcessCustomEntitiesReplaceCustomResources.

@Test
public void testProcessCustomEntitiesReplaceCustomResources() throws Exception {
    // Given
    File gatewayFragment = new File(getClass().getResource("/gateway-cr.yml").getFile());
    File virtualServiceFragment = new File(getClass().getResource("/virtualservice-cr.yml").getFile());
    GenericKubernetesResource gateway = Serialization.yamlMapper().readValue(gatewayFragment, GenericKubernetesResource.class);
    GenericKubernetesResource virtualService = Serialization.yamlMapper().readValue(virtualServiceFragment, GenericKubernetesResource.class);
    WebServerEventCollector collector = new WebServerEventCollector();
    mockServer.expect().get().withPath("/apis/networking.istio.io/v1alpha3").andReply(collector.record("get-resources").andReturn(HTTP_OK, new APIResourceListBuilder().addToResources(virtualServiceResource(), gatewayResource()).build())).times(2);
    mockServer.expect().get().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/reviews-route").andReply(collector.record("get-cr-virtualservice").andReturn(HTTP_OK, "{\"metadata\":{\"resourceVersion\":\"1001\"}}")).once();
    mockServer.expect().post().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices").andReply(collector.record("post-cr-virtualservice").andReturn(HTTP_OK, "{}")).once();
    mockServer.expect().get().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways/mygateway-https").andReply(collector.record("get-cr-gateway").andReturn(HTTP_OK, "{\"metadata\":{\"resourceVersion\":\"1002\"}}")).once();
    mockServer.expect().post().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways").andReply(collector.record("post-cr-gateway").andReturn(HTTP_CONFLICT, "{}")).once();
    mockServer.expect().put().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways/mygateway-https").andReply(collector.record("put-cr-gateway").andReturn(HTTP_OK, "{\"metadata\":{\"resourceVersion\":\"1002\"}}")).once();
    // When
    applyService.applyGenericKubernetesResource(gateway, gatewayFragment.getName());
    applyService.applyGenericKubernetesResource(virtualService, virtualServiceFragment.getName());
    // Then
    collector.assertEventsRecordedInOrder("get-cr-gateway", "post-cr-gateway", "put-cr-gateway", "get-cr-virtualservice", "post-cr-virtualservice");
    assertEquals(5, mockServer.getOpenShiftMockServer().getRequestCount());
}
Also used : WebServerEventCollector(org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector) File(java.io.File) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) APIResourceListBuilder(io.fabric8.kubernetes.api.model.APIResourceListBuilder) Test(org.junit.Test)

Example 5 with WebServerEventCollector

use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.

the class ApplyServiceTest method testCreateRouteNotAllowed.

@Test
public void testCreateRouteNotAllowed() {
    Route route = buildRoute();
    WebServerEventCollector collector = new WebServerEventCollector();
    mockServer.expect().get().withPath("/apis/route.openshift.io/v1/namespaces/default/routes/route").andReply(collector.record("get-route").andReturn(HTTP_NOT_FOUND, "")).always();
    applyService.setAllowCreate(false);
    applyService.apply(route, "route.yml");
    collector.assertEventsRecordedInOrder("get-route");
    assertEquals(1, mockServer.getOpenShiftMockServer().getRequestCount());
}
Also used : WebServerEventCollector(org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector) Route(io.fabric8.openshift.api.model.Route) Test(org.junit.Test)

Aggregations

WebServerEventCollector (org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector)10 Test (org.junit.Test)10 Route (io.fabric8.openshift.api.model.Route)4 APIResourceListBuilder (io.fabric8.kubernetes.api.model.APIResourceListBuilder)3 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)3 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 File (java.io.File)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)2 ServiceAccountBuilder (io.fabric8.kubernetes.api.model.ServiceAccountBuilder)2 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)2 IngressBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder)2 ArrayList (java.util.ArrayList)2 GenericKubernetesResourceBuilder (io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder)1 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)1 ReplicationControllerBuilder (io.fabric8.kubernetes.api.model.ReplicationControllerBuilder)1 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)1 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)1 NetworkPolicyBuilder (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyBuilder)1