jenkinsci / kubernetes-operator

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

JenkinsMaster container configuration does not receive Lifecycle configuration set in CRD #1059

Open DionJones615 opened 2 months ago

DionJones615 commented 2 months ago

Describe the bug When setting a Lifecycle configuration for the JenkinsMaster container in the Jenkins CRD, it does not have any effect.

To Reproduce

  1. Set a Lifecycle configuration for the JenkinsMaster container such as:

    [...]
    spec:
    master:
    containers:
    - name: jenkins-master
      lifecycle:
        preStop:
          exec:
            command:
              - "/bin/bash"
              - "-c"
              - |-
                _log() {
                    local level="$1"
                    local message="$2"
                    local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
                    if [[ "$level" =~ ^(ERROR|ERR|error|err)$ ]]; then
                        echo "${timestamp} - ${level} - ${message}" > /proc/1/fd/2
                    fi
                    echo "${timestamp} - ${level} - ${message}" > /proc/1/fd/1
                }
    
                NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
                TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
                CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
    
                while [[ ! "$(curl -s --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_PORT_443_TCP_PORT}/api/v1/namespaces/$NAMESPACE/pods/$HOSTNAME | sed -n '/"name": "backup"/,/}/p' | grep terminated)" ]]; do
                    _log "INFO" "[preStop] Waiting for backup container to terminate..."
                    sleep 5
                }
    [...]
  2. Observe that the resulting Jenkins pod configuration does not include this lifecycle configuration

Additional information

It appears that the Lifecycle is not passed to the container config here. However, I suspect reconciliation probably needs an update as well

Jenkins Operator version: 0.8.0

brokenpip3 commented 1 month ago

Yep indeed is not passed, do you mind create a PR? it should be easy, we just need the changes in pod.go (with handling of default empty) and helm chart values/template.