Skip to content

Commit 64b58ee

Browse files
committed
manifests: add jenkins.yaml template
There is this great plugin which I've somehow only learned about recently to make Jenkins configuration much easier: https://github.com/jenkinsci/configuration-as-code-plugin The RHCOS pipeline already makes use of it. To use this though, we need to be able to change the podspec of Jenkins itself, which until now was embedded in the `jenkins-persistent` template. There's more though: I want to be able to define environment variables, configmaps, secrets, etc... The default template doesn't provide facilities for this. So this patch essentially imports the template into our tree so that we can have more control. The downside of course is that we lose updates to the template. (Though that could also be seen as an upside too: we get better reproducibility even if the template is upgrade.) One convention I'm using is prefacing all the changes from the default template values with a comment saying "DELTA:". That way, we can more easily track what we added on top, and make rebasing easier in the future. Another advantage is that it makes setting it up easier because we don't have to customize as many parameters: we can just set the right default for us.
1 parent 4ac00b1 commit 64b58ee

File tree

2 files changed

+214
-14
lines changed

2 files changed

+214
-14
lines changed

Diff for: HACKING.md

+4-14
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,7 @@ And provide it to `--bucket` below.
220220
### Create a Jenkins instance with a persistent volume backing store
221221

222222
```
223-
oc new-app --template=jenkins-persistent \
224-
--param=NAMESPACE=fedora-coreos \
225-
--param=MEMORY_LIMIT=2Gi \
226-
--param=VOLUME_CAPACITY=2Gi \
227-
--param=JENKINS_IMAGE_STREAM_TAG=jenkins:2
223+
oc new-app --file=manifests/jenkins.yaml --param=NAMESPACE=fedora-coreos
228224
```
229225

230226
Notice the `NAMESPACE` parameter. This makes the Jenkins master use the
@@ -233,14 +229,6 @@ reason we create the app first is that otherwise OpenShift will
233229
automatically instantiate Jenkins with default parameters when creating
234230
the Jenkins pipeline).
235231

236-
The `jenkins:2` parameter is to match the tag name in the latest
237-
OpenShift. Some older versions of the template in OpenShift uses
238-
`jenkins:latest`. This will no longer be needed once we are running on a
239-
newer version of OpenShift than 3.6 in
240-
CentOS CI. See [#32](https://github.com/coreos/fedora-coreos-pipeline/pull/32)
241-
and [#70](https://github.com/coreos/fedora-coreos-pipeline/pull/70)
242-
for more context).
243-
244232
### Creating the pipeline
245233

246234
If working on the production pipeline, you may simply do:
@@ -260,7 +248,6 @@ but without the `--official` switch:
260248
You may also want to provide additional switches depending on the
261249
circumstances. Here are some of them:
262250

263-
- `--kvm-selector=kvm-device-plugin`: Use this if you're using the KVM device plugin (modern Kubernetes/OpenShift 4+).
264251
- `--prefix PREFIX`
265252
- The prefix to prepend to created developer-specific resources. By
266253
default, this will be your username, but you can provide a
@@ -269,6 +256,9 @@ circumstances. Here are some of them:
269256
- Git source URL and optional git ref for pipeline Jenkinsfile.
270257
- `--config <URL>[@REF]`
271258
- Git source URL and optional git ref for FCOS config.
259+
- `--kvm-selector=kvm-device-plugin`:
260+
- Use this if you're using the KVM device plugin (modern
261+
Kubernetes/OpenShift 4+).
272262
- `--pvc-size <SIZE>`
273263
- Size of the cache PVC to create. Note that the PVC size cannot be
274264
changed after creation. The format is the one understood by

Diff for: manifests/jenkins.yaml

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# This is a fork of the `jenkins-persistent` OpenShift template because we need
2+
# to be able to pass in more information to the Jenkins pod, such as env vars,
3+
# secrets, configmaps, etc...
4+
5+
apiVersion: v1
6+
kind: Template
7+
labels:
8+
app: fedora-coreos
9+
template: fedora-coreos-jenkins-template
10+
metadata:
11+
annotations:
12+
description: |-
13+
Jenkins service for the Fedora CoreOS pipeline.
14+
iconClass: icon-jenkins
15+
openshift.io/display-name: Fedora CoreOS Jenkins
16+
openshift.io/documentation-url: https://github.com/coreos/fedora-coreos-pipeline
17+
openshift.io/support-url: https://github.com/coreos/fedora-coreos-pipeline
18+
openshift.io/provider-display-name: Fedora CoreOS
19+
tags: fcos,jenkins,fedora
20+
name: fedora-coreos-jenkins
21+
objects:
22+
- apiVersion: v1
23+
kind: Route
24+
metadata:
25+
annotations:
26+
template.openshift.io/expose-uri: http://{.spec.host}{.spec.path}
27+
name: ${JENKINS_SERVICE_NAME}
28+
spec:
29+
tls:
30+
insecureEdgeTerminationPolicy: Redirect
31+
termination: edge
32+
to:
33+
kind: Service
34+
name: ${JENKINS_SERVICE_NAME}
35+
- apiVersion: v1
36+
kind: PersistentVolumeClaim
37+
metadata:
38+
name: ${JENKINS_SERVICE_NAME}
39+
spec:
40+
accessModes:
41+
- ReadWriteOnce
42+
resources:
43+
requests:
44+
storage: ${VOLUME_CAPACITY}
45+
- apiVersion: v1
46+
kind: DeploymentConfig
47+
metadata:
48+
annotations:
49+
template.alpha.openshift.io/wait-for-ready: "true"
50+
name: ${JENKINS_SERVICE_NAME}
51+
spec:
52+
replicas: 1
53+
selector:
54+
name: ${JENKINS_SERVICE_NAME}
55+
strategy:
56+
type: Recreate
57+
template:
58+
metadata:
59+
labels:
60+
name: ${JENKINS_SERVICE_NAME}
61+
spec:
62+
containers:
63+
- capabilities: {}
64+
env:
65+
- name: OPENSHIFT_ENABLE_OAUTH
66+
value: ${ENABLE_OAUTH}
67+
- name: OPENSHIFT_ENABLE_REDIRECT_PROMPT
68+
value: "true"
69+
- name: OPENSHIFT_JENKINS_JVM_ARCH
70+
value: ${JVM_ARCH}
71+
- name: KUBERNETES_MASTER
72+
value: https://kubernetes.default:443
73+
- name: KUBERNETES_TRUST_CERTIFICATES
74+
value: "true"
75+
- name: JNLP_SERVICE_NAME
76+
value: ${JNLP_SERVICE_NAME}
77+
image: ' '
78+
imagePullPolicy: IfNotPresent
79+
livenessProbe:
80+
failureThreshold: 30
81+
httpGet:
82+
path: /login
83+
port: 8080
84+
initialDelaySeconds: 420
85+
timeoutSeconds: 3
86+
name: jenkins
87+
readinessProbe:
88+
httpGet:
89+
path: /login
90+
port: 8080
91+
initialDelaySeconds: 3
92+
timeoutSeconds: 3
93+
resources:
94+
limits:
95+
memory: ${MEMORY_LIMIT}
96+
securityContext:
97+
capabilities: {}
98+
privileged: false
99+
terminationMessagePath: /dev/termination-log
100+
volumeMounts:
101+
- mountPath: /var/lib/jenkins
102+
name: ${JENKINS_SERVICE_NAME}-data
103+
dnsPolicy: ClusterFirst
104+
restartPolicy: Always
105+
serviceAccountName: ${JENKINS_SERVICE_NAME}
106+
volumes:
107+
- name: ${JENKINS_SERVICE_NAME}-data
108+
persistentVolumeClaim:
109+
claimName: ${JENKINS_SERVICE_NAME}
110+
triggers:
111+
- imageChangeParams:
112+
automatic: true
113+
containerNames:
114+
- jenkins
115+
from:
116+
kind: ImageStreamTag
117+
name: ${JENKINS_IMAGE_STREAM_TAG}
118+
namespace: ${NAMESPACE}
119+
lastTriggeredImage: ""
120+
type: ImageChange
121+
- type: ConfigChange
122+
- apiVersion: v1
123+
kind: ServiceAccount
124+
metadata:
125+
annotations:
126+
serviceaccounts.openshift.io/oauth-redirectreference.jenkins: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${JENKINS_SERVICE_NAME}"}}'
127+
name: ${JENKINS_SERVICE_NAME}
128+
- apiVersion: v1
129+
groupNames: null
130+
kind: RoleBinding
131+
metadata:
132+
name: ${JENKINS_SERVICE_NAME}_edit
133+
roleRef:
134+
name: edit
135+
subjects:
136+
- kind: ServiceAccount
137+
name: ${JENKINS_SERVICE_NAME}
138+
- apiVersion: v1
139+
kind: Service
140+
metadata:
141+
name: ${JNLP_SERVICE_NAME}
142+
spec:
143+
ports:
144+
- name: agent
145+
nodePort: 0
146+
port: 50000
147+
protocol: TCP
148+
targetPort: 50000
149+
selector:
150+
name: ${JENKINS_SERVICE_NAME}
151+
sessionAffinity: None
152+
type: ClusterIP
153+
- apiVersion: v1
154+
kind: Service
155+
metadata:
156+
annotations:
157+
service.alpha.openshift.io/dependencies: '[{"name": "${JNLP_SERVICE_NAME}",
158+
"namespace": "", "kind": "Service"}]'
159+
service.openshift.io/infrastructure: "true"
160+
name: ${JENKINS_SERVICE_NAME}
161+
spec:
162+
ports:
163+
- name: web
164+
nodePort: 0
165+
port: 80
166+
protocol: TCP
167+
targetPort: 8080
168+
selector:
169+
name: ${JENKINS_SERVICE_NAME}
170+
sessionAffinity: None
171+
type: ClusterIP
172+
parameters:
173+
- description: The name of the OpenShift Service exposed for the Jenkins container.
174+
displayName: Jenkins Service Name
175+
name: JENKINS_SERVICE_NAME
176+
value: jenkins
177+
- description: The name of the service used for master/slave communication.
178+
displayName: Jenkins JNLP Service Name
179+
name: JNLP_SERVICE_NAME
180+
value: jenkins-jnlp
181+
- description: Whether to enable OAuth OpenShift integration. If false, the static
182+
account 'admin' will be initialized with the password 'password'.
183+
displayName: Enable OAuth in Jenkins
184+
name: ENABLE_OAUTH
185+
value: "true"
186+
- description: Whether Jenkins runs with a 32 bit (i386) or 64 bit (x86_64) JVM.
187+
displayName: Jenkins JVM Architecture
188+
name: JVM_ARCH
189+
value: i386
190+
- description: Maximum amount of memory the container can use.
191+
displayName: Memory Limit
192+
# DELTA: changed from 512Mi
193+
name: MEMORY_LIMIT
194+
value: 2Gi
195+
- description: Volume space available for data, e.g. 512Mi, 2Gi.
196+
displayName: Volume Capacity
197+
name: VOLUME_CAPACITY
198+
required: true
199+
# DELTA: changed from 1Gi
200+
value: 2Gi
201+
- description: The OpenShift Namespace where the Jenkins ImageStream resides.
202+
displayName: Jenkins ImageStream Namespace
203+
name: NAMESPACE
204+
value: openshift
205+
- description: Name of the ImageStreamTag to be used for the Jenkins image.
206+
displayName: Jenkins ImageStreamTag
207+
name: JENKINS_IMAGE_STREAM_TAG
208+
# DELTA: changed from jenkins:latest
209+
# https://github.com/coreos/fedora-coreos-pipeline/pull/70
210+
value: jenkins:2

0 commit comments

Comments
 (0)