Skip to content

Commit 0735fb9

Browse files
authored
Add Helm lint CI workflow (#52)
1 parent 7693792 commit 0735fb9

File tree

10 files changed

+303
-4
lines changed

10 files changed

+303
-4
lines changed

.github/workflows/helm-lint.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Helm Lint
2+
on:
3+
workflow_call:
4+
inputs:
5+
ref:
6+
type: string
7+
description: The Git ref under test.
8+
required: true
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
ref: ${{ inputs.ref }}
18+
fetch-depth: 0
19+
20+
- name: Set up Helm
21+
uses: azure/setup-helm@v4
22+
with:
23+
version: v3.15.3
24+
25+
- name: Set up chart-testing
26+
uses: helm/chart-testing-action@v2
27+
28+
- name: Run chart-testing (lint)
29+
run: |-
30+
ct lint \
31+
--lint-conf lintconf.yaml \
32+
--target-branch ${{ github.event.repository.default_branch }} \
33+
--charts chart/ \
34+
--validate-maintainers=false
35+
36+
- name: Run template validation
37+
run: |-
38+
helm template foo chart \
39+
| docker run -i --rm ghcr.io/yannh/kubeconform:latest \
40+
--strict --summary
41+
42+
- name: Run manifest snapshot test
43+
run: docker run -i --rm -v $(pwd):/apps helmunittest/helm-unittest chart

.github/workflows/test-pr.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@ jobs:
2424
with:
2525
ref: ${{ github.event.pull_request.head.sha }}
2626

27+
# Run the chart linting on every PR, even from external repos
28+
helm_lint:
29+
uses: ./.github/workflows/helm-lint.yaml
30+
with:
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
2733
# This job exists so that PRs from outside the main repo are rejected
2834
fail_on_remote:
35+
needs: [unit_tests, helm_lint]
2936
runs-on: ubuntu-latest
3037
steps:
3138
- name: PR must be from a branch in the azimuth-cloud/azimuth-apps-operator repo
3239
run: exit ${{ github.event.pull_request.head.repo.full_name == 'azimuth-cloud/azimuth-apps-operator' && '0' || '1' }}
3340

3441
publish_artifacts:
35-
needs: [unit_tests, fail_on_remote]
42+
needs: [fail_on_remote]
3643
uses: ./.github/workflows/build-push-artifacts.yaml
3744
with:
3845
ref: ${{ github.event.pull_request.head.sha }}

.github/workflows/update-dependencies.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_dispatch:
77
# Run nightly
88
schedule:
9-
- cron: '0 0 * * *'
9+
- cron: "0 0 * * *"
1010

1111
jobs:
1212
propose_github_release_updates:
@@ -43,6 +43,13 @@ jobs:
4343
updates: |
4444
${{ matrix.version_jsonpath }}=${{ steps.next.outputs.version }}
4545
46+
- name: Update manifest snapshots
47+
run: |-
48+
docker run -i --rm --user $(id -u) \
49+
-v $(pwd):/apps \
50+
helmunittest/helm-unittest -u \
51+
chart
52+
4653
- name: Generate app token for PR
4754
uses: azimuth-cloud/github-actions/generate-app-token@master
4855
id: generate-app-token

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributing
2+
3+
We welcome contributions and suggestions for improvements to this code base.
4+
Please check for relevant issues and PRs before opening a new one of your own.
5+
6+
## Making a contribution
7+
8+
### Helm template snapshots
9+
10+
The CI in this repository uses the Helm
11+
[unittest](https://github.com/helm-unittest/helm-unittest) plugin's
12+
snapshotting functionality to check PRs for changes to the templated manifests.
13+
Therefore, if your PR makes changes to the manifest templates or values, you
14+
will need to update the saved snapshots to allow your changes to pass the
15+
automated tests. The easiest way to do this is to run the `helm unittest` command
16+
inside a docker container from the repo root.
17+
18+
```
19+
docker run -i --rm -v $(pwd):/apps helmunittest/helm-unittest chart -u
20+
```
21+
22+
where the `-u` option is used to update the existing snapshots.

chart/.helmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
.idea/
2222
*.tmproj
2323
.vscode/
24+
# Helm unit-test files
25+
tests/

chart/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ apiVersion: v2
33
name: azimuth-apps-operator
44
description: Helm chart for deploying the Azimuth apps operator.
55
type: application
6-
# The version and appVersion are updated by the chart build script
6+
# The version and appVersion are updated by the chart build script
77
version: 0.1.0
88
appVersion: main
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
templated manifests should match snapshot:
2+
1: |
3+
apiVersion: rbac.authorization.k8s.io/v1
4+
kind: ClusterRole
5+
metadata:
6+
labels:
7+
app.kubernetes.io/instance: RELEASE-NAME
8+
app.kubernetes.io/managed-by: Helm
9+
app.kubernetes.io/name: azimuth-apps-operator
10+
app.kubernetes.io/version: main
11+
helm.sh/chart: azimuth-apps-operator-0.1.0
12+
name: release-name-azimuth-apps-operator
13+
rules:
14+
- apiGroups:
15+
- apiextensions.k8s.io
16+
resources:
17+
- customresourcedefinitions
18+
verbs:
19+
- list
20+
- get
21+
- watch
22+
- create
23+
- apiGroups:
24+
- apiextensions.k8s.io
25+
resourceNames:
26+
- apptemplates.apps.azimuth-cloud.io
27+
- apps.apps.azimuth-cloud.io
28+
resources:
29+
- customresourcedefinitions
30+
verbs:
31+
- update
32+
- patch
33+
- apiGroups:
34+
- ""
35+
resources:
36+
- namespaces
37+
verbs:
38+
- list
39+
- watch
40+
- apiGroups:
41+
- ""
42+
- events.k8s.io
43+
resources:
44+
- events
45+
verbs:
46+
- create
47+
- apiGroups:
48+
- apps.azimuth-cloud.io
49+
resources:
50+
- '*'
51+
verbs:
52+
- '*'
53+
- apiGroups:
54+
- ""
55+
resources:
56+
- secrets
57+
verbs:
58+
- '*'
59+
- apiGroups:
60+
- source.toolkit.fluxcd.io
61+
resources:
62+
- helmrepositories
63+
- helmcharts
64+
verbs:
65+
- '*'
66+
- apiGroups:
67+
- helm.toolkit.fluxcd.io
68+
resources:
69+
- helmreleases
70+
verbs:
71+
- '*'
72+
- apiGroups:
73+
- identity.azimuth.stackhpc.com
74+
resources:
75+
- platforms
76+
verbs:
77+
- '*'
78+
2: |
79+
apiVersion: rbac.authorization.k8s.io/v1
80+
kind: ClusterRoleBinding
81+
metadata:
82+
labels:
83+
app.kubernetes.io/instance: RELEASE-NAME
84+
app.kubernetes.io/managed-by: Helm
85+
app.kubernetes.io/name: azimuth-apps-operator
86+
app.kubernetes.io/version: main
87+
helm.sh/chart: azimuth-apps-operator-0.1.0
88+
name: release-name-azimuth-apps-operator
89+
roleRef:
90+
apiGroup: rbac.authorization.k8s.io
91+
kind: ClusterRole
92+
name: release-name-azimuth-apps-operator
93+
subjects:
94+
- kind: ServiceAccount
95+
name: release-name-azimuth-apps-operator
96+
namespace: NAMESPACE
97+
3: |
98+
apiVersion: apps/v1
99+
kind: Deployment
100+
metadata:
101+
labels:
102+
app.kubernetes.io/instance: RELEASE-NAME
103+
app.kubernetes.io/managed-by: Helm
104+
app.kubernetes.io/name: azimuth-apps-operator
105+
app.kubernetes.io/version: main
106+
helm.sh/chart: azimuth-apps-operator-0.1.0
107+
name: release-name-azimuth-apps-operator
108+
spec:
109+
replicas: 1
110+
selector:
111+
matchLabels:
112+
app.kubernetes.io/instance: RELEASE-NAME
113+
app.kubernetes.io/name: azimuth-apps-operator
114+
strategy:
115+
type: Recreate
116+
template:
117+
metadata:
118+
annotations:
119+
azimuth.stackhpc.com/config-hash: 433363aa020effa397e7e63c535231db34bbc4d2900eadd596609a64cb8ebbbd
120+
labels:
121+
app.kubernetes.io/instance: RELEASE-NAME
122+
app.kubernetes.io/name: azimuth-apps-operator
123+
spec:
124+
containers:
125+
- image: ghcr.io/azimuth-cloud/azimuth-apps-operator:main
126+
imagePullPolicy: IfNotPresent
127+
name: operator
128+
ports:
129+
- containerPort: 8080
130+
name: metrics
131+
protocol: TCP
132+
resources: {}
133+
securityContext:
134+
allowPrivilegeEscalation: false
135+
capabilities:
136+
drop:
137+
- ALL
138+
readOnlyRootFilesystem: true
139+
volumeMounts:
140+
- mountPath: /etc/azimuth
141+
name: etc-azimuth
142+
readOnly: true
143+
- mountPath: /tmp
144+
name: tmp
145+
securityContext:
146+
runAsNonRoot: true
147+
serviceAccountName: release-name-azimuth-apps-operator
148+
volumes:
149+
- name: etc-azimuth
150+
secret:
151+
secretName: release-name-azimuth-apps-operator
152+
- emptyDir: {}
153+
name: tmp
154+
4: |
155+
apiVersion: v1
156+
kind: Secret
157+
metadata:
158+
labels:
159+
app.kubernetes.io/instance: RELEASE-NAME
160+
app.kubernetes.io/managed-by: Helm
161+
app.kubernetes.io/name: azimuth-apps-operator
162+
app.kubernetes.io/version: main
163+
helm.sh/chart: azimuth-apps-operator-0.1.0
164+
name: release-name-azimuth-apps-operator
165+
stringData:
166+
apps-operator.yaml: |
167+
!include "/etc/azimuth/defaults.yaml,/etc/azimuth/user-config.yaml"
168+
defaults.yaml: |
169+
{}
170+
user-config.yaml: |
171+
zenithOperator:
172+
chartName: zenith-operator
173+
chartRepo: https://azimuth-cloud.github.io/zenith
174+
chartVersion: 0.15.1
175+
5: |
176+
apiVersion: v1
177+
kind: Service
178+
metadata:
179+
labels:
180+
app.kubernetes.io/instance: RELEASE-NAME
181+
app.kubernetes.io/managed-by: Helm
182+
app.kubernetes.io/name: azimuth-apps-operator
183+
app.kubernetes.io/version: main
184+
helm.sh/chart: azimuth-apps-operator-0.1.0
185+
name: release-name-azimuth-apps-operator
186+
spec:
187+
ports:
188+
- name: metrics
189+
port: 8080
190+
protocol: TCP
191+
targetPort: metrics
192+
selector:
193+
app.kubernetes.io/instance: RELEASE-NAME
194+
app.kubernetes.io/name: azimuth-apps-operator
195+
type: ClusterIP
196+
6: |
197+
apiVersion: v1
198+
kind: ServiceAccount
199+
metadata:
200+
labels:
201+
app.kubernetes.io/instance: RELEASE-NAME
202+
app.kubernetes.io/managed-by: Helm
203+
app.kubernetes.io/name: azimuth-apps-operator
204+
app.kubernetes.io/version: main
205+
helm.sh/chart: azimuth-apps-operator-0.1.0
206+
name: release-name-azimuth-apps-operator

chart/tests/snapshot_test.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# To update manifest snapshots run helm unittest plugin with -u option:
2+
# docker run -i --rm -v $(pwd):/apps helmunittest/helm-unittest -u chart
3+
suite: Manifest snapshot tests
4+
tests:
5+
- it: templated manifests should match snapshot
6+
asserts:
7+
- matchSnapshot: {}

chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trustBundle:
1414
image:
1515
repository: ghcr.io/azimuth-cloud/azimuth-apps-operator
1616
pullPolicy: IfNotPresent
17-
tag: "" # Defaults to appVersion if not given
17+
tag: "" # Defaults to appVersion if not given
1818

1919
imagePullSecrets: []
2020

lintconf.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rules:
2+
comments:
3+
require-starting-space: true
4+
ignore-shebangs: true
5+
min-spaces-from-content: 1

0 commit comments

Comments
 (0)