Skip to content

Commit

Permalink
fix(master): pass lifecycle configuration to master container (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
DionJones615 authored Nov 22, 2024
1 parent a4fa09b commit d919a2a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v1alpha2/jenkins_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ type JenkinsMaster struct {
// periodSeconds: 10
// successThreshold: 1
// timeoutSeconds: 5
// lifecycle: {}
// name: jenkins-master
// readinessProbe:
// failureThreshold: 3
Expand Down
3 changes: 3 additions & 0 deletions chart/jenkins-operator/templates/jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ spec:
{{- with .Values.jenkins.env }}
env: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.jenkins.lifecycle}}
lifecycle: {{ toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.jenkins.volumeMounts }}
volumeMounts: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions chart/jenkins-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jenkins:
# imagePullPolicy defines policy for pulling images
imagePullPolicy: Always

# lifecycle is used if you want to specify lifecycle hooks for the master container
lifecycle: {}

# priorityClassName indicates the importance of a Pod relative to other Pods
# See: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/
priorityClassName: ""
Expand Down
5 changes: 5 additions & 0 deletions controllers/jenkins_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ func (r *JenkinsReconciler) setDefaults(jenkins *v1alpha2.Jenkins) (requeue bool
changed = true
jenkinsContainer.LivenessProbe = resources.NewProbe(containerProbeURI, containerProbePortName, corev1.URISchemeHTTP, 80, 5, 12)
}
if jenkinsContainer.Lifecycle == nil {
logger.Info("Setting default Jenkins lifecycle")
changed = true
jenkinsContainer.Lifecycle = &corev1.Lifecycle{}
}
if len(jenkinsContainer.Command) == 0 {
logger.Info("Setting default Jenkins container command")
changed = true
Expand Down
1 change: 1 addition & 0 deletions pkg/configuration/base/resources/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func NewJenkinsMasterContainer(jenkins *v1alpha2.Jenkins) corev1.Container {
Image: jenkinsContainer.Image,
ImagePullPolicy: jenkinsContainer.ImagePullPolicy,
Command: jenkinsContainer.Command,
Lifecycle: jenkinsContainer.Lifecycle,
LivenessProbe: jenkinsContainer.LivenessProbe,
ReadinessProbe: jenkinsContainer.ReadinessProbe,
Ports: []corev1.ContainerPort{
Expand Down
10 changes: 10 additions & 0 deletions test/bats/2-deploy-with-more-options.bats
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ setup() {
--set jenkins.nodeSelector.batstest=yep \
--set jenkins.image="jenkins/jenkins:2.462.3-lts" \
--set jenkins.imagePullPolicy="IfNotPresent" \
--set jenkins.lifecycle.preStop.command='["echo bats test"]' \
--set jenkins.backup.makeBackupBeforePodDeletion=false \
--set jenkins.backup.image=quay.io/jenkins-kubernetes-operator/backup-pvc:e2e-test \
chart/jenkins-operator --wait
Expand Down Expand Up @@ -137,6 +138,15 @@ setup() {
assert_success
}

#bats test_tags=phase:helm,scenario:more-options
@test "2.5 Helm: check lifecycle" {
[[ ! -f "chart/jenkins-operator/deploy.tmp" ]] && skip "Jenkins helm chart have not been deployed correctly"

run ${KUBECTL} get pod jenkins-jenkins -o jsonpath={.spec.containers[0].lifecycle.preStop.exec.command[0]}
assert_success
assert_output "echo 'bats test'"
}

#bats test_tags=phase:helm,scenario:more-options
@test "2.12 Helm: check node selector again" {
[[ ! -f "chart/jenkins-operator/deploy.tmp" ]] && skip "Jenkins helm chart have not been deployed correctly"
Expand Down

0 comments on commit d919a2a

Please sign in to comment.