Java Code Examples for io.kubernetes.client.util.Config#fromConfig()

The following examples show how to use io.kubernetes.client.util.Config#fromConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubeOpt.java    From dew with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates a new Kube opt.
 *
 * @param log              the log
 * @param base64KubeConfig the base64 kube config
 */
protected KubeOpt(Logger log, String base64KubeConfig) {
    this.log = log;
    YamlHelper.init(log);
    try {
        client = Config.fromConfig(
                KubeConfig.loadKubeConfig(
                        new StringReader(
                                $.security.decodeBase64ToString(base64KubeConfig, "UTF-8")
                        )
                )
        );
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    client.setReadTimeout(0);
    Configuration.setDefaultApiClient(client);
    coreApi = new CoreV1Api(client);
    appsApi = new AppsV1Api(client);
    extensionsApi = new ExtensionsV1beta1Api(client);
    rbacAuthorizationApi = new RbacAuthorizationV1Api(client);
    autoscalingApi = new AutoscalingV2beta2Api(client);
    podLogs = new PodLogs(client);
}
 
Example 2
Source File: KubeClusterMembershipConnectorComponent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
public ApiClient getApiClient(KubeConnectorConfiguration configuration) {
    String kubeApiServerUri = StringExt.safeTrim(configuration.getKubeApiServerUri());
    String kubeConfigPath = StringExt.safeTrim(configuration.getKubeConfigPath());

    Preconditions.checkState(!kubeApiServerUri.isEmpty() || !kubeConfigPath.isEmpty(),
            "Kubernetes address not set"
    );

    ApiClient client;
    if (kubeApiServerUri.isEmpty()) {
        try {
            logger.info("Initializing Kube ApiClient from config file: {}", kubeConfigPath);
            client = Config.fromConfig(kubeConfigPath);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        logger.info("Initializing Kube ApiClient with URI: {}", kubeApiServerUri);
        client = Config.fromUrl(kubeApiServerUri);
    }

    client.setReadTimeout(0); // infinite timeout
    return client;
}
 
Example 3
Source File: KubeApiClients.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static ApiClient createApiClient(String kubeApiServerUrl,
                                        String kubeConfigPath,
                                        String metricsNamePrefix,
                                        TitusRuntime titusRuntime,
                                        Function<Request, String> uriMapper,
                                        long readTimeoutMs) {
    OkHttpMetricsInterceptor metricsInterceptor = new OkHttpMetricsInterceptor(metricsNamePrefix, titusRuntime.getRegistry(),
            titusRuntime.getClock(), uriMapper);

    ApiClient client;
    if (Strings.isNullOrEmpty(kubeApiServerUrl)) {
        try {
            client = Config.fromConfig(kubeConfigPath);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        client = Config.fromUrl(kubeApiServerUrl);
    }

    client.setHttpClient(
            client.getHttpClient().newBuilder()
                    .addInterceptor(metricsInterceptor)
                    .readTimeout(readTimeoutMs, TimeUnit.SECONDS)
                    .build()
    );
    return client;
}