feat(skipPlugins): add option to skip install of plugins

This commit is contained in:
Tobia De Koninck 2024-09-27 16:49:33 +02:00
parent 7cdffbe716
commit fbaffc4e83
4 changed files with 21 additions and 0 deletions

View File

@ -376,6 +376,12 @@ type JenkinsMaster struct {
// +optional // +optional
LatestPlugins *bool `json:"latestPlugins,omitempty"` 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 allows you to toggle CSRF Protection on Jenkins
DisableCSRFProtection bool `json:"disableCSRFProtection"` DisableCSRFProtection bool `json:"disableCSRFProtection"`

View File

@ -147,6 +147,9 @@ spec:
description: Master represents Jenkins master pod properties and Jenkins description: Master represents Jenkins master pod properties and Jenkins
plugins. Every single change here requires a pod restart. plugins. Every single change here requires a pod restart.
properties: 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: annotations:
additionalProperties: additionalProperties:
type: string type: string

View File

@ -13,6 +13,9 @@ import (
) )
func (r *JenkinsBaseConfigurationReconciler) verifyPlugins(jenkinsClient jenkinsclient.Jenkins) (bool, error) { 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) allPluginsInJenkins, err := jenkinsClient.GetPlugins(fetchAllPlugins)
if err != nil { if err != nil {
return false, stackerr.WithStack(err) return false, stackerr.WithStack(err)

View File

@ -36,6 +36,7 @@ mkdir -p {{ .JenkinsHomePath }}/scripts
cp {{ .JenkinsScriptsVolumePath }}/*.sh {{ .JenkinsHomePath }}/scripts cp {{ .JenkinsScriptsVolumePath }}/*.sh {{ .JenkinsHomePath }}/scripts
chmod +x {{ .JenkinsHomePath }}/scripts/*.sh chmod +x {{ .JenkinsHomePath }}/scripts/*.sh
{{if not .SkipPlugins }}
{{- $jenkinsHomePath := .JenkinsHomePath }} {{- $jenkinsHomePath := .JenkinsHomePath }}
{{- $installPluginsCommand := .InstallPluginsCommand }} {{- $installPluginsCommand := .InstallPluginsCommand }}
@ -58,6 +59,7 @@ EOF
{{ $installPluginsCommand }} --verbose --latest {{ .LatestPlugins }} -f {{ .JenkinsHomePath }}/user-plugins.txt {{ $installPluginsCommand }} --verbose --latest {{ .LatestPlugins }} -f {{ .JenkinsHomePath }}/user-plugins.txt
echo "Installing plugins required by user - end" echo "Installing plugins required by user - end"
{{end}}
`)) `))
func buildConfigMapTypeMeta() metav1.TypeMeta { func buildConfigMapTypeMeta() metav1.TypeMeta {
@ -73,6 +75,11 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) {
latestP = new(bool) latestP = new(bool)
*latestP = true *latestP = true
} }
skipPlugins := jenkins.Spec.Master.SkipPlugins
if skipPlugins == nil {
skipPlugins = new(bool)
*skipPlugins = false
}
data := struct { data := struct {
JenkinsHomePath string JenkinsHomePath string
InitConfigurationPath string InitConfigurationPath string
@ -81,6 +88,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) {
BasePlugins []v1alpha2.Plugin BasePlugins []v1alpha2.Plugin
UserPlugins []v1alpha2.Plugin UserPlugins []v1alpha2.Plugin
LatestPlugins bool LatestPlugins bool
SkipPlugins bool
}{ }{
JenkinsHomePath: getJenkinsHomePath(jenkins), JenkinsHomePath: getJenkinsHomePath(jenkins),
InitConfigurationPath: jenkinsInitConfigurationVolumePath, InitConfigurationPath: jenkinsInitConfigurationVolumePath,
@ -89,6 +97,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) {
InstallPluginsCommand: installPluginsCommand, InstallPluginsCommand: installPluginsCommand,
JenkinsScriptsVolumePath: JenkinsScriptsVolumePath, JenkinsScriptsVolumePath: JenkinsScriptsVolumePath,
LatestPlugins: *latestP, LatestPlugins: *latestP,
SkipPlugins: *skipPlugins,
} }
output, err := render.Render(initBashTemplate, data) output, err := render.Render(initBashTemplate, data)