Search in sources :

Example 6 with ConfigBuilder

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!");
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 7 with ConfigBuilder

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;
}
Also used : Config(io.fabric8.kubernetes.client.Config) ProjectConfig(io.fabric8.devops.ProjectConfig) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 8 with ConfigBuilder

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();
}
Also used : ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)

Example 9 with ConfigBuilder

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());
}
Also used : ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) AutoAdaptableKubernetesClient(io.fabric8.kubernetes.client.AutoAdaptableKubernetesClient) KubernetesConfiguration(org.apache.camel.component.kubernetes.KubernetesConfiguration)

Example 10 with ConfigBuilder

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);
}
Also used : DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) DockerClient(io.fabric8.docker.client.DockerClient) Config(io.fabric8.docker.client.Config) AuthConfig(io.fabric8.docker.api.model.AuthConfig) DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) AuthConfigBuilder(io.fabric8.docker.api.model.AuthConfigBuilder) ConfigBuilder(io.fabric8.docker.client.ConfigBuilder) OutputHandle(io.fabric8.docker.dsl.OutputHandle) EventListener(io.fabric8.docker.dsl.EventListener)

Aggregations

ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)9 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)5 Config (io.fabric8.docker.client.Config)3 ConfigBuilder (io.fabric8.docker.client.ConfigBuilder)3 DockerClient (io.fabric8.docker.client.DockerClient)3 Config (io.fabric8.kubernetes.client.Config)3 AuthConfig (io.fabric8.docker.api.model.AuthConfig)2 AuthConfigBuilder (io.fabric8.docker.api.model.AuthConfigBuilder)2 DefaultDockerClient (io.fabric8.docker.client.DefaultDockerClient)2 EventListener (io.fabric8.docker.dsl.EventListener)2 OutputHandle (io.fabric8.docker.dsl.OutputHandle)2 ProjectConfig (io.fabric8.devops.ProjectConfig)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)1 AutoAdaptableKubernetesClient (io.fabric8.kubernetes.client.AutoAdaptableKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)1 Path (java.nio.file.Path)1 KubernetesConfiguration (org.apache.camel.component.kubernetes.KubernetesConfiguration)1