From be079e58fa0cdf68d1c9ea6d60f16c5f9550cfc0 Mon Sep 17 00:00:00 2001 From: shinjiro watanabe Date: Mon, 16 Dec 2019 14:42:48 +0900 Subject: [PATCH 1/6] get k8s config from requestConfig. and added test. --- .../kubernetes/KubernetesClientConfig.java | 25 +++----- .../KubernetesClientConfigTest.java | 63 ++++++++++++++++++- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java index 9a209cc023..8e9f37e79b 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java @@ -19,40 +19,33 @@ public static KubernetesClientConfig create(final Optional name, final Config systemConfig, final Config requestConfig) { - if (requestConfig.has("kubernetes")) { + Config config; + if (requestConfig.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { // from task request config - return KubernetesClientConfig.createFromTaskRequestConfig(name, requestConfig.getNested("kubernetes")); + config = requestConfig; } else { // from system config - return KubernetesClientConfig.createFromSystemConfig(name, systemConfig); + config = systemConfig; } - } - - private static KubernetesClientConfig createFromTaskRequestConfig(final Optional name, - final Config config) - { - // TODO - // We'd better to customize cluster config by task request config?? - throw new UnsupportedOperationException("Not support yet"); + return KubernetesClientConfig.create(name, config); } @VisibleForTesting - static KubernetesClientConfig createFromSystemConfig(final Optional name, - final io.digdag.client.config.Config systemConfig) + static KubernetesClientConfig create(final Optional name, final Config config) { final String clusterName; if (!name.isPresent()) { - if (!systemConfig.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { + if (!config.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { throw new ConfigException("agent.command_executor.type: is not 'kubernetes'"); } - clusterName = systemConfig.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); + clusterName = config.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); } else { clusterName = name.get(); } final String keyPrefix = KUBERNETES_CLIENT_PARAMS_PREFIX + clusterName + "."; - final Config extracted = StorageManager.extractKeyPrefix(systemConfig, keyPrefix); + final Config extracted = StorageManager.extractKeyPrefix(config, keyPrefix); if (extracted.has("kube_config_path")) { String kubeConfigPath = extracted.get("kube_config_path", String.class); io.fabric8.kubernetes.client.Config validatedKubeConfig; diff --git a/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java b/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java index bf4b5d2f54..6e8b6c19d3 100644 --- a/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java +++ b/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java @@ -59,7 +59,7 @@ public void testCreateFromSystemConfig() .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "test=") .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "default"); - KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.createFromSystemConfig(clusterName, systemConfig); + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig); String masterUrl = "https://127.0.0.1"; String namespace = "default"; @@ -79,7 +79,7 @@ public void testCreateFromSystemConfigWithKubeConfig() .set("agent.command_executor.type", "kubernetes") .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.kube_config_path", kubeConfigPath); - KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.createFromSystemConfig(clusterName, systemConfig); + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig); String masterUrl = "https://127.0.0.1"; String namespace = "default"; @@ -90,4 +90,63 @@ public void testCreateFromSystemConfigWithKubeConfig() assertThat(oauthToken, is(kubernetesClientConfig.getOauthToken())); assertThat(namespace, is(kubernetesClientConfig.getNamespace())); } + + @Test + public void testCreateFromLocalConfig() + throws Exception + { + final Config systemConfig = cf.create() + .set("agent.command_executor.type", "kubernetes") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.master", "https://127.0.0.1") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.certs_ca_data", "test=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "test=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "default"); + + final Config localConfig = cf.create() + .set("agent.command_executor.type", "kubernetes") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.master", "https://localhost") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.certs_ca_data", "testlocal=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "testlocal=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "local"); + + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig, localConfig); + + String masterUrl = "https://localhost"; + String namespace = "local"; + String caCertData = "testlocal="; + String oauthToken = "testlocal="; + assertThat(masterUrl, is(kubernetesClientConfig.getMaster())); + assertThat(caCertData, is(kubernetesClientConfig.getCertsCaData())); + assertThat(oauthToken, is(kubernetesClientConfig.getOauthToken())); + assertThat(namespace, is(kubernetesClientConfig.getNamespace())); + } + + @Test + public void testCreateFromLocalConfigWithKubeConfig() + throws Exception + { + + final Config systemConfig = cf.create() + .set("agent.command_executor.type", "kubernetes") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.master", "https://localhost") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.certs_ca_data", "testlocal=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "testlocal=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "local"); + + final Config localConfig = cf.create() + .set("agent.command_executor.type", "kubernetes") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.kube_config_path", kubeConfigPath); + + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig, localConfig); + + String masterUrl = "https://127.0.0.1"; + String namespace = "default"; + String caCertData = "test="; + String oauthToken = "test="; + assertThat(masterUrl, is(kubernetesClientConfig.getMaster())); + assertThat(caCertData, is(kubernetesClientConfig.getCertsCaData())); + assertThat(oauthToken, is(kubernetesClientConfig.getOauthToken())); + assertThat(namespace, is(kubernetesClientConfig.getNamespace())); + } + } From c067a6394e2c981e0192a00bb8e828d250bd454e Mon Sep 17 00:00:00 2001 From: shinjiro watanabe Date: Mon, 6 Jan 2020 17:17:13 +0900 Subject: [PATCH 2/6] change RequestConfig param yaml --- .../kubernetes/KubernetesClientConfig.java | 45 +++++++++---- .../KubernetesClientConfigTest.java | 67 +++++++++---------- 2 files changed, 66 insertions(+), 46 deletions(-) diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java index 8e9f37e79b..1bc6af08d3 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java @@ -19,35 +19,56 @@ public static KubernetesClientConfig create(final Optional name, final Config systemConfig, final Config requestConfig) { - Config config; - if (requestConfig.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { + if (requestConfig != null && requestConfig.has("kubernetes")) { // from task request config - config = requestConfig; + return KubernetesClientConfig.createFromTaskRequestConfig(name, requestConfig); } else { // from system config - config = systemConfig; + return KubernetesClientConfig.createFromSystemConfig(name, systemConfig); } - return KubernetesClientConfig.create(name, config); } @VisibleForTesting - static KubernetesClientConfig create(final Optional name, final Config config) + private static KubernetesClientConfig createFromTaskRequestConfig(final Optional name, + final Config requestConfig) + { + if (!requestConfig.has("kubernetes")) { + throw new ConfigException("not found 'kubernetes'"); + } + final Config kubernetesConfig = requestConfig.getNested("kubernetes"); + + final String clusterName; + if (!name.isPresent()) { + clusterName = kubernetesConfig.get("name", String.class); + } + else { + clusterName = name.get(); + } + return createKubeConfig(clusterName, kubernetesConfig); + } + + @VisibleForTesting + static KubernetesClientConfig createFromSystemConfig(final Optional name, final Config systemConfig) { final String clusterName; if (!name.isPresent()) { - if (!config.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { + if (!systemConfig.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { throw new ConfigException("agent.command_executor.type: is not 'kubernetes'"); } - clusterName = config.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); + clusterName = systemConfig.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); } else { clusterName = name.get(); } final String keyPrefix = KUBERNETES_CLIENT_PARAMS_PREFIX + clusterName + "."; - final Config extracted = StorageManager.extractKeyPrefix(config, keyPrefix); - if (extracted.has("kube_config_path")) { - String kubeConfigPath = extracted.get("kube_config_path", String.class); + final Config extracted = StorageManager.extractKeyPrefix(systemConfig, keyPrefix); + return createKubeConfig(clusterName, extracted); + } + + private static KubernetesClientConfig createKubeConfig(final String clusterName, final Config config){ + if (config.has("kube_config_path")) { + String kubeConfigPath = config.get("kube_config_path", String.class); io.fabric8.kubernetes.client.Config validatedKubeConfig; validatedKubeConfig = validateKubeConfig(getKubeConfigFromPath(kubeConfigPath)); return create(clusterName, @@ -56,7 +77,7 @@ static KubernetesClientConfig create(final Optional name, final Config c validatedKubeConfig.getOauthToken(), validatedKubeConfig.getNamespace()); } else { - final Config validatedConfig = validateConfig(extracted); + final Config validatedConfig = validateConfig(config); return create(clusterName, validatedConfig.get("master", String.class), validatedConfig.get("certs_ca_data", String.class), diff --git a/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java b/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java index 6e8b6c19d3..d7c1953f29 100644 --- a/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java +++ b/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java @@ -59,7 +59,16 @@ public void testCreateFromSystemConfig() .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "test=") .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "default"); - KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig); + final Config kubernetesConfig = cf.create() + .set("test.master", "https://127.0.0.1") + .set("test.certs_ca_data", "test=") + .set("test.oauth_token", "test=") + .set("test.namespace", "default"); + + final Config requestConfig = cf.create() + .setNested("kubernetes", kubernetesConfig); + + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig, null); String masterUrl = "https://127.0.0.1"; String namespace = "default"; @@ -79,7 +88,7 @@ public void testCreateFromSystemConfigWithKubeConfig() .set("agent.command_executor.type", "kubernetes") .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.kube_config_path", kubeConfigPath); - KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig); + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig, null); String masterUrl = "https://127.0.0.1"; String namespace = "default"; @@ -92,29 +101,24 @@ public void testCreateFromSystemConfigWithKubeConfig() } @Test - public void testCreateFromLocalConfig() + public void testCreateFromRequestConfig() throws Exception { - final Config systemConfig = cf.create() - .set("agent.command_executor.type", "kubernetes") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.master", "https://127.0.0.1") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.certs_ca_data", "test=") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "test=") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "default"); - - final Config localConfig = cf.create() - .set("agent.command_executor.type", "kubernetes") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.master", "https://localhost") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.certs_ca_data", "testlocal=") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "testlocal=") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "local"); - - KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig, localConfig); - - String masterUrl = "https://localhost"; - String namespace = "local"; - String caCertData = "testlocal="; - String oauthToken = "testlocal="; + final Config kubernetesConfig = cf.create() + .set("master", "https://127.0.0.1") + .set("certs_ca_data", "test=") + .set("oauth_token", "test=") + .set("namespace", "default"); + + final Config requestConfig = cf.create() + .setNested("kubernetes", kubernetesConfig); + + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, null, requestConfig); + + String masterUrl = "https://127.0.0.1"; + String namespace = "default"; + String caCertData = "test="; + String oauthToken = "test="; assertThat(masterUrl, is(kubernetesClientConfig.getMaster())); assertThat(caCertData, is(kubernetesClientConfig.getCertsCaData())); assertThat(oauthToken, is(kubernetesClientConfig.getOauthToken())); @@ -122,22 +126,17 @@ public void testCreateFromLocalConfig() } @Test - public void testCreateFromLocalConfigWithKubeConfig() + public void testCreateFromRequestConfigWithKubeConfig() throws Exception { - final Config systemConfig = cf.create() - .set("agent.command_executor.type", "kubernetes") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.master", "https://localhost") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.certs_ca_data", "testlocal=") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "testlocal=") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "local"); + final Config kubernetesConfig = cf.create() + .set("kube_config_path", kubeConfigPath); - final Config localConfig = cf.create() - .set("agent.command_executor.type", "kubernetes") - .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.kube_config_path", kubeConfigPath); + final Config requestConfig = cf.create() + .setNested("kubernetes", kubernetesConfig); - KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig, localConfig); + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, null, requestConfig); String masterUrl = "https://127.0.0.1"; String namespace = "default"; From 2f902d4e4b42cb0ac2f8979eed8ed89cc2d3ca6a Mon Sep 17 00:00:00 2001 From: shinjiro watanabe Date: Mon, 6 Jan 2020 17:22:16 +0900 Subject: [PATCH 3/6] code format. --- .../command/kubernetes/KubernetesClientConfig.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java index 1bc6af08d3..c6d7842791 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java @@ -21,7 +21,7 @@ public static KubernetesClientConfig create(final Optional name, { if (requestConfig != null && requestConfig.has("kubernetes")) { // from task request config - return KubernetesClientConfig.createFromTaskRequestConfig(name, requestConfig); + return KubernetesClientConfig.createFromTaskRequestConfig(name, requestConfig.getNested("kubernetes")); } else { // from system config @@ -31,13 +31,8 @@ public static KubernetesClientConfig create(final Optional name, @VisibleForTesting private static KubernetesClientConfig createFromTaskRequestConfig(final Optional name, - final Config requestConfig) + final Config kubernetesConfig) { - if (!requestConfig.has("kubernetes")) { - throw new ConfigException("not found 'kubernetes'"); - } - final Config kubernetesConfig = requestConfig.getNested("kubernetes"); - final String clusterName; if (!name.isPresent()) { clusterName = kubernetesConfig.get("name", String.class); @@ -49,7 +44,8 @@ private static KubernetesClientConfig createFromTaskRequestConfig(final Optional } @VisibleForTesting - static KubernetesClientConfig createFromSystemConfig(final Optional name, final Config systemConfig) + static KubernetesClientConfig createFromSystemConfig(final Optional name, + final Config systemConfig) { final String clusterName; if (!name.isPresent()) { From 44a9612f98a50bb4198e94f66db43397fc808455 Mon Sep 17 00:00:00 2001 From: shinjiro watanabe Date: Mon, 6 Jan 2020 17:24:08 +0900 Subject: [PATCH 4/6] change variable name --- .../command/kubernetes/KubernetesClientConfig.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java index c6d7842791..bfa39dee47 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java @@ -31,21 +31,21 @@ public static KubernetesClientConfig create(final Optional name, @VisibleForTesting private static KubernetesClientConfig createFromTaskRequestConfig(final Optional name, - final Config kubernetesConfig) + final Config config) { final String clusterName; if (!name.isPresent()) { - clusterName = kubernetesConfig.get("name", String.class); + clusterName = config.get("name", String.class); } else { clusterName = name.get(); } - return createKubeConfig(clusterName, kubernetesConfig); + return createKubeConfig(clusterName, config); } @VisibleForTesting static KubernetesClientConfig createFromSystemConfig(final Optional name, - final Config systemConfig) + final io.digdag.client.config.Config systemConfig) { final String clusterName; if (!name.isPresent()) { From 27db7965db6065d1c021dd00c785e2ef34ace65c Mon Sep 17 00:00:00 2001 From: shinjiro watanabe Date: Wed, 12 Feb 2020 05:18:29 +0900 Subject: [PATCH 5/6] Create a config that merges requestconfig with systemconfig --- .../kubernetes/KubernetesClientConfig.java | 66 +++++++++---------- .../KubernetesClientConfigTest.java | 20 ++++-- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java index bfa39dee47..f6658a3c28 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java @@ -19,47 +19,45 @@ public static KubernetesClientConfig create(final Optional name, final Config systemConfig, final Config requestConfig) { - if (requestConfig != null && requestConfig.has("kubernetes")) { - // from task request config - return KubernetesClientConfig.createFromTaskRequestConfig(name, requestConfig.getNested("kubernetes")); - } - else { - // from system config - return KubernetesClientConfig.createFromSystemConfig(name, systemConfig); - } - } - @VisibleForTesting - private static KubernetesClientConfig createFromTaskRequestConfig(final Optional name, - final Config config) - { - final String clusterName; - if (!name.isPresent()) { - clusterName = config.get("name", String.class); - } - else { + String clusterName = null; + if (name.isPresent()) { clusterName = name.get(); } - return createKubeConfig(clusterName, config); - } - @VisibleForTesting - static KubernetesClientConfig createFromSystemConfig(final Optional name, - final io.digdag.client.config.Config systemConfig) - { - final String clusterName; - if (!name.isPresent()) { - if (!systemConfig.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { - throw new ConfigException("agent.command_executor.type: is not 'kubernetes'"); + Config extractedSystemConfig = null; + if (systemConfig != null && systemConfig.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { + if (clusterName == null) { + clusterName = systemConfig.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); } - clusterName = systemConfig.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); + final String keyPrefix = KUBERNETES_CLIENT_PARAMS_PREFIX + clusterName + "."; + extractedSystemConfig = StorageManager.extractKeyPrefix(systemConfig, keyPrefix); } - else { - clusterName = name.get(); + + Config extractedRequestConfig = null; + if (requestConfig != null && requestConfig.has("kubernetes")) { + if (clusterName == null) { + clusterName = requestConfig.get("name", String.class); + } + extractedRequestConfig = requestConfig.getNested("kubernetes"); + } + + // Create a config that merges RequestConfig with SystemConfig + final Config config; + if (extractedSystemConfig != null && extractedRequestConfig != null) { + config = extractedSystemConfig.merge(extractedRequestConfig); + + } else if (extractedRequestConfig != null) { + config = extractedRequestConfig; + + } else if (extractedSystemConfig != null) { + config = extractedSystemConfig; + + } else { + throw new ConfigException("systemConfig and requestConfig does not exist"); } - final String keyPrefix = KUBERNETES_CLIENT_PARAMS_PREFIX + clusterName + "."; - final Config extracted = StorageManager.extractKeyPrefix(systemConfig, keyPrefix); - return createKubeConfig(clusterName, extracted); + + return KubernetesClientConfig.createKubeConfig(clusterName, config); } private static KubernetesClientConfig createKubeConfig(final String clusterName, final Config config){ diff --git a/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java b/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java index d7c1953f29..38918a14a0 100644 --- a/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java +++ b/digdag-standards/src/test/java/io/digdag/standards/command/kubernetes/KubernetesClientConfigTest.java @@ -126,20 +126,30 @@ public void testCreateFromRequestConfig() } @Test - public void testCreateFromRequestConfigWithKubeConfig() + public void testCreateFromRequestConfigAndSystemConfigMerge() throws Exception { + final Config systemConfig = cf.create() + .set("agent.command_executor.type", "kubernetes") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.master", "https://127.0.0.1") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.certs_ca_data", "test=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.oauth_token", "test=") + .set(KUBERNETES_CLIENT_PARAMS_PREFIX+"test.namespace", "default"); + final Config kubernetesConfig = cf.create() - .set("kube_config_path", kubeConfigPath); + .set("master", "https://localhost") +// .set("certs_ca_data", "test=") +// .set("oauth_token", "test=") + .set("namespace", "request"); final Config requestConfig = cf.create() .setNested("kubernetes", kubernetesConfig); - KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, null, requestConfig); + KubernetesClientConfig kubernetesClientConfig = KubernetesClientConfig.create(clusterName, systemConfig, requestConfig); - String masterUrl = "https://127.0.0.1"; - String namespace = "default"; + String masterUrl = "https://localhost"; + String namespace = "request"; String caCertData = "test="; String oauthToken = "test="; assertThat(masterUrl, is(kubernetesClientConfig.getMaster())); From 805d7c700b8dd3051708bb133eb37315d1120994 Mon Sep 17 00:00:00 2001 From: shinjiro watanabe Date: Mon, 13 Apr 2020 11:52:06 +0900 Subject: [PATCH 6/6] add comment 'ConfigException' --- .../standards/command/kubernetes/KubernetesClientConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java index f6658a3c28..4e926d170b 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/kubernetes/KubernetesClientConfig.java @@ -28,7 +28,7 @@ public static KubernetesClientConfig create(final Optional name, Config extractedSystemConfig = null; if (systemConfig != null && systemConfig.get("agent.command_executor.type", String.class, "").equals("kubernetes")) { if (clusterName == null) { - clusterName = systemConfig.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); + clusterName = systemConfig.get(KUBERNETES_CLIENT_PARAMS_PREFIX + "name", String.class); // ConfigException } final String keyPrefix = KUBERNETES_CLIENT_PARAMS_PREFIX + clusterName + "."; extractedSystemConfig = StorageManager.extractKeyPrefix(systemConfig, keyPrefix); @@ -37,7 +37,7 @@ public static KubernetesClientConfig create(final Optional name, Config extractedRequestConfig = null; if (requestConfig != null && requestConfig.has("kubernetes")) { if (clusterName == null) { - clusterName = requestConfig.get("name", String.class); + clusterName = requestConfig.get("name", String.class); // ConfigException } extractedRequestConfig = requestConfig.getNested("kubernetes"); }