Skip to content

Commit

Permalink
[stable/jenkins] display error when admin user does not exist. (#16949)
Browse files Browse the repository at this point in the history
* Display error when admin user does not exist.

Print an error message when `master.sidecars.configAutoReload.enabled` is `true`, but the admin user which is needed to configure the SSH key does not exist.

Signed-off-by: Torsten Walter <[email protected]>

* only configure ssh key if user exists

Signed-off-by: Torsten Walter <[email protected]>
  • Loading branch information
torstenwalter authored and k8s-ci-robot committed Sep 13, 2019
1 parent 75e0471 commit 53c7071
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions charts/jenkins/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ numbering uses [semantic versioning](http://semver.org).

NOTE: The change log until version 1.5.7 is auto generated based on git commits. Those include a reference to the git commit to be able to get more details.

## 1.6.1

Print error message when `master.sidecars.configAutoReload.enabled` is `true`, but the admin user can't be found to configure the SSH key.

## 1.6.0

Add support for Google Cloud Storage for backup CronJob (migrating from nuvo/kube-tasks to maorfr/kube-tasks)
Expand Down
2 changes: 1 addition & 1 deletion charts/jenkins/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
name: jenkins
home: https://jenkins.io/
version: 1.6.0
version: 1.6.1
appVersion: lts
description: Open source continuous integration server. It supports multiple SCM tools
including CVS, Subversion and Git. It can execute Apache Ant and Apache Maven-based
Expand Down
24 changes: 13 additions & 11 deletions charts/jenkins/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,20 @@ data:
init-add-ssh-key-to-admin.groovy: |-
import jenkins.security.*
import hudson.model.User
import jenkins.security.ApiTokenProperty
import jenkins.model.Jenkins
User u = User.get("{{ .Values.master.adminUser | default "admin" }}")
ApiTokenProperty t = u.getProperty(ApiTokenProperty.class)
String sshKeyString = new File('/var/jenkins_home/key.pub').text
keys_param = new org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl(sshKeyString)
u.addProperty(keys_param)
def inst = Jenkins.getInstance()
def sshDesc = inst.getDescriptor("org.jenkinsci.main.modules.sshd.SSHD")
sshDesc.setPort({{ .Values.master.sidecars.configAutoReload.sshTcpPort | default 1044 }})
sshDesc.getActualPort()
sshDesc.save()
User user = User.get("{{ .Values.master.adminUser | default "admin" }}", false)
if (user == null) {
System.err.println("ERROR: user '{{ .Values.master.adminUser | default "admin" }}' not found! Can't configure SSH key which is needed to reload JCasC config!")
} else {
String sshKeyString = new File('/var/jenkins_home/key.pub').text
keys_param = new org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl(sshKeyString)
user.addProperty(keys_param)
def inst = Jenkins.getInstance()
def sshDesc = inst.getDescriptor("org.jenkinsci.main.modules.sshd.SSHD")
sshDesc.setPort({{ .Values.master.sidecars.configAutoReload.sshTcpPort | default 1044 }})
sshDesc.getActualPort()
sshDesc.save()
}
{{- else }}
# Only add config to this script if we aren't auto-reloading otherwise the pod will restart upon each config change:
{{- range $key, $val := .Values.master.JCasC.configScripts }}
Expand Down

0 comments on commit 53c7071

Please sign in to comment.