jenkinsci / helm-charts

Jenkins helm charts
https://artifacthub.io/packages/helm/jenkinsci/jenkins
Apache License 2.0
562 stars 890 forks source link

Exclude clouds configuration if it's configured as part of JCasC.configScripts or agent.enabled=false #469

Open oleg-z opened 3 years ago

oleg-z commented 3 years ago

Is your feature request related to a problem? Please describe. Current helm chart assumes kubernetes cloud needs to be configured if deployed on kubernetes. More over cloud is configured even if agent.enabled=false

It may cause issues when additional clouds are required or cloud is configured via different method i.e. via JCasC.configScripts

Describe the solution you'd like Don't configure kubernetes cloud if agent.enabled = false or cloud: is configured as part of JCasC.configScripts (similar to https://github.com/jenkinsci/helm-charts/blob/main/charts/jenkins/templates/_helpers.tpl#L111)

Describe alternatives you've considered While I can configure cloud in a different way default cloud cause issue when using podInheritence inside of pipeline

Additional context

Example of yaml configuration:

controller:
 ...
  JCasC:
    configScripts:
      kubernetes-cloud: |
        jenkins:
          clouds:
            - kubernetes:
               <my kubernetes configuration>
agent:
  enabled: false
arun-var commented 3 years ago

Is there a way to configure additional cloud config using helm chart in addition to default one? If not is it not a bug/limitation?

oleg-z commented 3 years ago

There is a way to configure additional values via JCasC.configScripts but automatically configured cloud could be incorrectly picked up when using inheritFrom functionality of kubernetes plugin.

arun-var commented 3 years ago

@oleg-z What is the workaround, is this documented anywhere? And does the solution require to disable the default kubernetes cloud ?

oleg-z commented 2 years ago

There is no 100% work around for it. I can deploy additional clouds using JCasC.configScripts configuration but default cloud stays configured.

The issue is this empty cloud becomes default cloud if user don't specify cloud for inheritance. See next example:

I have 2 clouds configured on my controller.

User tries to run next code:

  stage("Custom Agent") {
  podTemplate(inheritFrom: "nonprod", containers: [agentPod]) {
  ...
  }

Current kubernetes plugin behavior is to pick first cloud in Jenkins.instance.clouds (https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecution.java#L166). If this first cloud doesn't exist then plugins ignores inheritance and use default cloud settings. As result user gets agent which doesn't have all the settings which are supposed to be there.

Work around is to specify additional property cloud: 'correct-one' in podTemplate.

While this workaround works it creates additional work and forces user to specify cloud name even if only one cloud is functional.

oleg-z commented 2 years ago

Created kubernetes plugin issue as well to resolve non deterministic behavior of plugin: https://issues.jenkins.io/browse/JENKINS-67294

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.