Search in sources :

Example 46 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project vertx-openshift-it by cescoffier.

the class Kube method createRouteForService.

public static Route createRouteForService(KubernetesClient client, String svc, boolean deleteIfExist) {
    OpenShiftClient oc = oc(client);
    Route existing = oc.routes().withName(svc).get();
    if (existing != null && deleteIfExist) {
        oc.routes().withName(name(existing)).delete();
    }
    if (existing != null && !deleteIfExist) {
        return existing;
    }
    return oc.routes().createNew().withNewMetadata().withName(svc).endMetadata().withNewSpec().withNewTo().withName(svc).withKind("Service").endTo().endSpec().done();
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Route(io.fabric8.openshift.api.model.Route)

Example 47 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project kie-wb-common by kiegroup.

the class OpenShiftAccessInterfaceImpl method newOpenShiftClient.

@Override
public OpenShiftClient newOpenShiftClient(final ProviderConfig providerConfig) {
    checkInstanceOf("providerConfig", providerConfig, OpenShiftProviderConfig.class);
    OpenShiftConfig clientConfig = buildOpenShiftConfig((OpenShiftProviderConfig) providerConfig);
    return new OpenShiftClient(new DefaultOpenShiftClient(clientConfig));
}
Also used : OpenShiftClient(org.guvnor.ala.openshift.access.OpenShiftClient) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftConfig(io.fabric8.openshift.client.OpenShiftConfig) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient)

Example 48 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testGetResourcesFromTemplateWhenResourceIsNull.

@Test
public void testGetResourcesFromTemplateWhenResourceIsNull() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(null);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.NO_RESOURCE_LOADED_FROM_DEFINITION);
    }
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 49 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateContainerGateway.

@Test
public void testCreateContainerGateway() 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);
    Ingress ingress = createIngress(openShiftClient, nonNamespaceOperation, scalableResource);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service, deployment, ingress);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    Mockito.verify(openShiftClient, Mockito.times(4)).load(Mockito.any());
    Mockito.verify(openShiftClient, Mockito.times(3)).services();
    Mockito.verify(openShiftClient, Mockito.times(6)).extensions();
}
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) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 50 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateServiceResourceForInvalidResource.

@Test
public void testCreateServiceResourceForInvalidResource() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    HasMetadata invalidMetadata = Mockito.mock(Deployment.class);
    List<HasMetadata> serviceResources = new ArrayList<>();
    serviceResources.add(invalidMetadata);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(serviceResources);
    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 : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Aggregations

OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)65 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 IOException (java.io.IOException)18 Test (org.junit.Test)17 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)14 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)12 API (org.wso2.carbon.apimgt.core.models.API)12 FileNotFoundException (java.io.FileNotFoundException)11 Service (io.fabric8.kubernetes.api.model.Service)10 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)10 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)10 BeforeTest (org.testng.annotations.BeforeTest)9 Test (org.testng.annotations.Test)9 Controller (io.fabric8.kubernetes.api.Controller)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)8 Route (io.fabric8.openshift.api.model.Route)8 JSONObject (org.json.JSONObject)8