Skip to content

Commit 9ead42b

Browse files
authored
Add Helm lint CI workflow (#150)
1 parent b5a5979 commit 9ead42b

File tree

7 files changed

+298
-2
lines changed

7 files changed

+298
-2
lines changed

.github/workflows/helm-lint.yaml

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

.github/workflows/main.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ jobs:
1515
with:
1616
ref: ${{ github.ref }}
1717

18+
helm_lint:
19+
uses: ./.github/workflows/helm-lint.yaml
20+
with:
21+
ref: ${{ github.ref }}
22+
1823
publish_images:
19-
needs: [unit_tests]
24+
needs: [unit_tests, helm_lint]
2025
uses: ./.github/workflows/publish-images.yaml
2126
with:
2227
ref: ${{ github.ref }}

.github/workflows/pr.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ jobs:
2121
with:
2222
ref: ${{ github.event.pull_request.head.sha }}
2323

24+
helm_lint:
25+
uses: ./.github/workflows/helm-lint.yaml
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha }}
28+
2429
# When the PR is from a branch of the main repo, publish images and charts
2530
publish_images:
26-
needs: [unit_tests]
31+
needs: [unit_tests, helm_lint]
2732
uses: ./.github/workflows/publish-images.yaml
2833
with:
2934
ref: ${{ github.event.pull_request.head.sha }}

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 charts/operator -u
20+
```
21+
22+
where the `-u` option is used to update the existing snapshots.

charts/operator/.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/
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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-schedule-operator
10+
app.kubernetes.io/version: main
11+
helm.sh/chart: azimuth-schedule-operator-0.1.0
12+
rbac.authorization.k8s.io/aggregate-to-admin: "true"
13+
rbac.authorization.k8s.io/aggregate-to-edit: "true"
14+
rbac.authorization.k8s.io/aggregate-to-view: "true"
15+
name: release-name-azimuth-schedule-operator:edit
16+
rules:
17+
- apiGroups:
18+
- scheduling.azimuth.stackhpc.com
19+
resources:
20+
- '*'
21+
verbs:
22+
- '*'
23+
2: |
24+
apiVersion: rbac.authorization.k8s.io/v1
25+
kind: ClusterRole
26+
metadata:
27+
labels:
28+
app.kubernetes.io/instance: RELEASE-NAME
29+
app.kubernetes.io/managed-by: Helm
30+
app.kubernetes.io/name: azimuth-schedule-operator
31+
app.kubernetes.io/version: main
32+
helm.sh/chart: azimuth-schedule-operator-0.1.0
33+
name: release-name-azimuth-schedule-operator:controller
34+
rules:
35+
- apiGroups:
36+
- apiextensions.k8s.io
37+
resources:
38+
- customresourcedefinitions
39+
verbs:
40+
- '*'
41+
- apiGroups:
42+
- ""
43+
resources:
44+
- namespaces
45+
verbs:
46+
- list
47+
- watch
48+
- apiGroups:
49+
- ""
50+
- events.k8s.io
51+
resources:
52+
- events
53+
verbs:
54+
- create
55+
- apiGroups:
56+
- scheduling.azimuth.stackhpc.com
57+
resources:
58+
- '*'
59+
verbs:
60+
- '*'
61+
- apiGroups:
62+
- ""
63+
resources:
64+
- secrets
65+
verbs:
66+
- get
67+
- delete
68+
- apiGroups:
69+
- caas.azimuth.stackhpc.com
70+
resources:
71+
- clusters
72+
verbs:
73+
- get
74+
- delete
75+
- apiGroups:
76+
- azimuth.stackhpc.com
77+
resources:
78+
- clusters
79+
verbs:
80+
- get
81+
- delete
82+
3: |
83+
apiVersion: rbac.authorization.k8s.io/v1
84+
kind: ClusterRole
85+
metadata:
86+
labels:
87+
app.kubernetes.io/instance: RELEASE-NAME
88+
app.kubernetes.io/managed-by: Helm
89+
app.kubernetes.io/name: azimuth-schedule-operator
90+
app.kubernetes.io/version: main
91+
helm.sh/chart: azimuth-schedule-operator-0.1.0
92+
rbac.authorization.k8s.io/aggregate-to-view: "true"
93+
name: release-name-azimuth-schedule-operator:view
94+
rules:
95+
- apiGroups:
96+
- scheduling.azimuth.stackhpc.com
97+
resources:
98+
- '*'
99+
verbs:
100+
- get
101+
- list
102+
- watch
103+
4: |
104+
apiVersion: rbac.authorization.k8s.io/v1
105+
kind: ClusterRoleBinding
106+
metadata:
107+
labels:
108+
app.kubernetes.io/instance: RELEASE-NAME
109+
app.kubernetes.io/managed-by: Helm
110+
app.kubernetes.io/name: azimuth-schedule-operator
111+
app.kubernetes.io/version: main
112+
helm.sh/chart: azimuth-schedule-operator-0.1.0
113+
name: release-name-azimuth-schedule-operator
114+
roleRef:
115+
apiGroup: rbac.authorization.k8s.io
116+
kind: ClusterRole
117+
name: release-name-azimuth-schedule-operator:controller
118+
subjects:
119+
- kind: ServiceAccount
120+
name: release-name-azimuth-schedule-operator
121+
namespace: NAMESPACE
122+
5: |
123+
apiVersion: apps/v1
124+
kind: Deployment
125+
metadata:
126+
labels:
127+
app.kubernetes.io/instance: RELEASE-NAME
128+
app.kubernetes.io/managed-by: Helm
129+
app.kubernetes.io/name: azimuth-schedule-operator
130+
app.kubernetes.io/version: main
131+
helm.sh/chart: azimuth-schedule-operator-0.1.0
132+
name: release-name-azimuth-schedule-operator
133+
spec:
134+
replicas: 1
135+
selector:
136+
matchLabels:
137+
app.kubernetes.io/instance: RELEASE-NAME
138+
app.kubernetes.io/name: azimuth-schedule-operator
139+
strategy:
140+
type: Recreate
141+
template:
142+
metadata:
143+
labels:
144+
app.kubernetes.io/instance: RELEASE-NAME
145+
app.kubernetes.io/name: azimuth-schedule-operator
146+
spec:
147+
containers:
148+
- env:
149+
- name: AZIMUTH_SCHEDULE_CHECK_INTERVAL_SECONDS
150+
value: "60"
151+
- name: AZIMUTH_LEASE_CHECK_INTERVAL_SECONDS
152+
value: "60"
153+
- name: AZIMUTH_LEASE_DEFAULT_GRACE_PERIOD_SECONDS
154+
value: "600"
155+
- name: AZIMUTH_LEASE_BLAZAR_ENABLED
156+
value: auto
157+
image: ghcr.io/azimuth-cloud/azimuth-schedule-operator:main
158+
imagePullPolicy: IfNotPresent
159+
name: operator
160+
ports:
161+
- containerPort: 8080
162+
name: metrics
163+
protocol: TCP
164+
resources: {}
165+
securityContext:
166+
allowPrivilegeEscalation: false
167+
capabilities:
168+
drop:
169+
- ALL
170+
readOnlyRootFilesystem: true
171+
volumeMounts:
172+
- mountPath: /tmp
173+
name: tmp
174+
securityContext:
175+
runAsNonRoot: true
176+
serviceAccountName: release-name-azimuth-schedule-operator
177+
volumes:
178+
- emptyDir: {}
179+
name: tmp
180+
6: |
181+
apiVersion: v1
182+
kind: Service
183+
metadata:
184+
labels:
185+
app.kubernetes.io/instance: RELEASE-NAME
186+
app.kubernetes.io/managed-by: Helm
187+
app.kubernetes.io/name: azimuth-schedule-operator
188+
app.kubernetes.io/version: main
189+
helm.sh/chart: azimuth-schedule-operator-0.1.0
190+
name: release-name-azimuth-schedule-operator
191+
spec:
192+
ports:
193+
- name: metrics
194+
port: 8080
195+
protocol: TCP
196+
targetPort: metrics
197+
selector:
198+
app.kubernetes.io/instance: RELEASE-NAME
199+
app.kubernetes.io/name: azimuth-schedule-operator
200+
type: ClusterIP
201+
7: |
202+
apiVersion: v1
203+
kind: ServiceAccount
204+
metadata:
205+
labels:
206+
app.kubernetes.io/instance: RELEASE-NAME
207+
app.kubernetes.io/managed-by: Helm
208+
app.kubernetes.io/name: azimuth-schedule-operator
209+
app.kubernetes.io/version: main
210+
helm.sh/chart: azimuth-schedule-operator-0.1.0
211+
name: release-name-azimuth-schedule-operator
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: {}

0 commit comments

Comments
 (0)