public BaseClient(final Config config) throws KubernetesClientException { this(HttpClientUtils.createHttpClient(config), config); }
private static URL getProxyUrl(Config config) throws MalformedURLException { URL master = new URL(config.getMasterUrl()); String host = master.getHost(); if (config.getNoProxy() != null) { for (String noProxy : config.getNoProxy()) { if (isIpAddress(noProxy)) { if (new IpAddressMatcher(noProxy).matches(host)) { return null; } } else { if (host.contains(noProxy)) { return null; } } } } String proxy = config.getHttpsProxy(); if (master.getProtocol().equals("http")) { proxy = config.getHttpProxy(); } if (proxy != null) { return new URL(proxy); } return null; }
URL proxyUrl = getProxyUrl(config); if (proxyUrl != null) { httpClientBuilder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl.getHost(), proxyUrl.getPort())));
URL proxyUrl = getProxyUrl(config); if (proxyUrl != null) { httpClientBuilder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl.getHost(), proxyUrl.getPort())));
public static boolean isHttpsAvailable(Config config) { Config sslConfig = new ConfigBuilder(config) .withMasterUrl(Config.HTTPS_PROTOCOL_PREFIX + config.getMasterUrl()) .withRequestTimeout(1000) .withConnectionTimeout(1000) .build(); OkHttpClient client = HttpClientUtils.createHttpClient(config); try { Request request = new Request.Builder().get().url(sslConfig.getMasterUrl()) .build(); Response response = client.newCall(request).execute(); try (ResponseBody body = response.body()) { return response.isSuccessful(); } } catch (Throwable t) { LOG.warn("SSL handshake failed. Falling back to insecure connection."); } finally { if (client != null && client.connectionPool() != null) { client.connectionPool().evictAll(); } } return false; }
public BaseClient(final Config config) throws KubernetesClientException { this(HttpClientUtils.createHttpClient(config), config); }
@Produces @ApplicationScoped private static final OkHttpClient produceOkHttpClient(final Config config) { return HttpClientUtils.createHttpClient(config); }
public SupportUtil(NamespacedOpenShiftClient client, IntegrationHandler integrationHandler, IntegrationSupportHandler integrationSupportHandler) { this.client = client; this.integrationHandler = integrationHandler; this.integrationSupportHandler = integrationSupportHandler; this.okHttpClient = this.client == null ? null : HttpClientUtils.createHttpClient(this.client.getConfiguration()); }
public KubernetesSupport(KubernetesClient client) { this.client = client; this.okHttpClient = this.client == null ? null : HttpClientUtils.createHttpClient(this.client.getConfiguration()); }
public static boolean isHttpsAvailable(Config config) { Config sslConfig = new ConfigBuilder(config) .withMasterUrl(Config.HTTPS_PROTOCOL_PREFIX + config.getMasterUrl()) .withRequestTimeout(1000) .withConnectionTimeout(1000) .build(); OkHttpClient client = HttpClientUtils.createHttpClient(config); try { Request request = new Request.Builder().get().url(sslConfig.getMasterUrl()) .build(); Response response = client.newCall(request).execute(); try (ResponseBody body = response.body()) { return response.isSuccessful(); } } catch (Throwable t) { LOG.warn("SSL handshake failed. Falling back to insecure connection."); } finally { if (client != null && client.connectionPool() != null) { client.connectionPool().evictAll(); } } return false; }
static NamespacedKubernetesClient getKubernetesClient(Config rootConfig, String id, Container gke, KubernetesClientFactory clientFactory) { try { final Config config = rootConfig .getConfig(GKE_CLUSTER_PATH) .getConfig(id); final Cluster cluster = gke.projects().locations().clusters() .get(String.format("projects/%s/locations/%s/clusters/%s", config.getString(GKE_CLUSTER_PROJECT_ID), config.getString(GKE_CLUSTER_ZONE), config.getString(GKE_CLUSTER_ID))).execute(); final io.fabric8.kubernetes.client.Config kubeConfig = new ConfigBuilder() .withMasterUrl("https://" + cluster.getEndpoint()) .withCaCertData(cluster.getMasterAuth().getClusterCaCertificate()) .withClientCertData(cluster.getMasterAuth().getClientCertificate()) .withClientKeyData(cluster.getMasterAuth().getClientKey()) .withNamespace(config.getString(GKE_CLUSTER_NAMESPACE)) .withRequestTimeout(get(rootConfig, rootConfig::getInt, KUBERNETES_REQUEST_TIMEOUT) .orElse(DEFAULT_KUBERNETES_REQUEST_TIMEOUT_MILLIS)) .build(); final OkHttpClient httpClient = HttpClientUtils.createHttpClient(kubeConfig).newBuilder() .protocols(Collections.singletonList(Protocol.HTTP_1_1)) .build(); return clientFactory.apply(httpClient, kubeConfig); } catch (IOException e) { throw Throwables.propagate(e); } }