Skip to content

Commit

Permalink
Add unit tests for most resources (#87)
Browse files Browse the repository at this point in the history
* Add unit tests for most resources

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

* removed helm.sh/chart label from pod template

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

* Add tests for deployment and AlertingRule

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

* Renamed tests

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

* Align deployment test

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

* Removed helm.sh/chart label from ConfigMap

Checksum of the configmap is used as annotation on the jenkins
pod to trigger a restart on config changes.

If the chart version is part of the label then it triggers a restart
whenever a newer chart version is used.

Signed-off-by: Torsten Walter <[email protected]>
  • Loading branch information
torstenwalter authored Oct 14, 2020
1 parent 6259c19 commit acb51f5
Show file tree
Hide file tree
Showing 23 changed files with 1,968 additions and 113 deletions.
4 changes: 4 additions & 0 deletions charts/jenkins/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Use the following links to reference issues, PRs, and commits prior to v2.6.0.

The change log until v1.5.7 was auto-generated based on git commits. Those entries include a reference to the git commit to be able to get more details.

## 2.12.2

Added unit tests for most resources in the Helm chart.

## 2.12.1

Helm chart README update
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: 2.12.1
version: 2.12.2
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
1 change: 0 additions & 1 deletion charts/jenkins/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
namespace: {{ template "jenkins.namespace" . }}
labels:
"app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
"helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
"app.kubernetes.io/managed-by": "{{ .Release.Service }}"
"app.kubernetes.io/instance": "{{ .Release.Name }}"
"app.kubernetes.io/component": "{{ .Values.master.componentName }}"
Expand Down
1 change: 0 additions & 1 deletion charts/jenkins/templates/jenkins-master-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ spec:
metadata:
labels:
"app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
"helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
"app.kubernetes.io/managed-by": "{{ .Release.Service }}"
"app.kubernetes.io/instance": "{{ .Release.Name }}"
"app.kubernetes.io/component": "{{ .Values.master.componentName }}"
Expand Down
2 changes: 0 additions & 2 deletions charts/jenkins/templates/jenkins-master-servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ spec:
- "{{ template "jenkins.namespace" $ }}"
selector:
matchLabels:
"app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
"helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
"app.kubernetes.io/instance": "{{ .Release.Name }}"
"app.kubernetes.io/component": "{{ .Values.master.componentName }}"
{{- end }}
85 changes: 85 additions & 0 deletions charts/jenkins/tests/config-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
suite: ConfigMap
templates:
- config.yaml
tests:
- it: default config
asserts:
- isKind:
of: ConfigMap
- hasDocuments:
count: 1
- equal:
path: data.apply_config\.sh
value: |-
echo "applying Jenkins configuration"
echo "disable Setup Wizard"
# Prevent Setup Wizard when JCasC is enabled
echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.UpgradeWizard.state
echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
echo "download plugins"
# Install missing plugins
cp /var/jenkins_config/plugins.txt /var/jenkins_home;
rm -rf /usr/share/jenkins/ref/plugins/*.lock
/usr/local/bin/install-plugins.sh `echo $(cat /var/jenkins_home/plugins.txt)`;
echo "copy plugins to shared volume"
# Copy plugins to shared volume
yes n | cp -i /usr/share/jenkins/ref/plugins/* /var/jenkins_plugins/;
echo "finished initialization"
- equal:
path: data.plugins\.txt
value: |-
kubernetes:1.25.7
workflow-job:2.39
workflow-aggregator:2.6
credentials-binding:1.23
git:4.2.2
configuration-as-code:1.43
- it: no plugins
set:
master.installPlugins: []
asserts:
- equal:
path: data.apply_config\.sh
value: |-
echo "applying Jenkins configuration"
echo "disable Setup Wizard"
# Prevent Setup Wizard when JCasC is enabled
echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.UpgradeWizard.state
echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
echo "finished initialization"
- equal:
path: data.plugins\.txt
value: ""
- it: additional plugins config
set:
master:
additionalPlugins:
- kubernetes-credentials-provider
asserts:
- equal:
path: data.apply_config\.sh
value: |-
echo "applying Jenkins configuration"
echo "disable Setup Wizard"
# Prevent Setup Wizard when JCasC is enabled
echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.UpgradeWizard.state
echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
echo "download plugins"
# Install missing plugins
cp /var/jenkins_config/plugins.txt /var/jenkins_home;
rm -rf /usr/share/jenkins/ref/plugins/*.lock
/usr/local/bin/install-plugins.sh `echo $(cat /var/jenkins_home/plugins.txt)`;
echo "copy plugins to shared volume"
# Copy plugins to shared volume
yes n | cp -i /usr/share/jenkins/ref/plugins/* /var/jenkins_plugins/;
echo "finished initialization"
- equal:
path: data.plugins\.txt
value: |-
kubernetes:1.25.7
workflow-job:2.39
workflow-aggregator:2.6
credentials-binding:1.23
git:4.2.2
configuration-as-code:1.43
kubernetes-credentials-provider
108 changes: 0 additions & 108 deletions charts/jenkins/tests/deployment_test.yaml

This file was deleted.

63 changes: 63 additions & 0 deletions charts/jenkins/tests/home-pvc-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
suite: PersistentVolumeClaim
release:
name: my-release
namespace: my-namespace
templates:
- home-pvc.yaml
tests:
- it: tests defaults
asserts:
- isKind:
of: PersistentVolumeClaim
- equal:
path: apiVersion
value: v1
- equal:
path: metadata.name
value: my-release-jenkins
- equal:
path: metadata.namespace
value: my-namespace
- isNull:
path: metadata.annotations
- contains:
path: spec.accessModes
content: ReadWriteOnce
- equal:
path: spec.resources.requests
value:
storage: 8Gi
- isNull:
path: spec.storageClassName

- it: test different values
set:
persistence:
annotations:
my-annotation: value
accessMode: ReadWriteMany
size: 20Gi
storageClass: gp2
asserts:
- equal:
path: metadata.annotations
value:
my-annotation: value
- contains:
path: spec.accessModes
content: ReadWriteMany
- equal:
path: spec.resources.requests
value:
storage: 20Gi
- equal:
path: spec.storageClassName
value: gp2

- it: existing claim
set:
persistence:
existingClaim: my-pvc
asserts:
- hasDocuments:
count: 0
Loading

0 comments on commit acb51f5

Please sign in to comment.