#190 Fix run Jenkins master on top of OpenShift
This commit is contained in:
parent
80a6d33b0b
commit
09b9972f40
|
|
@ -29,6 +29,11 @@ const (
|
||||||
jenkinsInitConfigurationVolumeName = "init-configuration"
|
jenkinsInitConfigurationVolumeName = "init-configuration"
|
||||||
jenkinsInitConfigurationVolumePath = jenkinsPath + "/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
|
// GroovyScriptsSecretVolumePath is a path where are groovy scripts used to configure Jenkins
|
||||||
// This script is provided by user
|
// This script is provided by user
|
||||||
GroovyScriptsSecretVolumePath = jenkinsPath + "/groovy-scripts-secrets"
|
GroovyScriptsSecretVolumePath = jenkinsPath + "/groovy-scripts-secrets"
|
||||||
|
|
@ -59,7 +64,16 @@ func GetJenkinsMasterContainerBaseCommand() []string {
|
||||||
|
|
||||||
// GetJenkinsMasterContainerBaseEnvs returns Jenkins master pod envs required by operator
|
// GetJenkinsMasterContainerBaseEnvs returns Jenkins master pod envs required by operator
|
||||||
func GetJenkinsMasterContainerBaseEnvs(jenkins *v1alpha2.Jenkins) []corev1.EnvVar {
|
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 {
|
if len(jenkins.Spec.ConfigurationAsCode.Secret.Name) > 0 {
|
||||||
envVars = append(envVars, corev1.EnvVar{
|
envVars = append(envVars, corev1.EnvVar{
|
||||||
|
|
@ -169,6 +183,11 @@ func GetJenkinsMasterContainerBaseVolumeMounts(jenkins *v1alpha2.Jenkins) []core
|
||||||
MountPath: getJenkinsHomePath(jenkins),
|
MountPath: getJenkinsHomePath(jenkins),
|
||||||
ReadOnly: false,
|
ReadOnly: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: RefVolumeName,
|
||||||
|
MountPath: refVolumePath,
|
||||||
|
ReadOnly: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: jenkinsScriptsVolumeName,
|
Name: jenkinsScriptsVolumeName,
|
||||||
MountPath: JenkinsScriptsVolumePath,
|
MountPath: JenkinsScriptsVolumePath,
|
||||||
|
|
|
||||||
|
|
@ -496,12 +496,32 @@ func (r *ReconcileJenkins) setDefaults(jenkins *v1alpha2.Jenkins, logger logr.Lo
|
||||||
jenkins.Spec.Master.SecurityContext = &securityContext
|
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 {
|
if changed {
|
||||||
return changed, errors.WithStack(r.client.Update(context.TODO(), jenkins))
|
return changed, errors.WithStack(r.client.Update(context.TODO(), jenkins))
|
||||||
}
|
}
|
||||||
return changed, nil
|
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 {
|
func isJavaOpsVariableNotSet(container v1alpha2.Container) bool {
|
||||||
for _, env := range container.Env {
|
for _, env := range container.Env {
|
||||||
if env.Name == constants.JavaOpsVariableName {
|
if env.Name == constants.JavaOpsVariableName {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue