Java Code Examples for io.fabric8.kubernetes.client.ConfigBuilder#build()
The following examples show how to use
io.fabric8.kubernetes.client.ConfigBuilder#build() .
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: IstioExecutor.java From istio-apim with Apache License 2.0 | 6 votes |
/** * Build the config for the client */ private Config buildConfig() throws APIManagementException { System.setProperty(TRY_KUBE_CONFIG, "false"); System.setProperty(TRY_SERVICE_ACCOUNT, "true"); ConfigBuilder configBuilder; configBuilder = new ConfigBuilder().withMasterUrl(kubernetesAPIServerUrl); if (!StringUtils.isEmpty(saTokenFileName)) { String token; String tokenFile = saTokenFilePath + "/" + saTokenFileName; try { token = FileUtil.readFileToString(tokenFile); } catch (IOException e) { throw new APIManagementException("Error while reading the SA Token FIle " + tokenFile); } configBuilder.withOauthToken(token); } return configBuilder.build(); }
Example 2
Source File: OperatorAutoConfiguration.java From java-operator-sdk with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnMissingBean public KubernetesClient kubernetesClient(OperatorProperties operatorProperties) { ConfigBuilder config = new ConfigBuilder(); config.withTrustCerts(operatorProperties.isTrustSelfSignedCertificates()); if (StringUtils.isNotBlank(operatorProperties.getUsername())) { config.withUsername(operatorProperties.getUsername()); } if (StringUtils.isNotBlank(operatorProperties.getPassword())) { config.withUsername(operatorProperties.getPassword()); } if (StringUtils.isNotBlank(operatorProperties.getMasterUrl())) { config.withMasterUrl(operatorProperties.getMasterUrl()); } KubernetesClient k8sClient = operatorProperties.isOpenshift() ? new DefaultOpenShiftClient(config.build()) : new DefaultKubernetesClient(config.build()); return k8sClient; }
Example 3
Source File: KubernetesHandler.java From apollo with Apache License 2.0 | 6 votes |
private KubernetesClient createKubernetesClient(Environment environment) { try { ConfigBuilder configBuilder = new ConfigBuilder() .withMasterUrl(environment.getKubernetesMaster()) .withOauthToken(environment.getKubernetesToken()); String caCert = environment.getKubernetesCaCert(); if (StringUtils.isNotBlank(caCert)) { configBuilder.withCaCertData(caCert); } Config config = configBuilder.build(); return new DefaultKubernetesClient(config); } catch (Exception e) { logger.error("Could not create kubernetes client for environment {}", environment.getId(), e); throw new RuntimeException(); } }
Example 4
Source File: K8sNetworkingUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Obtains workable kubernetes client. * * @param config kubernetes API config * @return kubernetes client */ public static KubernetesClient k8sClient(K8sApiConfig config) { if (config == null) { log.warn("Kubernetes API server config is empty."); return null; } String endpoint = endpoint(config); ConfigBuilder configBuilder = new ConfigBuilder().withMasterUrl(endpoint); if (config.scheme() == K8sApiConfig.Scheme.HTTPS) { configBuilder.withTrustCerts(true) .withOauthToken(config.token()) .withCaCertData(config.caCertData()) .withClientCertData(config.clientCertData()) .withClientKeyData(config.clientKeyData()); } return new DefaultKubernetesClient(configBuilder.build()); }
Example 5
Source File: K8sNodeUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Obtains workable kubernetes client. * * @param config kubernetes API config * @return kubernetes client */ public static KubernetesClient k8sClient(K8sApiConfig config) { if (config == null) { log.warn("Kubernetes API server config is empty."); return null; } String endpoint = endpoint(config); ConfigBuilder configBuilder = new ConfigBuilder().withMasterUrl(endpoint); if (config.scheme() == K8sApiConfig.Scheme.HTTPS) { configBuilder.withTrustCerts(true) .withCaCertData(config.caCertData()) .withClientCertData(config.clientCertData()) .withClientKeyData(config.clientKeyData()); if (StringUtils.isNotEmpty(config.token())) { configBuilder.withOauthToken(config.token()); } } return new DefaultKubernetesClient(configBuilder.build()); }
Example 6
Source File: KubernetesClientFactory.java From kubernetes-elastic-agents with Apache License 2.0 | 5 votes |
private KubernetesClient createClientFor(PluginSettings pluginSettings) { final ConfigBuilder configBuilder = new ConfigBuilder() .withOauthToken(pluginSettings.getSecurityToken()) .withMasterUrl(pluginSettings.getClusterUrl()) .withCaCertData(pluginSettings.getCaCertData()) .withNamespace(pluginSettings.getNamespace()); return new DefaultKubernetesClient(configBuilder.build()); }
Example 7
Source File: Fabric8WorkspaceEnvironmentProvider.java From rh-che with Eclipse Public License 2.0 | 5 votes |
public Config getWorkspacesOpenshiftConfig(Subject subject) throws InfrastructureException { Config config; checkSubject(subject); UserCheTenantData cheTenantData = getUserCheTenantData(subject); checkClusterCapacity(cheTenantData); String osoProxyUrl = multiClusterOpenShiftProxy.getUrl(); String namespace = cheTenantData.getNamespace(); ConfigBuilder configBuilder = new ConfigBuilder().withNamespace(namespace).withTrustCerts(true); if (standalone) { return configBuilder.build(); } String userId = subject.getUserId(); LOG.debug("The namespace '{}' is used by user '{}'", namespace, userId); if (cheServiceAccountTokenToggle.useCheServiceAccountToken(userId)) { LOG.debug("Using Che SA token for '{}'", userId); config = configBuilder.withMasterUrl(osoProxyUrl).withOauthToken(cheServiceAccountToken).build(); LOG.debug("Adding Impersonate Header: '{}'", userId); config.getRequestConfig().setImpersonateUsername(userId); // hot-fix to avoid NPE in ImpersonatorInterceptor when optional `Impersonate-Group` is not // set - https://github.com/fabric8io/kubernetes-client/issues/1266 // Need to update kubernetes-client to 4.1.1 version in upstream che - // https://github.com/eclipse/che/issues/11981 LOG.debug("Adding Impersonate Group: 'dummyGroup'"); config.getRequestConfig().setImpersonateGroups("dummyGroup"); } else { LOG.debug("Using OSIO user token for '{}'", userId); config = configBuilder.withMasterUrl(osoProxyUrl).withOauthToken(subject.getToken()).build(); } return config; }
Example 8
Source File: KubernetesClientFactory.java From che with Eclipse Public License 2.0 | 5 votes |
/** * Builds the default Kubernetes {@link Config} that will be the base configuration to create * per-workspace configurations. */ protected Config buildDefaultConfig(String masterUrl, Boolean doTrustCerts) { ConfigBuilder configBuilder = new ConfigBuilder(); if (!isNullOrEmpty(masterUrl)) { configBuilder.withMasterUrl(masterUrl); } if (doTrustCerts != null) { configBuilder.withTrustCerts(doTrustCerts); } return configBuilder.build(); }
Example 9
Source File: ClientFactory.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static KnativeClient newClient(String[] args) { ConfigBuilder config = new ConfigBuilder(); for (int i = 0; i < args.length - 1; i++) { String key = args[i]; String value = args[i + 1]; if (key.equals("--api-server")) { config = config.withMasterUrl(value); } if (key.equals("--token")) { config = config.withOauthToken(value); } if (key.equals("--username")) { config = config.withUsername(value); } if (key.equals("--password")) { config = config.withPassword(value); } if (key.equals("--namespace")) { config = config.withNamespace(value); } } return new DefaultKnativeClient(config.build()); }
Example 10
Source File: ClientFactory.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static TektonClient newClient(String[] args) { ConfigBuilder config = new ConfigBuilder(); for (int i = 0; i < args.length - 1; i++) { String key = args[i]; String value = args[i + 1]; if (key.equals("--api-server")) { config = config.withMasterUrl(value); } if (key.equals("--token")) { config = config.withOauthToken(value); } if (key.equals("--username")) { config = config.withUsername(value); } if (key.equals("--password")) { config = config.withPassword(value); } if (key.equals("--namespace")) { config = config.withNamespace(value); } } return new DefaultTektonClient(config.build()); }
Example 11
Source File: ClientFactory.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static ServiceCatalogClient newClient(String[] args) { ConfigBuilder config = new ConfigBuilder(); for (int i = 0; i < args.length - 1; i++) { String key = args[i]; String value = args[i + 1]; if (key.equals("--api-server")) { config = config.withMasterUrl(value); } if (key.equals("--token")) { config = config.withOauthToken(value); } if (key.equals("--username")) { config = config.withUsername(value); } if (key.equals("--password")) { config = config.withPassword(value); } if (key.equals("--namespace")) { config = config.withNamespace(value); } } return new DefaultServiceCatalogClient(config.build()); }
Example 12
Source File: ClusterConfiguration.java From jkube with Eclipse Public License 2.0 | 4 votes |
public Config getConfig() { final ConfigBuilder configBuilder = new ConfigBuilder(); if (StringUtils.isNotBlank(this.username)) { configBuilder.withUsername(this.username); } if (StringUtils.isNotBlank(this.password)) { configBuilder.withPassword(this.password); } if (StringUtils.isNotBlank(this.masterUrl)) { configBuilder.withMasterUrl(this.masterUrl); } if (StringUtils.isNotBlank(this.apiVersion)) { configBuilder.withApiVersion(this.apiVersion); } if (StringUtils.isNotBlank(this.caCertData)) { configBuilder.withCaCertData(this.caCertData); } if (StringUtils.isNotBlank(this.caCertFile)) { configBuilder.withCaCertFile(this.caCertFile); } if (StringUtils.isNotBlank(this.clientCertData)) { configBuilder.withClientCertData(this.clientCertData); } if (StringUtils.isNotBlank(this.clientCertFile)) { configBuilder.withClientCertFile(this.clientCertFile); } if (StringUtils.isNotBlank(this.clientKeyAlgo)) { configBuilder.withClientKeyAlgo(this.clientKeyAlgo); } if (StringUtils.isNotBlank(this.clientKeyData)) { configBuilder.withClientKeyData(this.clientKeyData); } if (StringUtils.isNotBlank(this.clientKeyFile)) { configBuilder.withClientKeyFile(this.clientKeyFile); } if (StringUtils.isNotBlank(this.clientKeyPassphrase)) { configBuilder.withClientKeyPassphrase(this.clientKeyPassphrase); } if (StringUtils.isNotBlank(this.keyStoreFile)) { configBuilder.withKeyStoreFile(this.keyStoreFile); } if (StringUtils.isNotBlank(this.keyStorePassphrase)) { configBuilder.withKeyStorePassphrase(this.keyStorePassphrase); } if (StringUtils.isNotBlank(namespace)) { configBuilder.withNamespace(getNamespace()); } if (StringUtils.isNotBlank(this.trustStoreFile)) { configBuilder.withTrustStoreFile(this.trustStoreFile); } if (StringUtils.isNotBlank(this.trustStorePassphrase)) { configBuilder.withTrustStorePassphrase(this.trustStorePassphrase); } return configBuilder.build(); }
Example 13
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Activate public void activate(Map<String, Object> properties) { final ConfigBuilder builder = new ConfigBuilder(); if (properties.containsKey(KUBERNETES_MASTER_SYSTEM_PROPERTY)) { builder.withMasterUrl((String) properties.get(KUBERNETES_MASTER_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_API_VERSION_SYSTEM_PROPERTY)) { builder.withApiVersion((String) properties.get(KUBERNETES_API_VERSION_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY)) { builder.withNamespace((String) properties.get(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY)) { builder.withCaCertFile((String) properties.get(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY)) { builder.withCaCertData((String) properties.get(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY)) { builder.withClientCertFile((String) properties.get(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY)) { builder.withClientCertData((String) properties.get(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY)) { builder.withClientKeyFile((String) properties.get(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY)) { builder.withClientKeyData((String) properties.get(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY)) { builder.withClientKeyAlgo((String) properties.get(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY)) { builder.withClientKeyPassphrase((String) properties.get(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_AUTH_BASIC_USERNAME_SYSTEM_PROPERTY)) { builder.withUsername((String) properties.get(KUBERNETES_AUTH_BASIC_USERNAME_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_AUTH_BASIC_PASSWORD_SYSTEM_PROPERTY)) { builder.withPassword((String) properties.get(KUBERNETES_AUTH_BASIC_PASSWORD_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_OAUTH_TOKEN_SYSTEM_PROPERTY)) { builder.withOauthToken((String) properties.get(KUBERNETES_OAUTH_TOKEN_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY)) { builder.withWatchReconnectInterval(Integer.parseInt((String) properties.get(KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_WATCH_RECONNECT_LIMIT_SYSTEM_PROPERTY)) { builder.withWatchReconnectLimit(Integer.parseInt((String) properties.get(KUBERNETES_WATCH_RECONNECT_LIMIT_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY)) { builder.withRequestTimeout(Integer.parseInt((String) properties.get(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_HTTP_PROXY)) { builder.withHttpProxy((String) properties.get(KUBERNETES_HTTP_PROXY)); } if (properties.containsKey(KUBERNETES_HTTPS_PROXY)) { builder.withHttpsProxy((String) properties.get(KUBERNETES_HTTPS_PROXY)); } if (properties.containsKey(KUBERNETES_NO_PROXY)) { String noProxyProperty = (String) properties.get(KUBERNETES_NO_PROXY); builder.withNoProxy(noProxyProperty.split(",")); } if (properties.containsKey(KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY)) { builder.withWebsocketTimeout(Long.parseLong((String) properties.get(KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY)) { builder.withWebsocketPingInterval(Long.parseLong((String) properties.get(KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_TRUSTSTORE_FILE_PROPERTY)) { builder.withTrustStoreFile((String) properties.get(KUBERNETES_TRUSTSTORE_FILE_PROPERTY)); } if (properties.containsKey(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY)) { builder.withTrustStorePassphrase((String) properties.get(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY)); } if (properties.containsKey(KUBERNETES_KEYSTORE_FILE_PROPERTY)) { builder.withKeyStoreFile((String) properties.get(KUBERNETES_KEYSTORE_FILE_PROPERTY)); } if (properties.containsKey(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY)) { builder.withKeyStorePassphrase((String) properties.get(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY)); } if (provider != null ) { builder.withOauthTokenProvider(provider); } delegate = new DefaultKubernetesClient(builder.build()); }
Example 14
Source File: HorizontalPodAutoscalerExample.java From kubernetes-client with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final ConfigBuilder configBuilder = new ConfigBuilder(); if (args.length > 0) { configBuilder.withMasterUrl(args[0]); } try (final KubernetesClient client = new DefaultKubernetesClient(configBuilder.build())) { HorizontalPodAutoscaler horizontalPodAutoscaler = new HorizontalPodAutoscalerBuilder() .withNewMetadata().withName("the-hpa").withNamespace("default").endMetadata() .withNewSpec() .withNewScaleTargetRef() .withApiVersion("apps/v1") .withKind("Deployment") .withName("the-deployment") .endScaleTargetRef() .withMinReplicas(1) .withMaxReplicas(10) .addToMetrics(new MetricSpecBuilder() .withType("Resource") .withNewResource() .withName("cpu") .withNewTarget() .withType("Utilization") .withAverageUtilization(50) .endTarget() .endResource() .build()) .withNewBehavior() .withNewScaleDown() .addNewPolicy() .withType("Pods") .withValue(4) .withPeriodSeconds(60) .endPolicy() .addNewPolicy() .withType("Percent") .withValue(10) .withPeriodSeconds(60) .endPolicy() .endScaleDown() .endBehavior() .endSpec() .build(); client.autoscaling().v2beta2().horizontalPodAutoscalers().inNamespace("default").create(horizontalPodAutoscaler); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } }