Skip to content

Commit

Permalink
feat: expose jenkins master terminationGracePeriodSeconds (#1012)
Browse files Browse the repository at this point in the history
Co-authored-by: brokenpip3 <[email protected]>
  • Loading branch information
DionJones615 and brokenpip3 authored Jun 11, 2024
1 parent 061995a commit 18197e6
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 11 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha2/jenkins_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ type JenkinsMaster struct {
// HostAliases for Jenkins master pod and SeedJob agent
// +optional
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`

// The grace period is the duration in seconds after the processes running in the pod are sent
// a termination signal and the time when the processes are forcibly halted with a kill signal.
// Set this value longer than the expected cleanup time for your process.
// Defaults to 30 seconds.
// +optional
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
}

// Service defines Kubernetes service attributes
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chart/jenkins-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Kubernetes native operator which fully manages Jenkins on Kubernetes
| jenkins.seedJobAgentImage | string | `""` | |
| jenkins.seedJobs | list | `[]` | |
| jenkins.serviceAccount.annotations | object | `{}` | |
| jenkins.terminationGracePeriodSeconds | int | `30` | |
| jenkins.tolerations | list | `[]` | |
| jenkins.validateSecurityWarnings | bool | `false` | |
| jenkins.volumeMounts | list | `[]` | |
Expand Down
4 changes: 4 additions & 0 deletions chart/jenkins-operator/crds/jenkins-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,10 @@ spec:
type: string
type: object
type: object
terminationGracePeriodSeconds:
description: 'Optional duration in seconds the pod needs to terminate gracefully.'
type: integer
default: 30
tolerations:
description: If specified, the pod's tolerations.
items:
Expand Down
5 changes: 4 additions & 1 deletion chart/jenkins-operator/templates/jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ spec:
{{- with .Values.jenkins.hostAliases }}
hostAliases: {{ toYaml . | nindent 4 }}
{{- end }}
{{- if .Values.jenkins.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.jenkins.terminationGracePeriodSeconds }}
{{- end }}
containers:
- name: jenkins-master
image: {{ .Values.jenkins.image }}
Expand All @@ -137,7 +140,7 @@ spec:
{{- if .Values.jenkins.backup.enabled }}
- name: {{ .Values.jenkins.backup.containerName }}
image: {{ .Values.jenkins.backup.image }}
imagePullPolicy: {{ .Values.jenkins.imagePullPolicy }}
imagePullPolicy: {{ .Values.jenkins.imagePullPolicy }}
{{- with .Values.jenkins.backup.resources }}
resources: {{ toYaml . | nindent 10 }}
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions chart/jenkins-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ jenkins:
# - "foo.remote"
# - "bar.remote"

# Optional duration in seconds the pod needs to terminate gracefully.
# Default 30sec
terminationGracePeriodSeconds: 30

# validateSecurityWarnings enables or disables validating potential security warnings in Jenkins plugins via admission webhooks.
validateSecurityWarnings: false

Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/jenkins.io_jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,14 @@ spec:
type: string
type: object
type: object
terminationGracePeriodSeconds:
description: The grace period is the duration in seconds after
the processes running in the pod are sent a termination signal
and the time when the processes are forcibly halted with a kill
signal. Set this value longer than the expected cleanup time
for your process. Defaults to 30 seconds.
format: int64
type: integer
tolerations:
description: If specified, the pod's tolerations.
items:
Expand Down
26 changes: 16 additions & 10 deletions pkg/configuration/base/resources/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,26 @@ func NewJenkinsMasterPod(objectMeta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins
objectMeta.Name = GetJenkinsMasterPodName(jenkins)
objectMeta.Labels = GetJenkinsMasterPodLabels(*jenkins)

if jenkins.Spec.Master.TerminationGracePeriodSeconds == nil {
defaultGracePeriod := constants.DefaultTerminationGracePeriodSeconds
jenkins.Spec.Master.TerminationGracePeriodSeconds = &defaultGracePeriod
}

return &corev1.Pod{
TypeMeta: buildPodTypeMeta(),
ObjectMeta: objectMeta,
Spec: corev1.PodSpec{
ServiceAccountName: serviceAccountName,
RestartPolicy: corev1.RestartPolicyNever,
NodeSelector: jenkins.Spec.Master.NodeSelector,
Containers: newContainers(jenkins),
Volumes: append(GetJenkinsMasterPodBaseVolumes(jenkins), jenkins.Spec.Master.Volumes...),
SecurityContext: jenkins.Spec.Master.SecurityContext,
ImagePullSecrets: jenkins.Spec.Master.ImagePullSecrets,
Tolerations: jenkins.Spec.Master.Tolerations,
PriorityClassName: jenkins.Spec.Master.PriorityClassName,
HostAliases: jenkins.Spec.Master.HostAliases,
ServiceAccountName: serviceAccountName,
RestartPolicy: corev1.RestartPolicyNever,
NodeSelector: jenkins.Spec.Master.NodeSelector,
Containers: newContainers(jenkins),
Volumes: append(GetJenkinsMasterPodBaseVolumes(jenkins), jenkins.Spec.Master.Volumes...),
SecurityContext: jenkins.Spec.Master.SecurityContext,
ImagePullSecrets: jenkins.Spec.Master.ImagePullSecrets,
Tolerations: jenkins.Spec.Master.Tolerations,
PriorityClassName: jenkins.Spec.Master.PriorityClassName,
HostAliases: jenkins.Spec.Master.HostAliases,
TerminationGracePeriodSeconds: jenkins.Spec.Master.TerminationGracePeriodSeconds,
},
}
}
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ const (
DefaultSlavePortInt32 = int32(50000)
// JavaOpsVariableName is the name of environment variable which consists Jenkins Java options
JavaOpsVariableName = "JAVA_OPTS"
// DefaultTerminationGracePeriodSeconds is the default pod termination period second
DefaultTerminationGracePeriodSeconds = int64(30)
)
3 changes: 3 additions & 0 deletions test/e2e/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func verifyJenkinsMasterPodAttributes(jenkins *v1alpha2.Jenkins) {
jenkinsPod := getJenkinsMasterPod(jenkins)
jenkins = getJenkins(jenkins.Namespace, jenkins.Name)

defaultGracePeriod := constants.DefaultTerminationGracePeriodSeconds

assertMapContainsElementsFromAnotherMap(jenkins.Spec.Master.Annotations, jenkinsPod.ObjectMeta.Annotations)
Expect(jenkinsPod.Spec.NodeSelector).Should(Equal(jenkins.Spec.Master.NodeSelector))

Expand All @@ -125,6 +127,7 @@ func verifyJenkinsMasterPodAttributes(jenkins *v1alpha2.Jenkins) {

Expect(jenkinsPod.Labels).Should(Equal(resources.GetJenkinsMasterPodLabels(*jenkins)))
Expect(jenkinsPod.Spec.PriorityClassName).Should(Equal(jenkins.Spec.Master.PriorityClassName))
Expect(jenkinsPod.Spec.TerminationGracePeriodSeconds).Should(Equal(&defaultGracePeriod))

for _, actualContainer := range jenkinsPod.Spec.Containers {
if actualContainer.Name == resources.JenkinsMasterContainerName {
Expand Down

0 comments on commit 18197e6

Please sign in to comment.