use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.
the class ApplyServiceTest method testProcessCustomEntitiesRecreateModeTrue.
@Test
public void testProcessCustomEntitiesRecreateModeTrue() 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/gateways?fieldSelector=metadata.name%3Dmygateway-https").andReturn(HTTP_OK, new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("Gateway").withNewMetadata().withName("mygateway-https").endMetadata().build()).once();
mockServer.expect().get().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices?fieldSelector=metadata.name%3Dreviews-route").andReturn(HTTP_OK, new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("VirtualService").withNewMetadata().withName("reviews-route").endMetadata().build()).once();
mockServer.expect().delete().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/reviews-route").andReply(collector.record("delete-cr-virtualservice").andReturn(HTTP_OK, "{\"kind\":\"Status\",\"status\":\"Success\"}")).once();
mockServer.expect().delete().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways/mygateway-https").andReply(collector.record("delete-cr-gateway").andReturn(HTTP_OK, "{\"kind\":\"Status\",\"status\":\"Success\"}")).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().post().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways").andReply(collector.record("post-cr-gateway").andReturn(HTTP_OK, "{}")).once();
applyService.setRecreateMode(true);
// When
applyService.applyGenericKubernetesResource(gateway, gatewayFragment.getName());
applyService.applyGenericKubernetesResource(virtualService, virtualServiceFragment.getName());
// Then
collector.assertEventsRecordedInOrder("delete-cr-gateway", "post-cr-gateway", "delete-cr-virtualservice", "post-cr-virtualservice");
assertEquals(8, mockServer.getOpenShiftMockServer().getRequestCount());
applyService.setRecreateMode(false);
}
use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.
the class ApplyServiceTest method testCreateRoute.
@Test
public void testCreateRoute() {
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();
mockServer.expect().post().withPath("/apis/route.openshift.io/v1/namespaces/default/routes").andReply(collector.record("new-route").andReturn(HTTP_CREATED, route)).once();
applyService.apply(route, "route.yml");
collector.assertEventsRecordedInOrder("get-route", "new-route");
}
use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.
the class ApplyServiceTest method testApplyToMultipleNamespacesOverriddenWhenNamespaceConfigured.
@Test
public void testApplyToMultipleNamespacesOverriddenWhenNamespaceConfigured() throws InterruptedException {
// Given
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("cm1").withNamespace("default").endMetadata().build();
Ingress ingress = new IngressBuilder().withNewMetadata().withName("ing1").withNamespace("default").endMetadata().build();
ServiceAccount serviceAccount = new ServiceAccountBuilder().withNewMetadata().withName("default").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/default/configmaps").andReply(collector.record("configmap-default-ns-create").andReturn(HTTP_OK, configMap)).once();
mockServer.expect().post().withPath("/apis/networking.k8s.io/v1/namespaces/default/ingresses").andReply(collector.record("ingress-default-ns-create").andReturn(HTTP_OK, ingress)).once();
mockServer.expect().post().withPath("/api/v1/namespaces/default/serviceaccounts").andReply(collector.record("serviceaccount-default-ns-create").andReturn(HTTP_OK, serviceAccount)).once();
// When
applyService.applyEntities(null, entities, log, 5);
// Then
collector.assertEventsRecordedInOrder("configmap-default-ns-create", "serviceaccount-default-ns-create", "ingress-default-ns-create");
assertEquals(5, mockServer.getOpenShiftMockServer().getRequestCount());
applyService.setFallbackNamespace(null);
}
use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.
the class ApplyServiceTest method testApplyEntities.
@Test
public void testApplyEntities() throws Exception {
// Given
final Set<HasMetadata> entities = new HashSet<>(Arrays.asList(new DeploymentBuilder().withNewMetadata().withName("d1").endMetadata().build(), new ServiceBuilder().withNewMetadata().withName("svc1").endMetadata().build(), new ConfigMapBuilder().withNewMetadata().withName("c1").endMetadata().build(), new PodBuilder().withNewMetadata().withName("p1").endMetadata().build(), new ReplicationControllerBuilder().withNewMetadata().withName("rc1").endMetadata().build(), new NetworkPolicyBuilder().withNewMetadata().withName("npv1").endMetadata().build(), new io.fabric8.kubernetes.api.model.extensions.NetworkPolicyBuilder().withNewMetadata().withName("np-ext").endMetadata().build()));
String fileName = "foo.yml";
WebServerEventCollector collector = new WebServerEventCollector();
mockServer.expect().post().withPath("/api/v1/namespaces/default/services").andReply(collector.record("new-service").andReturn(HTTP_CREATED, "")).once();
mockServer.expect().post().withPath("/api/v1/namespaces/default/configmaps").andReply(collector.record("new-configmap").andReturn(HTTP_CREATED, "")).once();
mockServer.expect().post().withPath("/apis/apps/v1/namespaces/default/deployments").andReply(collector.record("new-deploy").andReturn(HTTP_CREATED, "")).once();
mockServer.expect().post().withPath("/api/v1/namespaces/default/pods").andReply(collector.record("new-pod").andReturn(HTTP_CREATED, "")).once();
mockServer.expect().post().withPath("/api/v1/namespaces/default/replicationcontrollers").andReply(collector.record("new-rc").andReturn(HTTP_CREATED, "")).once();
mockServer.expect().post().withPath("/apis/networking.k8s.io/v1/namespaces/default/networkpolicies").andReply(collector.record("new-np-v1").andReturn(HTTP_CREATED, "")).once();
mockServer.expect().post().withPath("/apis/extensions/v1beta1/namespaces/default/networkpolicies").andReply(collector.record("new-np-extensions").andReturn(HTTP_CREATED, "")).once();
// When
applyService.applyEntities(fileName, entities, log, 5);
// Then
collector.assertEventsRecordedInOrder("new-rc", "new-configmap", "new-service", "new-deploy", "new-pod");
collector.assertEventsRecorded("new-np-v1", "new-np-extensions");
}
use of org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector in project jkube by eclipse.
the class ApplyServiceTest method testApplyGenericKubernetesResource.
@Test
public void testApplyGenericKubernetesResource() 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().post().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices").andReply(collector.record("post-cr-virtualservice").andReturn(HTTP_OK, "{}")).once();
mockServer.expect().post().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways").andReply(collector.record("post-cr-gateway").andReturn(HTTP_OK, "{}")).once();
// When
applyService.applyGenericKubernetesResource(gateway, gatewayFragment.getName());
applyService.applyGenericKubernetesResource(virtualService, virtualServiceFragment.getName());
// Then
collector.assertEventsRecordedInOrder("get-resources", "post-cr-gateway", "get-resources", "post-cr-virtualservice");
assertEquals(6, mockServer.getOpenShiftMockServer().getRequestCount());
}
Aggregations