Skip to content

Commit 9ee5ac6

Browse files
mike-dubmandpressle
authored andcommitted
Matrix: avoid overriding existing k8s cloud namespace
1 parent fcea5e6 commit 9ee5ac6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/com/mellanox/cicd/Matrix.groovy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ def ensureK8sCloud(cloudName, namespace = "default") {
862862
def cl = j.pluginManager.uberClassLoader
863863
def k8sCloudClass = cl.loadClass("org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud")
864864
def cloud = j.clouds.getByName(cloudName)
865+
def cloudCreated = false
865866

866867
if (cloud != null && !k8sCloudClass.isInstance(cloud)) {
867868
j.clouds.remove(cloud)
@@ -871,6 +872,7 @@ def ensureK8sCloud(cloudName, namespace = "default") {
871872
if (cloud == null) {
872873
cloud = k8sCloudClass.getConstructor(String).newInstance(cloudName)
873874
j.clouds.add(cloud)
875+
cloudCreated = true
874876
}
875877

876878
// Only set serverUrl when JENKINS_K8S_API_URL is set; otherwise preserve existing (e.g. from
@@ -882,7 +884,12 @@ def ensureK8sCloud(cloudName, namespace = "default") {
882884
cloud.serverUrl = apiUrl
883885
}
884886
cloud.skipTlsVerify = true
885-
cloud.namespace = namespace ?: "default"
887+
// Do not overwrite namespace on existing shared clouds unless explicitly requested.
888+
def namespaceEnv = System.getenv("JENKINS_K8S_NAMESPACE")?.trim()
889+
def desiredNamespace = namespaceEnv ?: namespace ?: "default"
890+
if (namespaceEnv || cloudCreated || !cloud.namespace) {
891+
cloud.namespace = desiredNamespace
892+
}
886893
def jenkinsUrlEnv = System.getenv("JENKINS_URL")?.trim()
887894
if (jenkinsUrlEnv) {
888895
cloud.jenkinsUrl = jenkinsUrlEnv

0 commit comments

Comments
 (0)