- 
                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?
Conversation
         Wilkhu90
  
      
      
      commented
      
            Wilkhu90
  
      
      
      commented
        Sep 19, 2019 
      
    
  
- Adding changes to accommodate to situation when k8s API server is behind firewall.
- This will run kubectl commands using proxy when the value is set and ignore it otherwise.
…is behind firewall
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.
Needs a minimal test ensuring that the https proxy is injected in the kubernetes client configuration. Not sure how the build wrapper change can be tested.
        
          
                src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubectlBuildWrapper.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      |  | ||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Use launcher.launch().envs("HTTPS_PROXY="+this.https_proxy).cmdAsSingleString... (possibly refactor it to a method to avoid repeating 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.
I'll see if this way works in my environment and make the change.
        
          
                src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud/config.jelly
              
                Outdated
          
            Show resolved
            Hide resolved
        
      |  | ||
| int status = launcher.launch() | ||
| .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() | ||
| kubectlBegin += "kubectl config --kubeconfig=\""; | 
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.
Can you inline it so that the diff is minimal?
| .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() | ||
| kubectlBegin += "kubectl config --kubeconfig=\""; | ||
|  | ||
| int status = launcher.launch().envs("HTTPS_PROXY="+this.httpsProxy) | 
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.
Refactor launcher.launch().envs("HTTPS_PROXY="+this.httpsProxy) to a method to remove duplicates. Also, it should handle null httpsProxy.
| builder.withMaxConcurrentRequestsPerHost(maxRequestsPerHost); | ||
|  | ||
| if(httpsProxy != null && !httpsProxy.isEmpty()) { | ||
| LOGGER.info("Https Proxy used is " + httpsProxy); | 
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.
Use level fine or even remove it (this is trivial)
| this.connectTimeout = connectTimeout; | ||
| this.readTimeout = readTimeout; | ||
| this.maxRequestsPerHost = maxRequestsPerHost; | ||
| this.httpsProxy = httpsProxy != null && !httpsProxy.isEmpty() ? httpsProxy : null; | 
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.
Let KubernetesCloud do the validation
|  | ||
| @DataBoundSetter | ||
| public void setHttpsProxy(@Nonnull String httpsProxy) { | ||
| this.httpsProxy = httpsProxy; | 
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.httpsProxy = httpsProxy; | |
| this.httpsProxy = Util.fixEmpty(httpsProxy); | 
| return FormValidation.error("name is required"); | ||
|  | ||
| try (KubernetesClient client = new KubernetesFactoryAdapter(serverUrl, namespace, | ||
| try (KubernetesClient client = new KubernetesFactoryAdapter(serverUrl, httpsProxy, namespace, | 
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.
| try (KubernetesClient client = new KubernetesFactoryAdapter(serverUrl, httpsProxy, namespace, | |
| try (KubernetesClient client = new KubernetesFactoryAdapter(serverUrl, Util.fixEmpty(httpsProxy), namespace, | 
| builder = builder.withRequestTimeout(readTimeout * 1000).withConnectionTimeout(connectTimeout * 1000); | ||
| builder.withMaxConcurrentRequestsPerHost(maxRequestsPerHost); | ||
|  | ||
| if(httpsProxy != null && !httpsProxy.isEmpty()) { | 
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.
| if(httpsProxy != null && !httpsProxy.isEmpty()) { | |
| if(httpsProxy != null) { | 
It's already checked above