Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not delete configs on a readonly mount #20

Merged
merged 4 commits into from
Mar 30, 2018
Merged

Do not delete configs on a readonly mount #20

merged 4 commits into from
Mar 30, 2018

Conversation

sthaha
Copy link

@sthaha sthaha commented Mar 20, 2018

Following a recent change to the jenkins deployment that made the
configmap and the secrets readonly, deleting the configurations that
are stored in the config-map resulted in an error message.
This patch fixes it by deleting rm -rf /opt/openshift/configuration
in the run script.

Fixes: openshiftio/openshift.io#2608
See also: kubernetes/kubernetes#60814

@sthaha
Copy link
Author

sthaha commented Mar 20, 2018

NOTE: the PR is a wip I intend to add more commits to this pr which addresses related issues.

sthaha added 4 commits March 28, 2018 11:59
Following a recent change to the jenkins deployment that made the
configmap and the secrets readonly, deleting the configurations that
are stored in the config-map resulted in an error message.
This patch fixes it by deleting `rm -rf /opt/openshift/configuration`
in the `run` script.

Fixes: openshiftio/openshift.io#2608
See also: kubernetes/kubernetes#60814
This allow JENKINS_HOME to be setup to a different one when testing the
run script locally
Following a recent change to the jenkins deployment that made the
configmap and the secrets readonly, deleting the configurations that
are stored in the config-map resulted in an error message.
This patch fixes it by expanding templates into a temp directory and
then copying the expanded templates into JENKINS_HOME

Fixes: openshiftio/openshift.io#2608
See also: kubernetes/kubernetes#60814
@sthaha sthaha removed the DNM label Mar 29, 2018
@sthaha
Copy link
Author

sthaha commented Mar 29, 2018

With this patch

OPENSHIFT_JENKINS_JVM_ARCH is set to i686 so using 32 bit Java
mkdir: cannot create directory '/var/lib/jenkins/logs': File exists
Generating kubernetes-plugin configuration (/opt/openshift/configuration/config.xml.tpl) ...
/usr/libexec/s2i/run: line 111: /opt/openshift/configuration/config.xml: Read-only file system
Generating kubernetes-plugin credentials (/var/lib/jenkins/credentials.xml.tpl) ...
/usr/libexec/s2i/run: line 123: /opt/openshift/configuration/credentials.xml: Read-only file system
Copying Jenkins configuration to /var/lib/jenkins ...
rm: cannot remove '/opt/openshift/configuration/config.xml.tpl': Read-only file system
rm: cannot remove '/opt/openshift/configuration/credentials.xml.tpl': Read-only file system
rm: cannot remove '/opt/openshift/configuration/hudson.tasks.Maven.xml': Read-only file system
rm: cannot remove '/opt/openshift/configuration/io.fabric8.jenkins.openshiftsync.GlobalPluginConfiguration.xml': Read-only file system
rm: cannot remove '/opt/openshift/configuration/jenkins.plugins.nodejs.tools.NodeJSInstallation.xml': Read-only file system
rm: cannot remove '/opt/openshift/configuration/org.jenkinsci.main.modules.sshd.SSHD.xml': Read-only file system
rm: cannot remove '/opt/openshift/configuration/org.jenkinsci.plugins.updatebot.GlobalPluginConfiguration.xml': Read-only file system
rm: cannot remove '/opt/openshift/configuration/scriptApproval.xml': Read-only file system
Creating initial Jenkins 'admin' user ...
sed: can't read /var/lib/jenkins/users/admin/config.xml: No such file or directory
Running from: /usr/lib/jenkins/jenkins.war

turns to

OPENSHIFT_JENKINS_JVM_ARCH is set to i686 so using 32 bit Java
Mar 29, 2018 06:56:22 AM INFO: Using temp directory /var/lib/jenkins/tmp.LacoQ2DwnK for generating configurations
Mar 29, 2018 06:56:22 AM INFO: Generating kubernetes-plugin configuration (/opt/openshift/configuration/config.xml.tpl)
Mar 29, 2018 06:56:22 AM INFO: Generating kubernetes-plugin credentials (credentials.xml) ...
Mar 29, 2018 06:56:22 AM INFO: Copying Jenkins configuration to /var/lib/jenkins
Mar 29, 2018 06:56:22 AM INFO: Removing template files (*.tpl) from /var/lib/jenkins
Mar 29, 2018 06:56:22 AM INFO: Removed temp directory /var/lib/jenkins/tmp.LacoQ2DwnK
Creating initial Jenkins 'admin' user ...
sed: can't read /var/lib/jenkins/users/admin/config.xml: No such file or directory
Running from: /usr/lib/jenkins/jenkins.war

@sthaha
Copy link
Author

sthaha commented Mar 29, 2018

Tested the patch in OSIO by running pipeline twice


# we don't need the templates
log_info "Removing template files (*.tpl) from $JENKINS_HOME"
rm -f "$JENKINS_HOME/"*.tpl

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this remove really necessary? My concerns is that we face the same problem we had some time ago.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it shoudn't cause any errors as $JENKINS_HOME is rw and not read-only. If JENKINS_HOME is ro then that is a much bigger problem as nothing can write to it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a problem on an error but in performance problems we faced in the past . cc @kbsingh what do you think?

Copy link
Author

@sthaha sthaha Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lordofthejars Wasn't the root cause for performance issue that we were copying 400MB of plugin which is like close to 300 files?

A reason to do this way using a tmp dir is to ensure that failure of an in between step do not leave the system in a bad state.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think we can remove safely because exploring the issue I am mention (openshiftio/openshift.io#2612) I see that it was because of a move not a remove. So go ahead.

generate_jenkins_config
generate_credentials
copy_config_files
rm -fr "${IMAGE_CONFIG_GEN_DIR}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before, I am not sure if it is really good idea to remove all created stuff,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am only removing the tmp directory used to expand the templates after they are copied to appropriate locations. So the workflow is like this ...

  1. check if config needs to be generated
  2. if so, create a tmp dir and generate all configs there
  3. copy the expanded configs to appropriate location
  4. cleanup the tmp dir i.e. rm it

This is all done under $JENKINS_HOME which is required to by read-write mount

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so this remove is just executed at most once, so when an instance is unidled, since everything is already in place then it is not executed right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lordofthejars yes, and no. Given the current config-map no, the config will be generated every time the jenkins boots until we modify existing config-map to add a timestamp see - CONFIG_TIMESTAMP var above and how that is used config_changed method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well configs are not so many files IIRC and not so much MB so we are fine.

@sthaha sthaha merged commit 4dd3216 into fabric8-jenkins:master Mar 30, 2018
@sthaha sthaha deleted the fix-2608-config-rm-errors branch March 30, 2018 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lots of config errors on jenkins startup
2 participants