use of io.fabric8.openshift.client.DefaultOpenShiftClient 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.openshift.client.DefaultOpenShiftClient in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method initImpl.
/**
* Initializes OpenShiftClient (extended KubernetesClient) and sets the necessary parameters
*
* @param implParameters implementation parameters added by the super class #initImpl(java.util.Map) method
* @throws ServiceDiscoveryException if an error occurs while initializing the client
*/
@Override
public void initImpl(Map<String, String> implParameters) throws ServiceDiscoveryException {
try {
setClient(new DefaultOpenShiftClient(buildConfig(implParameters)));
} catch (KubernetesClientException | APIMgtDAOException e) {
String msg = "Error occurred while creating Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
} catch (ArrayIndexOutOfBoundsException e) {
String msg = "Error occurred while reading filtering criteria from the configuration";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
}
includeClusterIP = Boolean.parseBoolean(implParameters.get(INCLUDE_CLUSTER_IPS));
includeExternalNameTypeServices = Boolean.parseBoolean(implParameters.get(INCLUDE_EXTERNAL_NAME_SERVICES));
}
use of io.fabric8.openshift.client.DefaultOpenShiftClient in project fabric8-maven-plugin by fabric8io.
the class BaseBoosterIT method setupSampleTestRepository.
protected Repository setupSampleTestRepository(String repositoryUrl, String relativePomPath) throws IOException, GitAPIException, XmlPullParserException {
openShiftClient = new DefaultOpenShiftClient(new ConfigBuilder().build());
testsuiteNamespace = openShiftClient.getNamespace();
Repository repository = cloneRepositoryUsingHttp(repositoryUrl);
modifyPomFileToProjectVersion(repository, relativePomPath);
return repository;
}
use of io.fabric8.openshift.client.DefaultOpenShiftClient in project fabric8 by fabric8io.
the class WatchBuildsExample method main.
public static void main(String... args) throws Exception {
OpenShiftClient client = new DefaultOpenShiftClient();
client.builds().watch(new Watcher<Build>() {
@Override
public void eventReceived(Action action, Build build) {
System.out.println(action + ": " + build);
}
@Override
public void onClose(KubernetesClientException e) {
System.out.println("Closed: " + e);
}
});
client.close();
}
use of io.fabric8.openshift.client.DefaultOpenShiftClient in project fabric8 by fabric8io.
the class KubernetesHelper method createJenkinshiftOpenShiftClient.
public static OpenShiftClient createJenkinshiftOpenShiftClient(String jenkinshiftUrl) {
Config config = createJenkinshiftConfig(jenkinshiftUrl);
// TODO until jenkinshift supports HTTPS lets disable HTTPS by default
// openShiftClient = new DefaultOpenShiftClient(jenkinshiftUrl);
JenkinShiftClient jenkinShiftClient = new JenkinShiftClient(config);
jenkinShiftClient.updateHttpClient(config);
return jenkinShiftClient;
}
Aggregations