From fbaffc4e8357ab19937f26b126651e4656865710 Mon Sep 17 00:00:00 2001 From: Tobia De Koninck Date: Fri, 27 Sep 2024 16:49:33 +0200 Subject: [PATCH] feat(skipPlugins): add option to skip install of plugins --- api/v1alpha2/jenkins_types.go | 6 ++++++ config/crd/bases/jenkins.io_jenkins.yaml | 3 +++ pkg/configuration/base/plugin.go | 3 +++ pkg/configuration/base/resources/scripts_configmap.go | 9 +++++++++ 4 files changed, 21 insertions(+) diff --git a/api/v1alpha2/jenkins_types.go b/api/v1alpha2/jenkins_types.go index 7ffed5a86..85a2ffe9f 100644 --- a/api/v1alpha2/jenkins_types.go +++ b/api/v1alpha2/jenkins_types.go @@ -376,6 +376,12 @@ type JenkinsMaster struct { // +optional LatestPlugins *bool `json:"latestPlugins,omitempty"` + // Allow to skip installation of both BasePlugins and Plugins. + // Requires using a custom image which includes the BasePlugins. + // Defaults to false. + // +optional + SkipPlugins *bool `json:"skipPlugins,omitempty"` + // DisableCSRFProtection allows you to toggle CSRF Protection on Jenkins DisableCSRFProtection bool `json:"disableCSRFProtection"` diff --git a/config/crd/bases/jenkins.io_jenkins.yaml b/config/crd/bases/jenkins.io_jenkins.yaml index 0e3a40e5d..c1428ec0a 100644 --- a/config/crd/bases/jenkins.io_jenkins.yaml +++ b/config/crd/bases/jenkins.io_jenkins.yaml @@ -147,6 +147,9 @@ spec: description: Master represents Jenkins master pod properties and Jenkins plugins. Every single change here requires a pod restart. properties: + skipPlugins: + description: Allow to skip installation of both BasePlugins and Plugins. Requires using a custom image which includes the BasePlugins. Defaults to false. + type: boolean annotations: additionalProperties: type: string diff --git a/pkg/configuration/base/plugin.go b/pkg/configuration/base/plugin.go index 41614ac9f..8b9375eb9 100644 --- a/pkg/configuration/base/plugin.go +++ b/pkg/configuration/base/plugin.go @@ -13,6 +13,9 @@ import ( ) func (r *JenkinsBaseConfigurationReconciler) verifyPlugins(jenkinsClient jenkinsclient.Jenkins) (bool, error) { + if r.Configuration.Jenkins.Spec.Master.SkipPlugins != nil && *r.Configuration.Jenkins.Spec.Master.SkipPlugins { + return true, nil + } allPluginsInJenkins, err := jenkinsClient.GetPlugins(fetchAllPlugins) if err != nil { return false, stackerr.WithStack(err) diff --git a/pkg/configuration/base/resources/scripts_configmap.go b/pkg/configuration/base/resources/scripts_configmap.go index b60aa50b4..091456237 100644 --- a/pkg/configuration/base/resources/scripts_configmap.go +++ b/pkg/configuration/base/resources/scripts_configmap.go @@ -36,6 +36,7 @@ mkdir -p {{ .JenkinsHomePath }}/scripts cp {{ .JenkinsScriptsVolumePath }}/*.sh {{ .JenkinsHomePath }}/scripts chmod +x {{ .JenkinsHomePath }}/scripts/*.sh +{{if not .SkipPlugins }} {{- $jenkinsHomePath := .JenkinsHomePath }} {{- $installPluginsCommand := .InstallPluginsCommand }} @@ -58,6 +59,7 @@ EOF {{ $installPluginsCommand }} --verbose --latest {{ .LatestPlugins }} -f {{ .JenkinsHomePath }}/user-plugins.txt echo "Installing plugins required by user - end" +{{end}} `)) func buildConfigMapTypeMeta() metav1.TypeMeta { @@ -73,6 +75,11 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) { latestP = new(bool) *latestP = true } + skipPlugins := jenkins.Spec.Master.SkipPlugins + if skipPlugins == nil { + skipPlugins = new(bool) + *skipPlugins = false + } data := struct { JenkinsHomePath string InitConfigurationPath string @@ -81,6 +88,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) { BasePlugins []v1alpha2.Plugin UserPlugins []v1alpha2.Plugin LatestPlugins bool + SkipPlugins bool }{ JenkinsHomePath: getJenkinsHomePath(jenkins), InitConfigurationPath: jenkinsInitConfigurationVolumePath, @@ -89,6 +97,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) { InstallPluginsCommand: installPluginsCommand, JenkinsScriptsVolumePath: JenkinsScriptsVolumePath, LatestPlugins: *latestP, + SkipPlugins: *skipPlugins, } output, err := render.Render(initBashTemplate, data)