Search in sources :

Example 11 with ConfigBuilder

use of io.fabric8.kubernetes.api.model.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)

Example 12 with ConfigBuilder

use of io.fabric8.kubernetes.api.model.ConfigBuilder in project ballerina by ballerina-lang.

the class DefaultBallerinaDockerClient method getDockerClient.

/**
 * Creates a {@link DockerClient} from the given Docker host URL.
 *
 * @param env The URL of the Docker host. If this is null, a {@link DockerClient} pointed to the local Docker
 *            daemon will be created.
 * @return {@link DockerClient} object.
 */
private DockerClient getDockerClient(String env) {
    DockerClient client;
    if (env == null) {
        env = LOCAL_DOCKER_DAEMON_SOCKET;
    }
    Config dockerClientConfig = new ConfigBuilder().withDockerUrl(env).build();
    client = new io.fabric8.docker.client.DefaultDockerClient(dockerClientConfig);
    return client;
}
Also used : DockerClient(io.fabric8.docker.client.DockerClient) BallerinaDockerClient(org.ballerinalang.containers.docker.BallerinaDockerClient) Config(io.fabric8.docker.client.Config) ConfigBuilder(io.fabric8.docker.client.ConfigBuilder)

Example 13 with ConfigBuilder

use of io.fabric8.kubernetes.api.model.ConfigBuilder in project logging-log4j2 by apache.

the class KubernetesClientBuilder method kubernetesClientConfig.

private Config kubernetesClientConfig() {
    Config base = null;
    try {
        base = Config.autoConfigure(null);
    } catch (Exception ex) {
        if (ex instanceof NullPointerException) {
            return null;
        }
    }
    KubernetesClientProperties props = new KubernetesClientProperties(base);
    Config properties = new ConfigBuilder(base).withApiVersion(props.getApiVersion()).withCaCertData(props.getCaCertData()).withCaCertFile(props.getCaCertFile()).withClientCertData(props.getClientCertData()).withClientCertFile(props.getClientCertFile()).withClientKeyAlgo(props.getClientKeyAlgo()).withClientKeyData(props.getClientKeyData()).withClientKeyFile(props.getClientKeyFile()).withClientKeyPassphrase(props.getClientKeyPassphrase()).withConnectionTimeout(props.getConnectionTimeout()).withHttpProxy(props.getHttpProxy()).withHttpsProxy(props.getHttpsProxy()).withMasterUrl(props.getMasterUrl()).withNamespace(props.getNamespace()).withNoProxy(props.getNoProxy()).withPassword(props.getPassword()).withProxyPassword(props.getProxyPassword()).withProxyUsername(props.getProxyUsername()).withRequestTimeout(props.getRequestTimeout()).withRollingTimeout(props.getRollingTimeout()).withTrustCerts(props.isTrustCerts()).withUsername(props.getUsername()).build();
    return properties;
}
Also used : Config(io.fabric8.kubernetes.client.Config) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder)

Example 14 with ConfigBuilder

use of io.fabric8.kubernetes.api.model.ConfigBuilder in project flink by apache.

the class KubernetesTestBase method writeKubeConfigForMockKubernetesServer.

protected String writeKubeConfigForMockKubernetesServer() throws Exception {
    final Config kubeConfig = new ConfigBuilder().withApiVersion(server.getClient().getApiVersion()).withClusters(new NamedClusterBuilder().withName(CLUSTER_ID).withNewCluster().withNewServer(server.getClient().getMasterUrl().toString()).withInsecureSkipTlsVerify(true).endCluster().build()).withContexts(new NamedContextBuilder().withName(CLUSTER_ID).withNewContext().withCluster(CLUSTER_ID).withUser(server.getClient().getConfiguration().getUsername()).endContext().build()).withNewCurrentContext(CLUSTER_ID).build();
    final File kubeConfigFile = new File(temporaryFolder.newFolder(".kube"), "config");
    Serialization.yamlMapper().writeValue(kubeConfigFile, kubeConfig);
    return kubeConfigFile.getAbsolutePath();
}
Also used : NamedClusterBuilder(io.fabric8.kubernetes.api.model.NamedClusterBuilder) Config(io.fabric8.kubernetes.api.model.Config) ConfigBuilder(io.fabric8.kubernetes.api.model.ConfigBuilder) File(java.io.File) NamedContextBuilder(io.fabric8.kubernetes.api.model.NamedContextBuilder)

Example 15 with ConfigBuilder

use of io.fabric8.kubernetes.api.model.ConfigBuilder in project shinyproxy by openanalytics.

the class KubernetesBackend method initialize.

@Override
public void initialize() throws ShinyProxyException {
    super.initialize();
    ConfigBuilder configBuilder = new ConfigBuilder();
    String masterUrl = getProperty(PROPERTY_URL);
    if (masterUrl != null)
        configBuilder.withMasterUrl(masterUrl);
    String certPath = getProperty(PROPERTY_CERT_PATH);
    if (certPath != null && Files.isDirectory(Paths.get(certPath))) {
        Path certFilePath = Paths.get(certPath, "ca.pem");
        if (Files.exists(certFilePath))
            configBuilder.withCaCertFile(certFilePath.toString());
        certFilePath = Paths.get(certPath, "cert.pem");
        if (Files.exists(certFilePath))
            configBuilder.withClientCertFile(certFilePath.toString());
        certFilePath = Paths.get(certPath, "key.pem");
        if (Files.exists(certFilePath))
            configBuilder.withClientKeyFile(certFilePath.toString());
    }
    kubeClient = new DefaultKubernetesClient(configBuilder.build());
}
Also used : Path(java.nio.file.Path) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Aggregations

ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)13 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)7 Config (io.fabric8.kubernetes.client.Config)5 Config (io.fabric8.docker.client.Config)3 ConfigBuilder (io.fabric8.docker.client.ConfigBuilder)3 DockerClient (io.fabric8.docker.client.DockerClient)3 ProjectConfig (io.fabric8.devops.ProjectConfig)2 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 Pod (io.fabric8.kubernetes.api.model.Pod)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)2 Config (io.fabric8.kubernetes.api.model.Config)1 ConfigBuilder (io.fabric8.kubernetes.api.model.ConfigBuilder)1 NamedClusterBuilder (io.fabric8.kubernetes.api.model.NamedClusterBuilder)1 NamedContextBuilder (io.fabric8.kubernetes.api.model.NamedContextBuilder)1