use of io.fabric8.docker.client.ConfigBuilder in project camel by apache.
the class KubernetesEndpoint method createKubernetesClient.
private KubernetesClient createKubernetesClient() {
LOG.debug("Create Kubernetes client with the following Configuration: " + configuration.toString());
ConfigBuilder builder = new ConfigBuilder();
builder.withMasterUrl(configuration.getMasterUrl());
if ((ObjectHelper.isNotEmpty(configuration.getUsername()) && ObjectHelper.isNotEmpty(configuration.getPassword())) && ObjectHelper.isEmpty(configuration.getOauthToken())) {
builder.withUsername(configuration.getUsername());
builder.withPassword(configuration.getPassword());
}
if (ObjectHelper.isNotEmpty(configuration.getOauthToken())) {
builder.withOauthToken(configuration.getOauthToken());
}
if (ObjectHelper.isNotEmpty(configuration.getCaCertData())) {
builder.withCaCertData(configuration.getCaCertData());
}
if (ObjectHelper.isNotEmpty(configuration.getCaCertFile())) {
builder.withCaCertFile(configuration.getCaCertFile());
}
if (ObjectHelper.isNotEmpty(configuration.getClientCertData())) {
builder.withClientCertData(configuration.getClientCertData());
}
if (ObjectHelper.isNotEmpty(configuration.getClientCertFile())) {
builder.withClientCertFile(configuration.getClientCertFile());
}
if (ObjectHelper.isNotEmpty(configuration.getApiVersion())) {
builder.withApiVersion(configuration.getApiVersion());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyAlgo())) {
builder.withClientKeyAlgo(configuration.getClientKeyAlgo());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyData())) {
builder.withClientKeyData(configuration.getClientKeyData());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyFile())) {
builder.withClientKeyFile(configuration.getClientKeyFile());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyPassphrase())) {
builder.withClientKeyPassphrase(configuration.getClientKeyPassphrase());
}
if (ObjectHelper.isNotEmpty(configuration.getTrustCerts())) {
builder.withTrustCerts(configuration.getTrustCerts());
}
Config conf = builder.build();
return new DefaultKubernetesClient(conf);
}
use of io.fabric8.docker.client.ConfigBuilder 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.docker.client.ConfigBuilder in project jointware by isdream.
the class KubernetesClient method create.
@Override
public Object create(Map<String, Object> map) {
String prefix = null;
if (map == null || map.get(MASTER_TYPE) == null) {
return null;
} else if (map.get(MASTER_TYPE).equals(PROTOCOL_HTTP)) {
prefix = PROTOCOL_HTTP + "://";
} else {
return null;
}
Config config = new ConfigBuilder().withMasterUrl(prefix + map.get(MASTER_IP) + ":" + map.get(MASTER_PORT)).build();
return new DefaultKubernetesClient(config);
}
use of io.fabric8.docker.client.ConfigBuilder in project kubernetes by ballerinax.
the class DockerHandler method pushImage.
/**
* Push docker image.
*
* @param dockerModel DockerModel
* @throws InterruptedException When error with docker build process
* @throws IOException When error with docker build process
*/
public void pushImage(DockerModel dockerModel) throws InterruptedException, IOException, KubernetesPluginException {
AuthConfig authConfig = new AuthConfigBuilder().withUsername(dockerModel.getUsername()).withPassword(dockerModel.getPassword()).build();
Config config = new ConfigBuilder().withDockerUrl(dockerModel.getDockerHost()).addToAuthConfigs(RegistryUtils.extractRegistry(dockerModel.getName()), authConfig).build();
DockerClient client = new DefaultDockerClient(config);
final DockerError dockerError = new DockerError();
OutputHandle handle = client.image().withName(dockerModel.getName()).push().usingListener(new EventListener() {
@Override
public void onSuccess(String message) {
pushDone.countDown();
}
@Override
public void onError(String message) {
pushDone.countDown();
dockerError.setErrorMsg("error pushing docker image: " + message);
}
@Override
public void onError(Throwable t) {
pushDone.countDown();
dockerError.setErrorMsg("error pushing docker image: " + t.getMessage());
}
@Override
public void onEvent(String event) {
printDebug(event);
}
}).toRegistry();
pushDone.await();
handle.close();
client.close();
handleError(dockerError);
}
use of io.fabric8.docker.client.ConfigBuilder 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;
}
Aggregations