Search in sources :

Example 1 with ConfigBuilder

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);
}
Also used : Config(io.fabric8.kubernetes.client.Config) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 2 with ConfigBuilder

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();
    }
}
Also used : ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder)

Example 3 with ConfigBuilder

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);
}
Also used : Config(io.fabric8.kubernetes.client.Config) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 4 with ConfigBuilder

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

Example 5 with ConfigBuilder

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;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient)

Aggregations

ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)10 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)5 Config (io.fabric8.kubernetes.client.Config)4 Config (io.fabric8.docker.client.Config)3 ConfigBuilder (io.fabric8.docker.client.ConfigBuilder)3 DockerClient (io.fabric8.docker.client.DockerClient)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 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 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