Search in sources :

Example 1 with GenericKubernetesResourceBuilder

use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.

the class KubernetesClientUtilTest method doDeleteAndWait_withExistingResource_shouldDeleteAndReachWaitLimit.

@Test
public void doDeleteAndWait_withExistingResource_shouldDeleteAndReachWaitLimit() {
    // Given
    GenericKubernetesResource resource = new GenericKubernetesResourceBuilder().withApiVersion("org.eclipse.jkube/v1beta1").withKind("JKubeCustomResource").withNewMetadata().withName("name").endMetadata().build();
    // When
    doDeleteAndWait(kubernetesClient, resource, "namespace", 2L);
    // Then
    // @formatter:off
    new Verifications() {

        {
            kubernetesClient.genericKubernetesResources("org.eclipse.jkube/v1beta1", "JKubeCustomResource").inNamespace("namespace").withName("name").delete();
            times = 1;
        }
    };
// @formatter:on
}
Also used : GenericKubernetesResourceBuilder(io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder) Verifications(mockit.Verifications) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.Test)

Example 2 with GenericKubernetesResourceBuilder

use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder 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 3 with GenericKubernetesResourceBuilder

use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.

the class KubernetesHelperTest method testGetFullyQualifiedApiGroupWithKind.

@Test
public void testGetFullyQualifiedApiGroupWithKind() {
    // Given
    GenericKubernetesResource cr1 = new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("VirtualService").build();
    GenericKubernetesResource cr2 = new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("Gateway").build();
    // When
    String result1 = KubernetesHelper.getFullyQualifiedApiGroupWithKind(cr1);
    String result2 = KubernetesHelper.getFullyQualifiedApiGroupWithKind(cr2);
    // Then
    assertEquals("networking.istio.io/v1alpha3#VirtualService", result1);
    assertEquals("networking.istio.io/v1alpha3#Gateway", result2);
}
Also used : GenericKubernetesResourceBuilder(io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.Test)

Example 4 with GenericKubernetesResourceBuilder

use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.

the class DefaultMetadataEnricherTest method setUp.

@Before
public void setUp() throws Exception {
    Configuration configuration = Configuration.builder().resource(ResourceConfig.builder().annotations(MetaDataConfig.builder().all(properties("all-annotation", 1)).deployment(properties("deployment", "Deployment")).ingress(properties("ingress", "Ingress")).serviceAccount(properties("service-account", "ServiceAccount")).build()).labels(MetaDataConfig.builder().all(properties("all-label", 10L)).deployment(properties("deployment-label", "Deployment")).ingress(properties("ingress-label", "Ingress")).serviceAccount(properties("service-account-label", "ServiceAccount")).build()).build()).build();
    // @formatter:off
    new Expectations() {

        {
            buildContext.getConfiguration();
            result = configuration;
        }
    };
    // @formatter:on
    defaultMetadataEnricher = new DefaultMetadataEnricher(buildContext);
    configMap = new ConfigMapBuilder().withNewMetadata().endMetadata();
    deployment = new DeploymentBuilder();
    genericResource = new GenericKubernetesResourceBuilder().withNewMetadata().endMetadata();
    ingressV1 = new io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder();
    ingressV1beta1 = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder();
    serviceAccount = new ServiceAccountBuilder();
    klb = new KubernetesListBuilder().addToItems(configMap).addToItems(deployment).addToItems(genericResource).addToItems(ingressV1).addToItems(ingressV1beta1).addToItems(serviceAccount);
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Configuration(org.eclipse.jkube.kit.enricher.api.model.Configuration) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) GenericKubernetesResourceBuilder(io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Before(org.junit.Before)

Example 5 with GenericKubernetesResourceBuilder

use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.

the class KubernetesUndeployServiceTest method undeployWithManifestAndCustomResourcesShouldDeleteAllEntities.

@Test
public void undeployWithManifestAndCustomResourcesShouldDeleteAllEntities(@Mocked ResourceConfig resourceConfig) throws Exception {
    // Given
    final File manifest = temporaryFolder.newFile("temp.yml");
    final File crManifest = temporaryFolder.newFile("temp-cr.yml");
    final String crdId = "org.eclipse.jkube/v1alpha1#Crd";
    final Service service = new Service();
    final GenericKubernetesResource customResource = new GenericKubernetesResourceBuilder().withApiVersion("org.eclipse.jkube/v1alpha1").withKind("Crd").build();
    customResource.setMetadata(new ObjectMetaBuilder().withName("my-cr").build());
    final APIResource customResourceApiResource = new APIResourceBuilder().withGroup("org.eclipse.jkube").withNamespaced(false).withKind("Crd").withName("crds").withSingularName("crd").build();
    // @formatter:off
    new Expectations() {

        {
            kubernetesHelper.loadResources(manifest);
            result = Arrays.asList(service, customResource);
            kubernetesHelper.getFullyQualifiedApiGroupWithKind(customResource);
            result = crdId;
        }
    };
    // @formatter:on
    // When
    kubernetesUndeployService.undeploy(null, resourceConfig, manifest);
    // Then
    // @formatter:off
    new Verifications() {

        {
            jKubeServiceHub.getClient().genericKubernetesResources("org.eclipse.jkube/v1alpha1", "Crd").inNamespace(null).withName("my-cr").delete();
            times = 1;
        }
    };
// @formatter:on
}
Also used : Expectations(mockit.Expectations) GenericKubernetesResourceBuilder(io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder) APIResourceBuilder(io.fabric8.kubernetes.api.model.APIResourceBuilder) APIResource(io.fabric8.kubernetes.api.model.APIResource) Service(io.fabric8.kubernetes.api.model.Service) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Verifications(mockit.Verifications) File(java.io.File) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Test(org.junit.Test)

Aggregations

GenericKubernetesResourceBuilder (io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder)5 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)4 Test (org.junit.Test)4 File (java.io.File)2 Expectations (mockit.Expectations)2 Verifications (mockit.Verifications)2 APIResource (io.fabric8.kubernetes.api.model.APIResource)1 APIResourceBuilder (io.fabric8.kubernetes.api.model.APIResourceBuilder)1 APIResourceListBuilder (io.fabric8.kubernetes.api.model.APIResourceListBuilder)1 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 Service (io.fabric8.kubernetes.api.model.Service)1 ServiceAccountBuilder (io.fabric8.kubernetes.api.model.ServiceAccountBuilder)1 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)1 WebServerEventCollector (org.eclipse.jkube.kit.config.service.openshift.WebServerEventCollector)1 Configuration (org.eclipse.jkube.kit.enricher.api.model.Configuration)1 Before (org.junit.Before)1