use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method listServices.
/**
* {@inheritDoc}
*/
@Override
public List<Endpoint> listServices(String namespace, Map<String, String> criteria) throws ServiceDiscoveryException {
List<Endpoint> endpointList = new ArrayList<>();
if (client != null) {
log.debug("Looking for services, with the specified labels, in namespace {}", namespace);
try {
List<Service> serviceList = client.services().inNamespace(namespace).withLabels(criteria).list().getItems();
addServicesToEndpointList(serviceList, endpointList);
} catch (KubernetesClientException | MalformedURLException e) {
String msg = "Error occurred while trying to list services using Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
} catch (NoSuchMethodError e) {
String msg = "Filtering criteria in the deployment yaml includes unwanted characters";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
}
}
return endpointList;
}
use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method listServices.
/**
* {@inheritDoc}
*/
@Override
public List<Endpoint> listServices() throws ServiceDiscoveryException {
List<Endpoint> endpointList = new ArrayList<>();
if (client != null) {
log.debug("Looking for services in all namespaces");
try {
List<Service> serviceList = client.services().inNamespace(null).list().getItems();
addServicesToEndpointList(serviceList, endpointList);
} catch (KubernetesClientException | MalformedURLException e) {
String msg = "Error occurred while trying to list services using Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
}
}
return endpointList;
}
use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method listServices.
/**
* {@inheritDoc}
*/
@Override
public List<Endpoint> listServices(String namespace) throws ServiceDiscoveryException {
List<Endpoint> endpointList = new ArrayList<>();
if (client != null) {
log.debug("Looking for services in namespace {}", namespace);
try {
List<Service> serviceList = client.services().inNamespace(namespace).list().getItems();
addServicesToEndpointList(serviceList, endpointList);
} catch (KubernetesClientException | MalformedURLException e) {
String msg = "Error occurred while trying to list services using Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
}
}
return endpointList;
}
use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method buildConfig.
/**
* Builds the Config required by DefaultOpenShiftClient
* Also sets the system properties
* (1) to not refer .kube/config file and
* (2) the client to use service account procedure to get authenticated and authorised
*
* @return {@link io.fabric8.kubernetes.client.Config} object to build the client
* @throws ServiceDiscoveryException if an error occurs while building the config using externally stored token
*/
private Config buildConfig(Map<String, String> implParameters) throws ServiceDiscoveryException, APIMgtDAOException {
System.setProperty(TRY_KUBE_CONFIG, "false");
System.setProperty(TRY_SERVICE_ACCOUNT, "true");
/*
* Common to both situations,
* - Token found inside APIM pod
* - Token stored in APIM resources/security folder }
*/
ConfigBuilder configBuilder = new ConfigBuilder().withMasterUrl(implParameters.get(MASTER_URL)).withCaCertFile(implParameters.get(CA_CERT_PATH));
/*
* Check if a service account token File Name is given in the configuration
* - if not : assume APIM is running inside a pod and look for the pod's token
*/
String externalSATokenFileName = implParameters.get(EXTERNAL_SA_TOKEN_FILE_NAME);
if (StringUtils.isEmpty(externalSATokenFileName)) {
log.debug("Looking for service account token in " + POD_MOUNTED_SA_TOKEN_FILE_PATH);
String podMountedSAToken = APIFileUtils.readFileContentAsText(implParameters.get(POD_MOUNTED_SA_TOKEN_FILE_PATH));
return configBuilder.withOauthToken(podMountedSAToken).build();
} else {
log.info("Using externally stored service account token");
return configBuilder.withOauthToken(resolveToken("encrypted" + externalSATokenFileName)).build();
}
}
use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method listServices.
/**
* {@inheritDoc}
*/
@Override
public List<Endpoint> listServices(Map<String, String> criteria) throws ServiceDiscoveryException {
List<Endpoint> endpointList = new ArrayList<>();
if (client != null) {
log.debug("Looking for services, with the specified labels, in all namespaces");
try {
// namespace has to be set to null to check all allowed namespaces
List<Service> serviceList = client.services().inNamespace(null).withLabels(criteria).list().getItems();
addServicesToEndpointList(serviceList, endpointList);
} catch (KubernetesClientException | MalformedURLException e) {
String msg = "Error occurred while trying to list services using Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
} catch (NoSuchMethodError e) {
String msg = "Filtering criteria in the deployment yaml includes unwanted characters";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
}
}
return endpointList;
}
Aggregations