use of io.fabric8.docker.client.ConfigBuilder in project fabric8 by fabric8io.
the class PodIdToReplicationControllerIDExample method main.
public static void main(String[] args) {
if (args.length < 3) {
System.out.println("Arguments: kuberneteMasterUrl namespace podID");
return;
}
String kuberneteMasterUrl = args[0];
String namespace = args[1];
String podID = args[2];
System.out.println("Looking up ReplicationController for pod ID: " + podID);
KubernetesClient client = new DefaultKubernetesClient(new ConfigBuilder().withMasterUrl(kuberneteMasterUrl).build());
Pod pod = (Pod) client.pods().inNamespace(namespace).withName(podID);
pod.getMetadata().getLabels();
List<ReplicationController> replicationControllers = client.replicationControllers().inNamespace(namespace).withLabels(pod.getMetadata().getLabels()).list().getItems();
if (replicationControllers.size() == 1) {
ReplicationController replicationController = replicationControllers.get(0);
String id = KubernetesHelper.getName(replicationController);
System.out.println("Found replication controller: " + id);
} else {
System.out.println("Could not find replication controller!");
}
}
use of io.fabric8.docker.client.ConfigBuilder in project fabric8 by fabric8io.
the class DevOpsConnector method getKubernetes.
public KubernetesClient getKubernetes() {
if (kubernetes == null) {
Config config = new ConfigBuilder().withNamespace(namespace).build();
kubernetes = new DefaultKubernetesClient(config);
}
return kubernetes;
}
use of io.fabric8.docker.client.ConfigBuilder in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method buildConfig.
/**
* Build configurations for Openshift client
*
* @throws ContainerBasedGatewayException if failed to configure Openshift client
*/
private Config buildConfig() throws ContainerBasedGatewayException {
System.setProperty(TRY_KUBE_CONFIG, "false");
System.setProperty(TRY_SERVICE_ACCOUNT, "true");
ConfigBuilder configBuilder;
if (masterURL != null) {
configBuilder = new ConfigBuilder().withMasterUrl(masterURL);
} else {
throw new ContainerBasedGatewayException("Kubernetes Master URL is not provided!", ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
if (!StringUtils.isEmpty(saTokenFileName)) {
configBuilder.withOauthToken(resolveToken("encrypted" + saTokenFileName));
}
return configBuilder.build();
}
use of io.fabric8.docker.client.ConfigBuilder in project camel by apache.
the class KubernetesClientServiceDiscovery method doStart.
@Override
protected void doStart() throws Exception {
if (client != null) {
return;
}
final KubernetesConfiguration configuration = getConfiguration();
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());
} else {
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());
}
client = new AutoAdaptableKubernetesClient(builder.build());
}
use of io.fabric8.docker.client.ConfigBuilder in project kubernetes by ballerinax.
the class DockerHandler method buildImage.
/**
* Create docker image.
*
* @param dockerModel dockerModel object
* @param dockerDir dockerfile directory
* @throws InterruptedException When error with docker build process
* @throws IOException When error with docker build process
*/
public void buildImage(DockerModel dockerModel, String dockerDir) throws InterruptedException, IOException, KubernetesPluginException {
Config dockerClientConfig = new ConfigBuilder().withDockerUrl(dockerModel.getDockerHost()).build();
DockerClient client = new io.fabric8.docker.client.DefaultDockerClient(dockerClientConfig);
final DockerError dockerError = new DockerError();
OutputHandle buildHandle = client.image().build().withRepositoryName(dockerModel.getName()).withNoCache().alwaysRemovingIntermediate().usingListener(new EventListener() {
@Override
public void onSuccess(String message) {
buildDone.countDown();
}
@Override
public void onError(String message) {
dockerError.setErrorMsg("error building docker image: " + message);
buildDone.countDown();
}
@Override
public void onError(Throwable t) {
dockerError.setErrorMsg("error building docker image: " + t.getMessage());
buildDone.countDown();
}
@Override
public void onEvent(String event) {
printDebug(event);
}
}).fromFolder(dockerDir);
buildDone.await();
buildHandle.close();
client.close();
handleError(dockerError);
}
Aggregations