Skip to content

Commit 4303ec3

Browse files
authored
Merge pull request #234 from jenkinsci/default-namespace
If namespace is not provided nor autoconfigured should use default
2 parents a2c450e + 16087b1 commit 4303ec3

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import javax.annotation.Nonnull;
2424
import javax.servlet.ServletException;
2525

26-
import hudson.model.Environment;
27-
import jenkins.model.JenkinsLocationConfiguration;
2826
import org.apache.commons.codec.binary.Base64;
2927
import org.apache.commons.lang.StringUtils;
3028
import org.kohsuke.stapler.DataBoundConstructor;
@@ -61,6 +59,7 @@
6159
import io.fabric8.kubernetes.client.KubernetesClient;
6260
import io.fabric8.kubernetes.client.KubernetesClientException;
6361
import jenkins.model.Jenkins;
62+
import jenkins.model.JenkinsLocationConfiguration;
6463

6564
/**
6665
* Kubernetes cloud provider.
@@ -184,7 +183,6 @@ public String getServerUrl() {
184183

185184
@DataBoundSetter
186185
public void setServerUrl(@Nonnull String serverUrl) {
187-
Preconditions.checkArgument(!StringUtils.isBlank(serverUrl));
188186
this.serverUrl = serverUrl;
189187
}
190188

@@ -512,16 +510,17 @@ public FormValidation doTestConnection(@QueryParameter String name, @QueryParame
512510
Util.fixEmpty(serverCertificate), Util.fixEmpty(credentialsId), skipTlsVerify,
513511
connectionTimeout, readTimeout).createClient();
514512

513+
// test listing pods
515514
client.pods().list();
516-
return FormValidation.ok("Connection successful");
515+
return FormValidation.ok("Connection test successful");
517516
} catch (KubernetesClientException e) {
518-
LOGGER.log(Level.FINE, String.format("Error connecting to %s", serverUrl), e);
519-
return FormValidation.error("Error connecting to %s: %s", serverUrl, e.getCause() == null
517+
LOGGER.log(Level.FINE, String.format("Error testing connection %s", serverUrl), e);
518+
return FormValidation.error("Error testing connection %s: %s", serverUrl, e.getCause() == null
520519
? e.getMessage()
521520
: String.format("%s: %s", e.getCause().getClass().getName(), e.getCause().getMessage()));
522521
} catch (Exception e) {
523-
LOGGER.log(Level.FINE, String.format("Error connecting to %s", serverUrl), e);
524-
return FormValidation.error("Error connecting to %s: %s", serverUrl, e.getMessage());
522+
LOGGER.log(Level.FINE, String.format("Error testing connection %s", serverUrl), e);
523+
return FormValidation.error("Error testing connection %s: %s", serverUrl, e.getMessage());
525524
}
526525
}
527526

src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesFactoryAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public KubernetesFactoryAdapter(String serviceAddress, String namespace, @CheckF
7575
public KubernetesFactoryAdapter(String serviceAddress, String namespace, @CheckForNull String caCertData,
7676
@CheckForNull String credentials, boolean skipTlsVerify, int connectTimeout, int readTimeout, int maxRequestsPerHost) {
7777
this.serviceAddress = serviceAddress;
78-
this.namespace = namespace;
78+
this.namespace = StringUtils.isBlank(namespace) ? "default" : namespace;
7979
this.caCertData = caCertData;
8080
this.credentials = credentials != null ? getCredentials(credentials) : null;
8181
this.skipTlsVerify = skipTlsVerify;

0 commit comments

Comments
 (0)