-
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
Autoconfigure cloud if kubernetes url is not set #208
Changes from 6 commits
f27a66c
40d452f
e2453e9
d215a3a
9ba778e
9902745
2dc5b2d
33485ce
4df0d9f
05c77be
dd441f6
b94db44
6f79c33
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 |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
import java.security.cert.CertificateEncodingException; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Collections; | ||
import java.util.logging.Level; | ||
import static java.util.logging.Level.*; | ||
import java.util.logging.Logger; | ||
|
||
import javax.annotation.CheckForNull; | ||
|
@@ -29,6 +29,7 @@ | |
|
||
import hudson.security.ACL; | ||
import hudson.util.Secret; | ||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.ConfigBuilder; | ||
import io.fabric8.kubernetes.client.DefaultKubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
|
@@ -93,9 +94,21 @@ private StandardCredentials getCredentials(String credentials) { | |
|
||
public KubernetesClient createClient() throws NoSuchAlgorithmException, UnrecoverableKeyException, | ||
KeyStoreException, IOException, CertificateEncodingException { | ||
ConfigBuilder builder = new ConfigBuilder().withMasterUrl(serviceAddress) | ||
.withRequestTimeout(readTimeout * 1000) | ||
.withConnectionTimeout(connectTimeout * 1000); | ||
|
||
ConfigBuilder builder; | ||
// autoconfigure if url is not set | ||
if (StringUtils.isBlank(serviceAddress)) { | ||
LOGGER.log(FINE, "Autoconfiguring Kubernetes client"); | ||
builder = new ConfigBuilder(Config.autoConfigure()); | ||
} else { | ||
// although this will still autoconfigure based on Config constructor notes | ||
// In future releases (2.4.x) the public constructor will be empty. | ||
// The current functionality will be provided by autoConfigure(). | ||
// This is a necessary change to allow us distinguish between auto configured values and builder values. | ||
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. I have to admit that I don't fully understand this comment. I guess it means that by 2.4.x, this
Will behave differently, i.e. if we move the dependency to 2.4.x we will either introduce a breaking change, or we will have to change that line again? 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.
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. But this will still cause a breaking change if somebody changes the client library to 2.4 and doesn't update this code here, right?
Is that intended? 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. yes, it may be a breaking change to document. Better than the current behavior because your jenkins settings may be ignored 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.
Right, I remember we had that problem as well. The only remaining downside that remains is that as of now, you can't have autoconfigure AND overwrite the kubernetes URL, like it used to work. One solution for this would be to add a checkbox for autoconfigure to make it explicit... |
||
builder = new ConfigBuilder().withMasterUrl(serviceAddress); | ||
} | ||
|
||
builder = builder.withRequestTimeout(readTimeout * 1000).withConnectionTimeout(connectTimeout * 1000); | ||
|
||
if (!StringUtils.isBlank(namespace)) { | ||
builder.withNamespace(namespace); | ||
|
@@ -128,7 +141,7 @@ public KubernetesClient createClient() throws NoSuchAlgorithmException, Unrecove | |
} | ||
builder.withMaxConcurrentRequestsPerHost(maxRequestsPerHost); | ||
|
||
LOGGER.log(Level.FINE, "Creating Kubernetes client: {0}", this.toString()); | ||
LOGGER.log(FINE, "Creating Kubernetes client: {0}", this.toString()); | ||
return new DefaultKubernetesClient(builder.build()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
pipeline { | ||
agent { | ||
kubernetes { | ||
cloud 'kubernetes-plugin-test' | ||
label 'mypod' | ||
containerTemplate { | ||
name 'maven' | ||
|
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.
I guess that comment was changed by an automated IDE refactoring.
What was that comment for in the first place? Can we remove it?
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.
no, it's just that now the cloud is the default
kubernetes
one