use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method createIngressResource.
/**
* Create an Ingress resource in cms
*
* @param ingressTemplate Ingress template as a String
* @param ingressName Name of the ingress
* @throws ContainerBasedGatewayException if failed to create a service
*/
private void createIngressResource(String ingressTemplate, String ingressName) throws ContainerBasedGatewayException {
HasMetadata resource = getResourcesFromTemplate(ingressTemplate);
try {
if (resource instanceof Ingress) {
// check whether there are existing service already
if (client.extensions().ingresses().inNamespace(namespace).withName(ingressName).get() == null) {
log.debug("Deploying in CMS type: {} and the Ingress resource definition: {} ", cmsType, ingressTemplate);
Ingress ingress = (Ingress) resource;
Ingress result = client.extensions().ingresses().inNamespace(namespace).create(ingress);
log.info("Created Ingress : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
} else {
log.info("There exist an ingress with the same name in " + cmsType + ". Ingress name : " + ingressName);
}
} else {
throw new ContainerBasedGatewayException("Loaded Resource is not a Service in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
}
} catch (KubernetesClientException e) {
throw new ContainerBasedGatewayException("Error while creating container based gateway ingress in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
}
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateContainerGatewayForAlreadyAvailableResources.
@Test
public void testCreateContainerGatewayForAlreadyAvailableResources() 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);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withName(serviceName)).thenReturn(baseOperation);
Service service = Mockito.mock(Service.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(baseOperation.get()).thenReturn(service);
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);
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(scalableResource);
Ingress ingress = Mockito.mock(Ingress.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(scalableResource.get()).thenReturn(deployment, ingress);
API api = SampleTestObjectCreator.createDefaultAPI().context("/test/context/").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(2)).services();
Mockito.verify(openShiftClient, Mockito.times(4)).extensions();
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method createMalformedServiceList.
/**
* Create ServiceList with the given port type, but without a loadBalancer ingress
*
* @param portType http or https or a wrong port to check behavior
* @return ServiceList containing one service of LoadBalancer type
*/
private ServiceList createMalformedServiceList(String portType) {
ServicePort port = new ServicePortBuilder().withName(portType).withPort(80).withNodePort(30005).build();
Service malformedService5 = new ServiceBuilder().withNewMetadata().withName("service5").withNamespace("prod").and().withNewSpec().withType("LoadBalancer").withClusterIP("1.1.1.5").withPorts(port).and().withNewStatus().withNewLoadBalancer().endLoadBalancer().and().build();
List<Service> servicesList = new ArrayList<>();
servicesList.add(malformedService5);
return new ServiceListBuilder().withItems(servicesList).build();
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method getIngressResources.
/**
* Get ingress resources
*
* @return List<HasMetadata> list of ingress resources
*/
private List<HasMetadata> getIngressResources() {
HasMetadata ingressMetadata = Mockito.mock(Ingress.class);
List<HasMetadata> ingressResources = new ArrayList<>();
ingressResources.add(ingressMetadata);
return ingressResources;
}
use of io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method createIngress.
/**
* Create Ingress resource
*
* @param openShiftClient Openshift client
* @param nonNamespaceOperation NonNamespaceOperation instance
* @param scalableResource ScalableResource instance
*/
private Ingress createIngress(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation, ScalableResource scalableResource) {
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(scalableResource);
Ingress ingress = Mockito.mock(Ingress.class, Mockito.RETURNS_DEEP_STUBS);
return ingress;
}
Aggregations