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);
}
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());
}
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");
}
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());
}
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());
}
Aggregations