@Deprecated public LogWatchCallback(OutputStream out) { this(new Config(), out); }
@Deprecated public ExecWebSocketListener(InputStream in, OutputStream out, OutputStream err, PipedOutputStream inputPipe, PipedInputStream outputPipe, PipedInputStream errorPipe, ExecListener listener) { this(new Config(), in, out, err, inputPipe, outputPipe, errorPipe, listener); }
public static Config fromKubeconfig(String context, String kubeconfigContents, String kubeconfigPath) { // we allow passing context along here, since downstream accepts it Config config = new Config(); Config.loadFromKubeconfig(config, context, kubeconfigContents, kubeconfigPath); return config; }
/** * @param context if null will use current-context */ public static Config autoConfigure(String context) { Config config = new Config(); return autoConfigure(config, context); }
System.setProperty(Config.KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY, "keystorePassphrase"); Config config = new Config(); assertConfig(config);
@Test public void testWithNamespacePath() { System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, "nokubeconfigfile"); System.setProperty(Config.KUBERNETES_NAMESPACE_FILE, TEST_NAMESPACE_FILE); System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "http://somehost:80"); Config config = new Config(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); assertEquals("testnsfrompath", config.getNamespace()); }
@Test public void testWithNonExistingNamespacePath() { System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, "nokubeconfigfile"); System.setProperty(Config.KUBERNETES_NAMESPACE_FILE, "nonamespace"); System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "http://somehost:80"); Config config = new Config(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); assertEquals(null, config.getNamespace()); }
@Test public void testWithNamespacePathAndSystemProperties() { 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, "testns"); Config config = new Config(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); assertEquals("testns", config.getNamespace()); }
@Test public void testWithKubeConfig() { System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, TEST_KUBECONFIG_FILE); Config config = new Config(); assertNotNull(config); assertEquals("https://172.28.128.4:8443/", config.getMasterUrl()); assertEquals("testns", config.getNamespace()); assertEquals("token", config.getOauthToken()); assertTrue(config.getCaCertFile().endsWith("testns/ca.pem".replace("/", File.separator))); assertTrue(new File(config.getCaCertFile()).isAbsolute()); }
@Test public void testWithKubeConfigAndSystemProperties() { System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, TEST_KUBECONFIG_FILE); System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "http://somehost:80"); Config config = new Config(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); assertEquals("testns", config.getNamespace()); assertEquals("token", config.getOauthToken()); }
@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; }
Config config = new Config(); when(client.getConfiguration()).thenReturn( config );
@Bean @ConditionalOnMissingBean(Config.class) public Config kubernetesClientConfig() { Config base = new Config(); Config properites = new ConfigBuilder(base) //Only set values that have been explicitly specified .withMasterUrl(or(properties.getMasterUrl(), base.getMasterUrl())) .withMasterUrl(or(properties.getApiVersion(), base.getApiVersion())) .withMasterUrl(or(properties.getApiVersion(), base.getMasterUrl())) .withUsername(or(properties.getUsername(), base.getUsername())) .withPassword(or(properties.getPassword(), base.getPassword())) .withCaCertFile(or(properties.getCaCertFile(), base.getCaCertFile())) .withCaCertData(or(properties.getCaCertData(), base.getCaCertData())) .withClientKeyFile(or(properties.getClientKeyFile(), base.getClientKeyFile())) .withClientKeyData(or(properties.getClientKeyData(), base.getClientKeyData())) .withClientCertFile(or(properties.getClientCertFile(), base.getClientCertFile())) .withClientCertData(or(properties.getClientCertData(), base.getClientCertData())) //No magic is done for the properties below so we leave them as is. .withClientKeyAlgo(or(properties.getClientKeyAlgo(), base.getClientKeyAlgo())) .withClientKeyPassphrase(or(properties.getClientKeyPassphrase(), base.getClientKeyPassphrase())) .withConnectionTimeout(or(properties.getConnectionTimeout(), base.getConnectionTimeout())) .withRequestTimeout(or(properties.getRequestTimeout(), base.getRequestTimeout())) .withRollingTimeout(or(properties.getRollingTimeout(), base.getRollingTimeout())) .withTrustCerts(or(properties.isTrustCerts(), base.isTrustCerts())) .build(); if (!base.equals(properites)) { System.out.println("Objects different"); } return properites; }
@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; }