diff --git a/pkg/controller/jenkins/configuration/base/resources/pod.go b/pkg/controller/jenkins/configuration/base/resources/pod.go index 98b37992..b1783872 100644 --- a/pkg/controller/jenkins/configuration/base/resources/pod.go +++ b/pkg/controller/jenkins/configuration/base/resources/pod.go @@ -29,6 +29,11 @@ const ( jenkinsInitConfigurationVolumeName = "init-configuration" jenkinsInitConfigurationVolumePath = jenkinsPath + "/init-configuration" + refEnvironmentName = "REF" + // RefVolumeName is the Jenkins volume with preinstalled plugins volume name + RefVolumeName = "ref" + refVolumePath = "/usr/share/jenkins/ref/plugins" + // GroovyScriptsSecretVolumePath is a path where are groovy scripts used to configure Jenkins // This script is provided by user GroovyScriptsSecretVolumePath = jenkinsPath + "/groovy-scripts-secrets" @@ -59,7 +64,16 @@ func GetJenkinsMasterContainerBaseCommand() []string { // GetJenkinsMasterContainerBaseEnvs returns Jenkins master pod envs required by operator func GetJenkinsMasterContainerBaseEnvs(jenkins *v1alpha2.Jenkins) []corev1.EnvVar { - envVars := []corev1.EnvVar{} + envVars := []corev1.EnvVar{ + { + Name: refEnvironmentName, + Value: refVolumePath, + }, + { + Name: "COPY_REFERENCE_FILE_LOG", + Value: fmt.Sprintf("%s/%s", getJenkinsHomePath(jenkins), "copy_reference_file.log"), + }, + } if len(jenkins.Spec.ConfigurationAsCode.Secret.Name) > 0 { envVars = append(envVars, corev1.EnvVar{ @@ -169,6 +183,11 @@ func GetJenkinsMasterContainerBaseVolumeMounts(jenkins *v1alpha2.Jenkins) []core MountPath: getJenkinsHomePath(jenkins), ReadOnly: false, }, + { + Name: RefVolumeName, + MountPath: refVolumePath, + ReadOnly: false, + }, { Name: jenkinsScriptsVolumeName, MountPath: JenkinsScriptsVolumePath, diff --git a/pkg/controller/jenkins/jenkins_controller.go b/pkg/controller/jenkins/jenkins_controller.go index c9e5b884..8c6b93cb 100644 --- a/pkg/controller/jenkins/jenkins_controller.go +++ b/pkg/controller/jenkins/jenkins_controller.go @@ -496,12 +496,32 @@ func (r *ReconcileJenkins) setDefaults(jenkins *v1alpha2.Jenkins, logger logr.Lo jenkins.Spec.Master.SecurityContext = &securityContext } + if !refVolumeSet(*jenkins) { + logger.Info("Setting default Jenkins master volume with preinstalled plugins") + changed = true + jenkins.Spec.Master.Volumes = append(jenkins.Spec.Master.Volumes, corev1.Volume{ + Name: resources.RefVolumeName, + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }) + } + if changed { return changed, errors.WithStack(r.client.Update(context.TODO(), jenkins)) } return changed, nil } +func refVolumeSet(jenkins v1alpha2.Jenkins) bool { + for _, volume := range jenkins.Spec.Master.Volumes { + if volume.Name == resources.RefVolumeName { + return true + } + } + return false +} + func isJavaOpsVariableNotSet(container v1alpha2.Container) bool { for _, env := range container.Env { if env.Name == constants.JavaOpsVariableName {