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