Search in sources :

Example 6 with WebServerEventCollector

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);
}
Also used : GenericKubernetesResourceBuilder(io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder) 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 7 with WebServerEventCollector

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");
}
Also used : WebServerEventCollector(org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector) Route(io.fabric8.openshift.api.model.Route) Test(org.junit.Test)

Example 8 with WebServerEventCollector

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);
}
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 9 with WebServerEventCollector

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");
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReplicationControllerBuilder(io.fabric8.kubernetes.api.model.ReplicationControllerBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) WebServerEventCollector(org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector) NetworkPolicyBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with WebServerEventCollector

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

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