diff --git a/.github/workflows/auto-codespell.yml b/.github/workflows/auto-codespell.yml deleted file mode 100644 index b8f8d4c4..00000000 --- a/.github/workflows/auto-codespell.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: CI Lint -on: - push: - branches: - - master - - main - pull_request: - types: [opened, synchronize, ready_for_review, reopened] -jobs: - codespell: - name: Codespell - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Codespell - uses: codespell-project/actions-codespell@v2 - with: - check_filenames: true - ignore_words_list: aks,ags,startin,NotIn - skip: "*.js,package-lock.json,*.lock,*/Font-Awesome/*,*.toml,*.svg,*assets/vendor/bootstrap*,cert-manager.crds.yaml,*/docs/*,go.sum" - pre-commit: - name: PreCommit - runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v5.1.0 - - uses: DeterminateSystems/nix-installer-action@v12 - with: - diagnostic-endpoint: "" - - uses: DeterminateSystems/magic-nix-cache-action@v7 - with: - diagnostic-endpoint: "" - - name: Checkout - uses: actions/checkout@v4 - - id: files - uses: tj-actions/changed-files@v44 - - name: nix checks - run: nix flake check - - name: nix pre-commit - run: nix develop . --command pre-commit run --files ${{ steps.files.outputs.all_changed_files }} --show-diff-on-failure diff --git a/.github/workflows/auto-gen-docs.yaml b/.github/workflows/auto-gen-docs.yaml index e88ba259..283f013a 100644 --- a/.github/workflows/auto-gen-docs.yaml +++ b/.github/workflows/auto-gen-docs.yaml @@ -33,7 +33,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'pull_request' || (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') steps: - - uses: DeterminateSystems/nix-installer-action@v12 + - uses: DeterminateSystems/nix-installer-action@v13 with: diagnostic-endpoint: "" - uses: DeterminateSystems/magic-nix-cache-action@v7 @@ -68,7 +68,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'pull_request' || (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') steps: - - uses: DeterminateSystems/nix-installer-action@v12 + - uses: DeterminateSystems/nix-installer-action@v13 with: diagnostic-endpoint: "" - uses: DeterminateSystems/magic-nix-cache-action@v7 diff --git a/api/v1alpha2/jenkins_types.go b/api/v1alpha2/jenkins_types.go index 7ffed5a8..4b9f95ce 100644 --- a/api/v1alpha2/jenkins_types.go +++ b/api/v1alpha2/jenkins_types.go @@ -14,7 +14,7 @@ type JenkinsSpec struct { Master JenkinsMaster `json:"master"` // SeedJobs defines list of Jenkins Seed Job configurations - // More info: https://jenkinsci.github.io/kubernetes-operator/docs/getting-started/latest/configuration#configure-seed-jobs-and-pipelines + // More info: https://jenkinsci.github.io/kubernetes-operator/docs/getting-started/latest/configuring-seed-jobs-and-pipelines/ // +optional SeedJobs []SeedJob `json:"seedJobs,omitempty"` @@ -46,12 +46,12 @@ type JenkinsSpec struct { SlaveService Service `json:"slaveService,omitempty"` // Backup defines configuration of Jenkins backup - // More info: https://jenkinsci.github.io/kubernetes-operator/docs/getting-started/latest/configure-backup-and-restore/ + // More info: https://jenkinsci.github.io/kubernetes-operator/docs/getting-started/latest/configuring-backup-and-restore/ // +optional Backup Backup `json:"backup,omitempty"` // Backup defines configuration of Jenkins backup restore - // More info: https://jenkinsci.github.io/kubernetes-operator/docs/getting-started/latest/configure-backup-and-restore/ + // More info: https://jenkinsci.github.io/kubernetes-operator/docs/getting-started/latest/configuring-backup-and-restore/ // +optional Restore Restore `json:"restore,omitempty"` @@ -311,6 +311,7 @@ type JenkinsMaster struct { // periodSeconds: 10 // successThreshold: 1 // timeoutSeconds: 5 + // lifecycle: {} // name: jenkins-master // readinessProbe: // failureThreshold: 3 diff --git a/chart/jenkins-operator/templates/jenkins.yaml b/chart/jenkins-operator/templates/jenkins.yaml index 72c18c23..0906891f 100644 --- a/chart/jenkins-operator/templates/jenkins.yaml +++ b/chart/jenkins-operator/templates/jenkins.yaml @@ -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 }} diff --git a/chart/jenkins-operator/values.yaml b/chart/jenkins-operator/values.yaml index 41ce76f8..d1e1ffea 100644 --- a/chart/jenkins-operator/values.yaml +++ b/chart/jenkins-operator/values.yaml @@ -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: "" diff --git a/internal/controller/jenkins_controller.go b/internal/controller/jenkins_controller.go index 88802826..fce29a64 100644 --- a/internal/controller/jenkins_controller.go +++ b/internal/controller/jenkins_controller.go @@ -390,6 +390,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 diff --git a/pkg/configuration/base/resources/pod.go b/pkg/configuration/base/resources/pod.go index 783ccaa2..e46eb533 100644 --- a/pkg/configuration/base/resources/pod.go +++ b/pkg/configuration/base/resources/pod.go @@ -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{ diff --git a/pkg/plugins/base_plugins.go b/pkg/plugins/base_plugins.go index 5b108e01..1baa0878 100644 --- a/pkg/plugins/base_plugins.go +++ b/pkg/plugins/base_plugins.go @@ -6,8 +6,8 @@ const ( jobDslPlugin = "job-dsl:1.89" kubernetesPlugin = "kubernetes:4295.v7fa_01b_309c95" kubernetesCredentialsProviderPlugin = "kubernetes-credentials-provider:1.262.v2670ef7ea_0c5" - // Depends on workflow-job which should be automatically downloaded - workflowAggregatorPlugin = "workflow-aggregator:600.vb_57cdd26fdd7" + workflowAggregatorPlugin = "workflow-aggregator:600.vb_57cdd26fdd7" + workflowJobPlugin = "workflow-job:1436.vfa_244484591f" ) // basePluginsList contains plugins to install by operator. @@ -18,6 +18,7 @@ var basePluginsList = []Plugin{ Must(New(kubernetesPlugin)), Must(New(kubernetesCredentialsProviderPlugin)), Must(New(workflowAggregatorPlugin)), + Must(New(workflowJobPlugin)), } // BasePlugins returns list of plugins to install by operator. diff --git a/test/bats/2-deploy-with-more-options.bats b/test/bats/2-deploy-with-more-options.bats index 92ef93c3..35ad137f 100644 --- a/test/bats/2-deploy-with-more-options.bats +++ b/test/bats/2-deploy-with-more-options.bats @@ -109,6 +109,7 @@ setup() { --set jenkins.nodeSelector.batstest=yep \ --set jenkins.image="jenkins/jenkins:2.479.2-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 @@ -141,6 +142,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" diff --git a/test/e2e/configuration_test.go b/test/e2e/configuration_test.go index 9a6fd852..3d40275e 100644 --- a/test/e2e/configuration_test.go +++ b/test/e2e/configuration_test.go @@ -31,8 +31,8 @@ const ( jobDslPlugin = "job-dsl:1.89" kubernetesPlugin = "kubernetes:4295.v7fa_01b_309c95" kubernetesCredentialsProviderPlugin = "kubernetes-credentials-provider:1.262.v2670ef7ea_0c5" - // Depends on workflow-job which should be automatically downloaded - workflowAggregatorPlugin = "workflow-aggregator:600.vb_57cdd26fdd7" + workflowAggregatorPlugin = "workflow-aggregator:600.vb_57cdd26fdd7" + workflowJobPlugin = "workflow-job:1436.vfa_244484591f" ) var expectedBasePluginsList = []plugins.Plugin{ @@ -42,6 +42,7 @@ var expectedBasePluginsList = []plugins.Plugin{ plugins.Must(plugins.New(kubernetesPlugin)), plugins.Must(plugins.New(kubernetesCredentialsProviderPlugin)), plugins.Must(plugins.New(workflowAggregatorPlugin)), + plugins.Must(plugins.New(workflowJobPlugin)), } func createUserConfigurationSecret(namespace string, stringData map[string]string) {