Skip to content

Commit f159d57

Browse files
feat(cf-common): add pvc template (#30)
1 parent b383cc5 commit f159d57

39 files changed

+595
-188
lines changed

.github/workflows/lint-test.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,25 @@ jobs:
160160
- name: Set short SHA
161161
run: echo "GITHUB_SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
162162

163+
- name: Normalize git branch name
164+
id: git-branch-name
165+
uses: ohueter/normalize-git-branch-name@v1
166+
with:
167+
ref: ${{ github.ref }}
168+
head-ref: ${{ github.head_ref }}
169+
170+
- name: Print normalized branch name and checksum
171+
run: |
172+
echo "Original branch name: ${{ steps.git-branch-name.outputs.original_name }}"
173+
echo "Normalized branch name: ${{ steps.git-branch-name.outputs.name }}"
174+
echo "SHA1 checksum of branch name: ${{ steps.git-branch-name.outputs.hash }}"
175+
echo "Short SHA1 checksum of branch name: ${{ steps.git-branch-name.outputs.short_hash }}"
176+
163177
- name: Push Helm Chart to Dev ChartMuseum
164178
run: |
165179
set -o xtrace
166180
CHART_NAME=$(yq read ${{ matrix.chart }}/Chart.yaml name)
167-
CHART_VERSION=$(yq read ${{ matrix.chart }}/Chart.yaml version)-$GITHUB_SHORT_SHA
181+
CHART_VERSION=$(yq read ${{ matrix.chart }}/Chart.yaml version)-${{ steps.git-branch-name.outputs.name }}
168182
169183
helm plugin install https://github.com/chartmuseum/helm-push.git
170184
helm repo add chartmuseum ${{ secrets.CHARTMUSEUM_DEV_URL }}/$CHART_NAME --username ${{ secrets.CHARTMUSEUM_DEV_USERNAME }} --password ${{ secrets.CHARTMUSEUM_DEV_PASSWORD }}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ $templateName := printf "cf-common-%s.pvc" (index .Subcharts "cf-common").Chart.Version }}
2+
{{- include $templateName . -}}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: deployment with pvc
3+
templates:
4+
- templates/controller.yaml
5+
- templates/pvc.yaml
6+
tests:
7+
- it: Test pvc volume in deployment
8+
template: templates/controller.yaml
9+
values:
10+
- values.yaml
11+
asserts:
12+
- contains:
13+
path: spec.template.spec.volumes
14+
content:
15+
name: data
16+
persistentVolumeClaim:
17+
claimName: RELEASE-NAME-cf-common-test-data
18+
19+
- it: Test pvc volume mount in deployment container
20+
template: templates/controller.yaml
21+
values:
22+
- values.yaml
23+
asserts:
24+
- contains:
25+
path: spec.template.spec.containers[0].volumeMounts
26+
content:
27+
name: data
28+
mountPath: /var/lib/data
29+
30+
- it: Test existing PVC
31+
templates:
32+
- templates/controller.yaml
33+
- templates/pvc.yaml
34+
values:
35+
- values.yaml
36+
set:
37+
persistence:
38+
data:
39+
enabled: false
40+
volumes:
41+
data:
42+
enabled: true
43+
type: pvc
44+
nameOverride: some-external-pvc
45+
asserts:
46+
- hasDocuments:
47+
count: 0
48+
template: templates/pvc.yaml
49+
- contains:
50+
path: spec.template.spec.volumes
51+
content:
52+
name: data
53+
persistentVolumeClaim:
54+
claimName: some-external-pvc
55+
template: templates/controller.yaml
56+
- contains:
57+
path: spec.template.spec.containers[0].volumeMounts
58+
content:
59+
name: data
60+
mountPath: /var/lib/data
61+
template: templates/controller.yaml
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: pvc error handlers
3+
templates:
4+
- templates/pvc.yaml
5+
tests:
6+
- it: Test required pvc size
7+
template: templates/pvc.yaml
8+
values:
9+
- values.yaml
10+
set:
11+
persistence:
12+
data:
13+
enabled: true
14+
size: null
15+
asserts:
16+
- failedTemplate:
17+
errorMessage: "size is required for PVC RELEASE-NAME-cf-common-test-data"
18+
19+
- it: Test required pvc accessMode
20+
template: templates/pvc.yaml
21+
values:
22+
- values.yaml
23+
set:
24+
persistence:
25+
data:
26+
enabled: true
27+
accessMode: null
28+
asserts:
29+
- failedTemplate:
30+
errorMessage: "accessMode is required for PVC RELEASE-NAME-cf-common-test-data"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: pvc metadata
3+
templates:
4+
- templates/pvc.yaml
5+
tests:
6+
- it: Test pvc default metadata
7+
template: templates/pvc.yaml
8+
values:
9+
- values.yaml
10+
asserts:
11+
- hasDocuments:
12+
count: 1
13+
- isKind:
14+
of: PersistentVolumeClaim
15+
- isNull:
16+
path: metadata.annotations
17+
- equal:
18+
path: metadata.labels
19+
value:
20+
app.kubernetes.io/instance: RELEASE-NAME
21+
app.kubernetes.io/managed-by: Helm
22+
app.kubernetes.io/name: cf-common-test
23+
helm.sh/chart: cf-common-test-0.0.0
24+
- equal:
25+
path: metadata.name
26+
value: RELEASE-NAME-cf-common-test-data
27+
28+
- it: Test retain enabled
29+
template: templates/pvc.yaml
30+
values:
31+
- values.yaml
32+
set:
33+
persistence:
34+
data:
35+
retain: true
36+
asserts:
37+
- hasDocuments:
38+
count: 1
39+
- isKind:
40+
of: PersistentVolumeClaim
41+
- equal:
42+
path: metadata.annotations
43+
value:
44+
helm.sh/resource-policy: keep
45+
46+
- it: Test pvc disabled
47+
template: templates/pvc.yaml
48+
values:
49+
- values.yaml
50+
set:
51+
persistence:
52+
data:
53+
enabled: false
54+
asserts:
55+
- hasDocuments:
56+
count: 0
57+
58+
- it: Test pvc nameOverride
59+
template: templates/pvc.yaml
60+
values:
61+
- values.yaml
62+
set:
63+
persistence:
64+
data:
65+
nameOverride: alice-pvc
66+
asserts:
67+
- hasDocuments:
68+
count: 1
69+
- isKind:
70+
of: PersistentVolumeClaim
71+
- isNull:
72+
path: metadata.annotations
73+
- equal:
74+
path: metadata.labels
75+
value:
76+
app.kubernetes.io/instance: RELEASE-NAME
77+
app.kubernetes.io/managed-by: Helm
78+
app.kubernetes.io/name: cf-common-test
79+
helm.sh/chart: cf-common-test-0.0.0
80+
- equal:
81+
path: metadata.name
82+
value: alice-pvc
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: pvc spec
3+
templates:
4+
- templates/pvc.yaml
5+
tests:
6+
- it: Test pvc accessMode
7+
template: templates/pvc.yaml
8+
values:
9+
- values.yaml
10+
asserts:
11+
- equal:
12+
path: spec.accessModes
13+
value:
14+
- ReadWriteOnce
15+
16+
- it: Test pvc size
17+
template: templates/pvc.yaml
18+
values:
19+
- values.yaml
20+
asserts:
21+
- equal:
22+
path: spec.resources.requests.storage
23+
value: 1Gi
24+
25+
- it: Test pvc default storage class
26+
template: templates/pvc.yaml
27+
values:
28+
- values.yaml
29+
asserts:
30+
- isNull:
31+
path: spec.storageClassName
32+
33+
- it: Test custom storage class
34+
template: templates/pvc.yaml
35+
values:
36+
- values.yaml
37+
set:
38+
persistence:
39+
data:
40+
storageClass: ebs-csi
41+
asserts:
42+
- equal:
43+
path: spec.storageClassName
44+
value: ebs-csi
45+
46+
- it: Test empty storage class
47+
template: templates/pvc.yaml
48+
values:
49+
- values.yaml
50+
set:
51+
persistence:
52+
data:
53+
storageClass: "-"
54+
asserts:
55+
- equal:
56+
path: spec.storageClassName
57+
value: ""
58+
59+
- it: Test global storage class
60+
template: templates/pvc.yaml
61+
values:
62+
- values.yaml
63+
set:
64+
global:
65+
storageClass: ebs-csi-global
66+
asserts:
67+
- equal:
68+
path: spec.storageClassName
69+
value: ebs-csi-global
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# mock values for tests
2+
global: {}
3+
4+
controller:
5+
enabled: true
6+
type: deployment
7+
labels: {}
8+
annotations: {}
9+
replicas: 2
10+
deployment:
11+
strategy: RollingUpdate
12+
rollingUpdate:
13+
maxUnavailable: 0
14+
maxSurge: "50%"
15+
revisionHistoryLimit: 5
16+
17+
container:
18+
image:
19+
registry: 839151377425.dkr.ecr.us-east-1.amazonaws.com/codefresh-inc
20+
repository: codefresh/cf-api
21+
tag: master
22+
pullPolicy: Always
23+
24+
25+
volumeMounts:
26+
data:
27+
path:
28+
- mountPath: /var/lib/data
29+
30+
persistence:
31+
data:
32+
enabled: true
33+
size: 1Gi
34+
accessMode: ReadWriteOnce
35+
36+
volumes:
37+
data:
38+
enabled: true
39+
type: pvc

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.1.2
5+
version: 0.2.0
66
type: library
77
keywords:
88
- codefresh

charts/cf-common/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Codefresh library chart
44

5-
![Version: 0.1.2](https://img.shields.io/badge/Version-0.1.2-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
5+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
66

77
## Installing the Chart
88

@@ -18,7 +18,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
1818
# Chart.yaml
1919
dependencies:
2020
- name: cf-common
21-
version: 0.1.2
21+
version: 0.2.0
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
@@ -121,6 +121,14 @@ dependencies:
121121
| pdb.enabled | bool | `false` | Enable PDB |
122122
| pdb.maxUnavailable | string | `""` | Set number of pods that are unavailable after eviction as number of percentage |
123123
| pdb.minAvailable | string | `""` | Set number of pods that are available after eviction as number of percentage |
124+
| persistence | object | See below | Configure persistence for the chart Additional items can be added by adding a dictionary key similar to the 'data' key. |
125+
| persistence.data | object | `{"accessMode":"ReadWriteOnce","enabled":false,"nameOverride":null,"retain":false,"size":"1Gi","storageClass":null}` | PersistentVolumeClaim name. |
126+
| persistence.data.accessMode | string | `"ReadWriteOnce"` | (required) Set AccessMode for persistent volume |
127+
| persistence.data.enabled | bool | `false` | Enable the PVC |
128+
| persistence.data.nameOverride | string | `nil` | Override the PVC name |
129+
| persistence.data.retain | bool | `false` | Set to true to retain the PVC upon `helm uninstall` |
130+
| persistence.data.size | string | `"1Gi"` | (required) Set the requested size for persistent volume |
131+
| persistence.data.storageClass | string | `nil` | Set Storage Class for PVC object If set to `-`, dynamic provisioning is disabled. If set to something else, the given storageClass is used. If undefined (the default) or set to null, no storageClassName spec is set, choosing the default provisioner. |
124132
| podAnnotations | object | `{}` | Set additional pod annotations |
125133
| podLabels | object | `{}` | Set additional pod labels |
126134
| podSecurityContext | object | `{}` | Set security context for the pod |
@@ -155,7 +163,7 @@ dependencies:
155163
| tolerations | list | `[]` | Set tolerations constrains |
156164
| topologySpreadConstraints | list | `[]` | Set topologySpreadConstraints rules. Helm template supported. Passed through `tpl`, should be configured as string |
157165
| volumes | object | See below | Configure volume for the controller. Additional items can be added by adding a dictionary key similar to the 'config'/`secret` key. |
158-
| volumes.config | object | `{"enabled":false,"type":"configMap"}` | Volume name. Make sure to use the same name in `configMaps`/`secrets` and `container.volumeMounts` |
166+
| volumes.config | object | `{"enabled":false,"type":"configMap"}` | Volume name. Make sure to use the same name in `configMaps`/`secrets`/`persistence` and `container.volumeMounts` |
159167
| volumes.config.enabled | bool | `false` | Enable the volume |
160168
| volumes.config.type | string | `"configMap"` | Volume type (configMap/secret) |
161169

charts/cf-common/templates/classic/_helpers.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{{/*
22
Calculate RabbitMQ URI (for On-Prem)
33
Usage
4-
{{ include "cf-common-0.1.2.classic.calculateRabbitMqUri" . }}
4+
{{ include "cf-common-0.2.0.classic.calculateRabbitMqUri" . }}
55
*/}}
66

7-
{{- define "cf-common-0.1.2.classic.calculateRabbitMqUri" }}
7+
{{- define "cf-common-0.2.0.classic.calculateRabbitMqUri" }}
88

99
{{- $rabbitmqProtocol := .Values.global.rabbitmqProtocol | default "amqp" -}}
1010
{{- $rabbitmqUsername := .Values.global.rabbitmqUsername -}}
@@ -22,9 +22,9 @@ coalesce here for backward compatibility
2222
{{/*
2323
Calculate Mongo Uri (for On-Prem)
2424
Usage:
25-
{{ include "cf.common-0.1.2.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
25+
{{ include "cf.common-0.2.0.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
2626
*/}}
27-
{{- define "cf-common-0.1.2.classic.calculateMongoUri" -}}
27+
{{- define "cf-common-0.2.0.classic.calculateMongoUri" -}}
2828
{{- if contains "?" .mongoURI -}}
2929
{{- $mongoURI := (splitList "?" .mongoURI) -}}
3030
{{- printf "%s%s?%s" (first $mongoURI) .dbName (last $mongoURI) }}

0 commit comments

Comments
 (0)