Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If namespace is not provided nor autoconfigured should use default #234

Merged
merged 3 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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