-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow KubectlBuildWrapper to work when k8s API server is behind firewall #599
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -68,13 +68,15 @@ public class KubectlBuildWrapper extends SimpleBuildWrapper { | |
| private final String serverUrl; | ||
| private final String credentialsId; | ||
| private final String caCertificate; | ||
| private final String https_proxy; | ||
|
|
||
| @DataBoundConstructor | ||
| public KubectlBuildWrapper(@Nonnull String serverUrl, @Nonnull String credentialsId, | ||
| @Nonnull String caCertificate) { | ||
| @Nonnull String caCertificate, String https_proxy) { | ||
| this.serverUrl = serverUrl; | ||
| this.credentialsId = credentialsId; | ||
| this.caCertificate = caCertificate; | ||
| this.https_proxy = https_proxy; | ||
| } | ||
|
|
||
| public String getServerUrl() { | ||
|
|
@@ -89,6 +91,10 @@ public String getCaCertificate() { | |
| return caCertificate; | ||
| } | ||
|
|
||
| public String getHttps_proxy() { | ||
| return https_proxy; | ||
| } | ||
|
|
||
| @Override | ||
| public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException { | ||
|
|
||
|
|
@@ -99,6 +105,7 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher | |
| context.setDisposer(new CleanupDisposer(tempFiles)); | ||
|
|
||
| String tlsConfig; | ||
| String kubectlBegin = ""; | ||
| if (caCertificate != null && !caCertificate.isEmpty()) { | ||
| FilePath caCrtFile = workspace.createTempFile("cert-auth", "crt"); | ||
| String ca = caCertificate; | ||
|
|
@@ -113,8 +120,14 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher | |
| tlsConfig = " --insecure-skip-tls-verify=true"; | ||
| } | ||
|
|
||
| if(this.https_proxy != null && !https_proxy.isEmpty()) { | ||
| kubectlBegin += "HTTPS_PROXY="+this.https_proxy+" kubectl config --kubeconfig=\""; | ||
| } else { | ||
| kubectlBegin += "kubectl config --kubeconfig=\""; | ||
| } | ||
|
|
||
| int status = launcher.launch() | ||
| .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() | ||
| .cmdAsSingleString(kubectlBegin + configFile.getRemote() | ||
|
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. Use 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'll see if this way works in my environment and make the change. |
||
| + "\" set-cluster k8s --server=" + serverUrl + tlsConfig) | ||
| .join(); | ||
| if (status != 0) throw new IOException("Failed to run kubectl config "+status); | ||
|
|
@@ -174,18 +187,18 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher | |
| } | ||
|
|
||
| status = launcher.launch() | ||
| .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() + "\" set-credentials cluster-admin " + login) | ||
| .cmdAsSingleString(kubectlBegin + configFile.getRemote() + "\" set-credentials cluster-admin " + login) | ||
| .masks(false, false, false, false, false, false, true) | ||
| .join(); | ||
| if (status != 0) throw new IOException("Failed to run kubectl config "+status); | ||
|
|
||
| status = launcher.launch() | ||
| .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() + "\" set-context k8s --cluster=k8s --user=cluster-admin") | ||
| .cmdAsSingleString(kubectlBegin + configFile.getRemote() + "\" set-context k8s --cluster=k8s --user=cluster-admin") | ||
| .join(); | ||
| if (status != 0) throw new IOException("Failed to run kubectl config "+status); | ||
|
|
||
| status = launcher.launch() | ||
| .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() + "\" use-context k8s") | ||
| .cmdAsSingleString(kubectlBegin + configFile.getRemote() + "\" use-context k8s") | ||
| .join(); | ||
| if (status != 0) throw new IOException("Failed to run kubectl config "+status); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div> | ||
| Use proxy when kubernetes api server is behind the firewall. | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div> | ||
| Use proxy when kubernetes api server is behind the firewall. | ||
| </div> |
Uh oh!
There was an error while loading. Please reload this page.