-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,14 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import javax.annotation.CheckForNull; | ||
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; | ||
|
@@ -56,11 +55,14 @@ | |
import hudson.slaves.NodeProvisioner; | ||
import hudson.util.FormValidation; | ||
import hudson.util.ListBoxModel; | ||
import io.fabric8.kubernetes.api.model.ContainerBuilder; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodBuilder; | ||
import io.fabric8.kubernetes.api.model.PodList; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClientException; | ||
import jenkins.model.Jenkins; | ||
import jenkins.model.JenkinsLocationConfiguration; | ||
|
||
/** | ||
* Kubernetes cloud provider. | ||
|
@@ -184,7 +186,6 @@ public String getServerUrl() { | |
|
||
@DataBoundSetter | ||
public void setServerUrl(@Nonnull String serverUrl) { | ||
Preconditions.checkArgument(!StringUtils.isBlank(serverUrl)); | ||
this.serverUrl = serverUrl; | ||
} | ||
|
||
|
@@ -512,16 +513,32 @@ 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"); | ||
|
||
// test creating pods | ||
Pod pod = client.pods().create(new PodBuilder() // | ||
.withNewMetadata().withGenerateName("kubernetes-plugin-").endMetadata() // | ||
.withNewSpec() // | ||
.withContainers( // | ||
new ContainerBuilder().withName("alpine").withImage("alpine").withCommand("cat") | ||
.withTty(true).build()) // | ||
.endSpec().build()); | ||
String podName = pod.getMetadata().getName(); | ||
LOGGER.log(Level.FINE, "Created test pod: {0}/{1}", | ||
new String[] { pod.getMetadata().getNamespace(), podName }); | ||
client.pods().withName(podName).waitUntilReady(30, TimeUnit.SECONDS); | ||
client.pods().withName(podName).delete(); | ||
|
||
return FormValidation.ok("Connection test successful"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really just a "connection test" if we actually create a pod? The button also says "test connection".. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any other suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point 😄 . I would only have stupid suggestions, write "test connection and creating pods" on the button, or remove the "creating pods" check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed pod creation |
||
} 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()); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if no "alpine" image is available.
Jenkins might be running in a closed build environment which does not have access to dockerhub, but only to a private registry with custom images. May happen in an enterprise setting..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should should the correct error in that case