From 0a4787e3bbb98315b71448d941b57c38ce4840eb Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Tue, 6 Aug 2024 12:05:46 +0530 Subject: [PATCH] fix: ClusterConfiguration.getConfig should also set namespace in current context Related to failures in #3304 ClusterConfiguration `getConfig()` method converts ClusterConfiguration to a KubernetesClient Config object. It should also set namespace in current context while setting current context in Config. Signed-off-by: Rohan Kumar --- .../jkube/kit/common/access/ClusterConfiguration.java | 3 +++ .../jkube/kit/common/access/ClusterConfigurationTest.java | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/access/ClusterConfiguration.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/access/ClusterConfiguration.java index 48282a3e5c..100f01bdc2 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/access/ClusterConfiguration.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/access/ClusterConfiguration.java @@ -143,6 +143,9 @@ public Config getConfig() { if (StringUtils.isNotBlank(this.currentContext)) { configBuilder.withCurrentContext(new NamedContextBuilder() .withName(this.currentContext) + .withNewContext() + .withNamespace(getNamespace()) + .endContext() .build()); } diff --git a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/access/ClusterConfigurationTest.java b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/access/ClusterConfigurationTest.java index c6e68368c0..dff98475eb 100644 --- a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/access/ClusterConfigurationTest.java +++ b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/access/ClusterConfigurationTest.java @@ -30,6 +30,7 @@ void should_load_configuration_from_properties() { final Properties properties = new Properties(); properties.put("jkube.username", "user name"); properties.put("jkube.password", "the pa$$w*rd"); + properties.put("jkube.namespace", "myns1"); properties.put("jkube.masterUrl", "https://example.com"); properties.put("jkube.corner-case", "corner"); properties.put("jkube.currentContext", "ctx1"); @@ -40,7 +41,9 @@ void should_load_configuration_from_properties() { assertThat(config).isNotNull() .hasFieldOrPropertyWithValue("username", "user name") .hasFieldOrPropertyWithValue("password", "the pa$$w*rd") - .hasFieldOrPropertyWithValue("currentContext", new NamedContextBuilder().withName("ctx1").build()) + .hasFieldOrPropertyWithValue("namespace", "myns1") + .hasFieldOrPropertyWithValue("currentContext.name", "ctx1") + .hasFieldOrPropertyWithValue("currentContext.context.namespace", "myns1") .hasFieldOrPropertyWithValue("masterUrl", "https://example.com/"); } @@ -130,7 +133,7 @@ void loadsConfigurationFromKubernetesConfig() { .hasFieldOrPropertyWithValue("clientKeyData", "clientKeyData") .hasFieldOrPropertyWithValue("clientKeyAlgo", "clientKeyAlgo") .hasFieldOrPropertyWithValue("clientKeyPassphrase", "clientKeyPassphrase") - .hasFieldOrPropertyWithValue("currentContext", new NamedContextBuilder().withName("ctx1").build()) + .hasFieldOrPropertyWithValue("currentContext", new NamedContextBuilder().withName("ctx1").withNewContext().withNamespace("namespace").endContext().build()) .hasFieldOrPropertyWithValue("trustStoreFile", "trustStoreFile") .hasFieldOrPropertyWithValue("trustStorePassphrase", "trustStorePassphrase") .hasFieldOrPropertyWithValue("keyStoreFile", "keyStoreFile")