Search in sources :

Example 11 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testListServicesWithoutCLusterIPAndExternalName.

@Test(description = "Test .listServices() method without ClusterIPs and ExternalNamesURLs")
public void testListServicesWithoutCLusterIPAndExternalName() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    // Not include ClusterIPs
    sdKubernetes.setIncludeClusterIP(false);
    // Not include ExternalNames
    sdKubernetes.setIncludeExternalNameTypeServices(false);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceList());
    Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
    List<Endpoint> endpoints = sdKubernetes.listServices();
    Assert.assertEquals(endpoints.size(), 5);
    Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testListServicesWithNamespace.

@Test(description = "Test .listServices(Namespace) method")
public void testListServicesWithNamespace() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    // Not include ClusterIPs
    sdKubernetes.setIncludeClusterIP(false);
    // Include ExternalNames
    sdKubernetes.setIncludeExternalNameTypeServices(true);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceListWithNamespace());
    Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
    List<Endpoint> endpoints = sdKubernetes.listServices("dev");
    Assert.assertEquals(endpoints.size(), 4);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 13 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateIngressResourceForInvalidResource.

@Test
public void testCreateIngressResourceForInvalidResource() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
    Mockito.when(scalableResource.get()).thenReturn(null);
    HasMetadata invalidMetadata = Mockito.mock(Deployment.class);
    List<HasMetadata> ingressResources = new ArrayList<>();
    ingressResources.add(invalidMetadata);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), getDeploymentResources(), ingressResources);
    Service service = createService(openShiftClient, nonNamespaceOperation);
    Deployment deployment = createDeployment(openShiftClient, nonNamespaceOperation, scalableResource);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service, deployment);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 14 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateIngressResourceForKubernetesException.

@Test
public void testCreateIngressResourceForKubernetesException() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), getDeploymentResources(), getIngressResources());
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
    Mockito.when(scalableResource.get()).thenReturn(null);
    Service service = createService(openShiftClient, nonNamespaceOperation);
    Deployment deployment = createDeployment(openShiftClient, nonNamespaceOperation, scalableResource);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service, deployment);
    ScalableResource scalableResourceIngress = Mockito.mock(ScalableResource.class);
    String ingressName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_INGRESS_SUFFIX;
    Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(ingressName)).thenReturn(scalableResourceIngress);
    Mockito.when(scalableResourceIngress.get()).thenThrow(KubernetesClientException.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 15 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createDeployment.

/**
 * Create Deployment resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 * @param scalableResource      ScalableResource instance
 */
private Deployment createDeployment(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation, ScalableResource scalableResource) {
    String deploymentName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_DEPLOYMENT_SUFFIX;
    Mockito.when(openShiftClient.extensions().deployments().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(deploymentName)).thenReturn(scalableResource);
    Deployment deployment = Mockito.mock(Deployment.class, Mockito.RETURNS_DEEP_STUBS);
    return deployment;
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Aggregations

OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 Map (java.util.Map)12 Resource (io.fabric8.kubernetes.client.dsl.Resource)9 Service (io.fabric8.kubernetes.api.model.Service)8 Test (org.junit.Test)8 API (org.wso2.carbon.apimgt.core.models.API)8 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)7 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)6 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)5 URL (java.net.URL)5 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)5 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ArrayList (java.util.ArrayList)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)1