jenkinsci / kubernetes-operator

Kubernetes native Jenkins Operator
https://jenkinsci.github.io/kubernetes-operator
Other
596 stars 233 forks source link

JCASC Merge of lists from different files is not working. #898

Closed lhupfeldt closed 6 months ago

lhupfeldt commented 11 months ago

We are having an issue with casc files not being merged the same way they are on a non kubernetes/operator setup.

Given the following configmap (unrelated parts removed):

apiVersion: v1
data:
  1-jcasc-pipeline-library.yml: |
    ---
    unclassified:
      globalLibraries:
        libraries:
        - defaultVersion: "main"
          includeInChangesets: false
          name: pipeline-library-1"
          retriever:
            modernSCM:
              scm:
                github:
                  configuredByUrl: true
                  credentialsId: "stdc.github.userpass"
                  repoOwner: "devops"
                  repository: "pipeline-library-1"
                  repositoryUrl: "https://somewhere/devops/pipeline-library-1.git"
                  traits:
                  - gitHubBranchDiscovery:
                      strategyId: 1
                  - gitHubPullRequestDiscovery:
                      strategyId: 1
                  - gitHubForkDiscovery:
                      strategyId: 1
                      trust: "gitHubTrustPermissions"
  2-jcasc-pipeline-library.yml: |
    ---
    unclassified:
      globalLibraries:
        libraries:
        - defaultVersion: "main"
          includeInChangesets: false
          name: pipeline-library-2"
          retriever:
            modernSCM:
              scm:
                github:
                  configuredByUrl: true
                  credentialsId: "stdc.github.userpass"
                  repoOwner: "devops"
                  repository: "pipeline-library-2"
                  repositoryUrl: "https://somewhere/devops/pipeline-library-2.git"
                  traits:
                  - gitHubBranchDiscovery:
                      strategyId: 1
                  - gitHubPullRequestDiscovery:
                      strategyId: 1
                  - gitHubForkDiscovery:
                      strategyId: 1
                      trust: "gitHubTrustPermissions"    
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: jenkins-operator-user-configuration

What we see is: Only a single library is defined in Jenkins. The second library casc file overwrites the first one. There are no errors logged from the casc file processing.

Kubernetes version: v1.24.15+rke2r1 Jenkins Operator version: v0.8.0-beta2

With the lirary definitions in separate casc files on non-kubernete Jenkins both libraries will be defined. I.e. The (one element) list in the second file is appended to the list from the first file.

Can you explain how the casc processing is done with the operator? I see that the log output is in the operator log, not the Jenkins log as I would have expected. I would have expected that the configmap files were mounted in the Jenkins container, but that does not seem to be the case.

brokenpip3 commented 8 months ago

I never tried that, can I ask you the use case of having 2 different casc config?

lhupfeldt commented 8 months ago

Sorry for the delay. The use case is basically "separation of concerns". We have two pipeline libraries, each having it's own piece of configuration. But I think the main point is that jcasc setup supported by plain Jenkins should be supported with the operator. It seems the operator does it't own handling of the jcasc. I'm curious why it does not simply mount the configmap in the jenkins namespace and ask jenkins to do the load?

brokenpip3 commented 6 months ago

It seems the operator does it't own handling of the jcasc. I'm curious why it does not simply mount the configmap in the jenkins namespace and ask jenkins to do the load?

Because afaik if you change the casc in the configmap jenkins will read it only when it start the process. The operator is constantly trying to update the CASC that you have as code in your git repo, this will let "live" changes of the CASC (obv you can do it manually from the webui in a imperative way).

Honestly I don't think that supporting a separated casc is a priority or something we need atm, sorry

brokenpip3 commented 6 months ago

(but I'm open to review any PRs that will address that!)