Java Code Examples for io.fabric8.kubernetes.client.ConfigBuilder#withMasterUrl()
The following examples show how to use
io.fabric8.kubernetes.client.ConfigBuilder#withMasterUrl() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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); } }