use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.
the class KubernetesConfigMapsProducer method doListConfigMapsByLabels.
protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception {
ConfigMapList configMapsList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class);
NonNamespaceOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps();
for (Map.Entry<String, String> entry : labels.entrySet()) {
configMaps.withLabel(entry.getKey(), entry.getValue());
}
configMapsList = configMaps.list();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(configMapsList.getItems());
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.
the class KubernetesSecretsProducer method doListSecretsByLabels.
protected void doListSecretsByLabels(Exchange exchange, String operation) throws Exception {
SecretList secretsList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SECRETS_LABELS, Map.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
NonNamespaceOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>> secrets;
secrets = getEndpoint().getKubernetesClient().secrets().inNamespace(namespaceName);
for (Map.Entry<String, String> entry : labels.entrySet()) {
secrets.withLabel(entry.getKey(), entry.getValue());
}
secretsList = secrets.list();
} else {
MixedOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>> secrets;
secrets = getEndpoint().getKubernetesClient().secrets();
for (Map.Entry<String, String> entry : labels.entrySet()) {
secrets.withLabel(entry.getKey(), entry.getValue());
}
secretsList = secrets.list();
}
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(secretsList.getItems());
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateDeploymentResourceForKubernetesException.
@Test
public void testCreateDeploymentResourceForKubernetesException() 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());
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
Service service = createService(openShiftClient, nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.create(Mockito.any())).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);
Mockito.when(scalableResource.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);
}
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithBothNamespaceAndCriteria.
@Test(description = "Test .listServices(Namespace, Criteria) method")
public void testListServicesWithBothNamespaceAndCriteria() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Include ClusterIPs
sdKubernetes.setIncludeClusterIP(true);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
Map<String, String> oneLabel = createOneLabelHashMap();
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withLabels(oneLabel)).thenReturn(baseOperation);
Mockito.when(baseOperation.list()).thenReturn(createServiceListWithBothNamespaceAndCriteria());
List<Endpoint> endpoints = sdKubernetes.listServices("dev", oneLabel);
Assert.assertEquals(endpoints.size(), 2);
}
Aggregations