Skip to content

Commit

Permalink
Merge pull request #234 from jenkinsci/default-namespace
Browse files Browse the repository at this point in the history
If namespace is not provided nor autoconfigured should use default
  • Loading branch information
marvinthepa authored Oct 31, 2017
2 parents a2c450e + 16087b1 commit 4303ec3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import javax.annotation.Nonnull;
import javax.servlet.ServletException;

import hudson.model.Environment;
import jenkins.model.JenkinsLocationConfiguration;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -61,6 +59,7 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;

/**
* Kubernetes cloud provider.
Expand Down Expand Up @@ -184,7 +183,6 @@ public String getServerUrl() {

@DataBoundSetter
public void setServerUrl(@Nonnull String serverUrl) {
Preconditions.checkArgument(!StringUtils.isBlank(serverUrl));
this.serverUrl = serverUrl;
}

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

// test listing pods
client.pods().list();
return FormValidation.ok("Connection successful");
return FormValidation.ok("Connection test successful");
} catch (KubernetesClientException e) {
LOGGER.log(Level.FINE, String.format("Error connecting to %s", serverUrl), e);
return FormValidation.error("Error connecting to %s: %s", serverUrl, e.getCause() == null
LOGGER.log(Level.FINE, String.format("Error testing connection %s", serverUrl), e);
return FormValidation.error("Error testing connection %s: %s", serverUrl, e.getCause() == null
? e.getMessage()
: String.format("%s: %s", e.getCause().getClass().getName(), e.getCause().getMessage()));
} catch (Exception e) {
LOGGER.log(Level.FINE, String.format("Error connecting to %s", serverUrl), e);
return FormValidation.error("Error connecting to %s: %s", serverUrl, e.getMessage());
LOGGER.log(Level.FINE, String.format("Error testing connection %s", serverUrl), e);
return FormValidation.error("Error testing connection %s: %s", serverUrl, e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public KubernetesFactoryAdapter(String serviceAddress, String namespace, @CheckF
public KubernetesFactoryAdapter(String serviceAddress, String namespace, @CheckForNull String caCertData,
@CheckForNull String credentials, boolean skipTlsVerify, int connectTimeout, int readTimeout, int maxRequestsPerHost) {
this.serviceAddress = serviceAddress;
this.namespace = namespace;
this.namespace = StringUtils.isBlank(namespace) ? "default" : namespace;
this.caCertData = caCertData;
this.credentials = credentials != null ? getCredentials(credentials) : null;
this.skipTlsVerify = skipTlsVerify;
Expand Down

0 comments on commit 4303ec3

Please sign in to comment.