@Override public NamespacedKubernetesClient inNamespace(String namespace) { Config updated = new ConfigBuilder(getConfiguration()).withNamespace(namespace).build(); return new DefaultKubernetesClient(httpClient, updated); }
@Override public NamespacedKubernetesClient inNamespace(String namespace) { Config updated = new ConfigBuilder(getConfiguration()).withNamespace(namespace).build(); return new AutoAdaptableKubernetesClient(httpClient, updated); }
.withApiVersion(or(kubernetesClientProperties.getApiVersion(), base.getApiVersion())) .withNamespace(or(kubernetesClientProperties.getNamespace(), base.getNamespace())) .withUsername(
builder.withNamespace((String) properties.get(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY));
public static void main(String[] args) throws InterruptedException { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master) .withTrustCerts(true) .withUsername("admin") .withPassword("admin") .withNamespace("default") .build(); try (final KubernetesClient client = new AutoAdaptableKubernetesClient(config)) { log("Received pods", client.pods().list()); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage(), e); Throwable[] suppressed = e.getSuppressed(); if (suppressed != null) { for (Throwable t : suppressed) { logger.error(t.getMessage(), t); } } } }
.withNamespace("testns") .build();
public NamespacedKubernetesClient createClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build(); return new DefaultKubernetesClient(config); }
@Test public void testWithNamespacePathAndSytemPropertiesAndBuilder() { System.setProperty(Config.KUBERNETES_NAMESPACE_FILE, TEST_NAMESPACE_FILE); System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "http://somehost:80"); System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "tobeoverriden"); Config config = new ConfigBuilder() .withNamespace("testns2") .build(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); assertEquals("testns2", config.getNamespace()); }
@Test public void testWithKubeConfigAndSytemPropertiesAndBuilder() { System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, TEST_KUBECONFIG_FILE); System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "http://somehost:80"); Config config = new ConfigBuilder() .withNamespace("testns2") .build(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); assertEquals("token", config.getOauthToken()); assertEquals("testns2", config.getNamespace()); }
public NamespacedOpenShiftClient createOpenShiftClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withNamespace("test") .withTrustCerts(true) .withTlsVersions(TLS_1_0) .build(); return new DefaultOpenShiftClient(config); } }
public NamespacedKubernetesClient createClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build(); return new DefaultKubernetesClient(config); }
public NamespacedOpenShiftClient createOpenShiftClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withNamespace("test") .withTrustCerts(true) .withTlsVersions(TLS_1_0) .build(); return new DefaultOpenShiftClient(config); } }
@Bean @ConditionalOnMissingBean(Config.class) public Config kubernetesClientConfig(KubernetesClientProperties kubernetesClientProperties) { Config base = new Config(); Config properties = new ConfigBuilder(base) //Only set values that have been explicitly specified .withMasterUrl(or(kubernetesClientProperties.getMasterUrl(), base.getMasterUrl())) .withApiVersion(or(kubernetesClientProperties.getApiVersion(), base.getApiVersion())) .withNamespace(or(kubernetesClientProperties.getNamespace(), base.getNamespace())) .withUsername(or(kubernetesClientProperties.getUsername(), base.getUsername())) .withPassword(or(kubernetesClientProperties.getPassword(), base.getPassword())) .withCaCertFile(or(kubernetesClientProperties.getCaCertFile(), base.getCaCertFile())) .withCaCertData(or(kubernetesClientProperties.getCaCertData(), base.getCaCertData())) .withClientKeyFile(or(kubernetesClientProperties.getClientKeyFile(), base.getClientKeyFile())) .withClientKeyData(or(kubernetesClientProperties.getClientKeyData(), base.getClientKeyData())) .withClientCertFile(or(kubernetesClientProperties.getClientCertFile(), base.getClientCertFile())) .withClientCertData(or(kubernetesClientProperties.getClientCertData(), base.getClientCertData())) //No magic is done for the properties below so we leave them as is. .withClientKeyAlgo(or(kubernetesClientProperties.getClientKeyAlgo(), base.getClientKeyAlgo())) .withClientKeyPassphrase(or(kubernetesClientProperties.getClientKeyPassphrase(), base.getClientKeyPassphrase())) .withConnectionTimeout(or(kubernetesClientProperties.getConnectionTimeout(), base.getConnectionTimeout())) .withRequestTimeout(or(kubernetesClientProperties.getRequestTimeout(), base.getRequestTimeout())) .withRollingTimeout(or(kubernetesClientProperties.getRollingTimeout(), base.getRollingTimeout())) .withTrustCerts(or(kubernetesClientProperties.isTrustCerts(), base.isTrustCerts())) .build(); if (properties.getNamespace() == null || properties.getNamespace().isEmpty()) { LOG.warn("No namespace has been detected. Please specify KUBERNETES_NAMESPACE env var, or use a later kubernetes version (1.3 or later)"); } return properties; }
@Override public NamespacedKubernetesClient inNamespace(String namespace) { Config updated = new ConfigBuilder(getConfiguration()).withNamespace(namespace).build(); return new AutoAdaptableKubernetesClient(httpClient, updated); }
@Override public NamespacedKubernetesClient inNamespace(String namespace) { Config updated = new ConfigBuilder(getConfiguration()).withNamespace(namespace).build(); return new DefaultKubernetesClient(httpClient, updated); }
@Override public NamespacedIstioClient inNamespace(String namespace) { Config updated = new ConfigBuilder(getConfiguration()) .withNamespace(namespace) .build(); return new DefaultIstioClient(getHttpClient(), updated); }
@Override public NamespacedIstioClient inNamespace(String namespace) { Config updated = new ConfigBuilder(getConfiguration()) .withNamespace(namespace) .build(); return new DefaultIstioClient(getHttpClient(), updated); }
public NamespacedKubernetesClient createClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build(); return new DefaultKubernetesClient(config); }
.withMasterUrl("http://somehost:80") .withApiVersion("v1") .withNamespace("testns") .withOauthToken("token") .withUsername("user")
/** * Lazily creates the kubernetes client if one is not already configured * * @param config * @param testKubernetesClient the client typically passed in during test cases * @return the lazily created kubernetes client */ protected static KubernetesClient getOrCreateKubernetesClient(Configuration config, KubernetesClient testKubernetesClient) { if (testKubernetesClient == null) { if (!Strings.isNullOrBlank(config.getMasterUrl())) { testKubernetesClient = new DefaultKubernetesClient(new ConfigBuilder() .withMasterUrl(config.getMasterUrl()) .withNamespace(config.getNamespace()) .build()); } else { testKubernetesClient = new DefaultKubernetesClient(new ConfigBuilder() .withNamespace(config.getNamespace()) .build()); } } return testKubernetesClient; }