Skip to content

Commit 3109625

Browse files
authored
Add Helm chart unit tests (#520)
1 parent 2d94cfa commit 3109625

28 files changed

+1996
-62
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Helm Chart Unit Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'charts/**'
9+
- 'version/VERSION'
10+
push:
11+
branches:
12+
- main
13+
workflow_dispatch:
14+
15+
env:
16+
HELM_CHART_PATH: 'charts/hcp-terraform-operator'
17+
18+
jobs:
19+
tests:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
30+
with:
31+
go-version-file: 'go.mod'
32+
33+
- name: Set up Helm
34+
uses: Azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0
35+
with:
36+
version: v3.11.2
37+
38+
- name: Run unit tests suite [Go]
39+
run: |
40+
make helm-test

CONTRIBUTING.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ There are two main pieces of the Operator `API` and `Controller`. Depending on w
141141

142142
- API:
143143

144-
If your made API-related changes(`/api/**`), please make sure you have updated the tests and always run them:
144+
If your made API-related changes(`/api/**`), please ensure you have updated the tests and always run them:
145145

146146
```console
147147
$ make test-api
148148
```
149149
150150
- Controllers:
151151

152-
We rely on [Ginkgo](https://github.com/onsi/ginkgo) testing framework in our controllers E2E tests. If your made controller-related changes(/controllers/**), please make sure you have updated the tests and always run them.
152+
We rely on [Ginkgo](https://github.com/onsi/ginkgo) testing framework in our controllers E2E tests. If your made controller-related changes(/controllers/**), please ensure you have updated the tests and always run them.
153153

154154
Export the organization name and API token to environment variable:
155155

@@ -172,6 +172,36 @@ There are two main pieces of the Operator `API` and `Controller`. Depending on w
172172

173173
Every test should be executable through a make target, and the target should have a prefix of "test-".
174174

175+
- Helm Chart:
176+
177+
If your made changes to Helm chart (`/charts/**`), please ensure you have updated the tests(`/charts/test/**`) and always run them:
178+
179+
```console
180+
$ make test-helm
181+
```
182+
183+
### Update documentation
184+
185+
- API:
186+
187+
The API documentation is generated from the doc strings associated with the relevant types in (`/api/v1alpha2`) and stored in (`/docs/api-reference.md`). Please ensure you run the following **make** target to update the documentation:
188+
189+
```console
190+
$ make docs
191+
```
192+
193+
- Helm Chart:
194+
195+
The Helm documentation(`/charts/hcp-terraform-operator/README.md`) is generated by [helm-docs](https://github.com/norwoodj/helm-docs). Please make changes _only_ in the `/charts/hcp-terraform-operator/README.md.gotmpl` file.
196+
197+
The Values Table is generated from the comment strings associated with the relevant values in the `/charts/hcp-terraform-operator/values.yaml` file.
198+
199+
Please ensure you run the following **make** target to update the Helm chart documentation:
200+
201+
```console
202+
$ make helm-docs
203+
```
204+
175205
### Write a changelog
176206

177207
We use the [Changie](https://changie.dev/) automation tool for changelog management.
@@ -188,13 +218,17 @@ Ensure that the generated files are pushed to the repository along with any code
188218

189219
## Submitting Changes
190220

221+
### Creating a Issue
222+
223+
If you are working on an already reported issue, you can skip this step. Otherwise, please report the issue you intend to work on before proposing any changes. _**This step is mandatory regardless of the size or scope of the change you want to make**_.
224+
191225
### Creating a Pull Request
192226

193227
We're excited that you're ready to contribute to the Operator by creating a pull request (PR)! Pull requests are a fundamental way to propose and discuss changes with the project maintainers and contributors.
194228

195229
1. **Description**: write a detailed description of your changes. Keep in mind, that it should be clear why you make this change, what you have changed, and how this will affect the Operator users. If you are working on a fix for an existing issue, you can provide less details about it.
196230

197-
1. **Usage Example**: if your change is API-related, make sure you have provided **Before** and **After** usage examples.
231+
1. **Usage Example**: if your change is API-related, ensure you have provided **Before** and **After** usage examples.
198232

199233
1. **References**: if you fix an existing issue, please provide a reference to it by using a relevant [GitHub keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
200234

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ docs: crd-ref-docs ## Generate API reference documentation.
105105
helm-docs: install-helm-docs ## Generate Helm chart documentation.
106106
$(HELM_DOCS) --log-level=debug --chart-search-root=./charts/hcp-terraform-operator/
107107

108+
.PHONY: helm-test
109+
helm-test: test-helm ## Run Helm chart tests. This is an alias for the test-helm target.
110+
108111
##@ Development
109112

110113
.PHONY: manifests
@@ -145,6 +148,10 @@ test-internal: fmt vet copywrite ## Run internal/* tests.
145148
./internal/pointer \
146149
./internal/slice
147150

151+
.PHONY: test-helm
152+
test-helm: ## Run Helm chart tests.
153+
cd charts/test; go test -timeout 5m -count=1 -v ./...
154+
148155
.PHONY: lint
149156
lint: golangci-lint ## Run golangci-lint linter & yamllint
150157
$(GOLANGCI_LINT) run

charts/hcp-terraform-operator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ For a more detailed explanation, please refer to the [FAQ](../../docs/faq.md#gen
184184
| operator.watchedNamespaces | list | `[]` | List of namespaces the controllers should watch. |
185185
| podLabels | object | `{}` | Additional labels to add to the Operator pods. |
186186
| priorityClassName | string | `""` | Deployment priorityClassName. More information in [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/). |
187-
| rbac.create | bool | `true` | Specifies whether a Role-Based Access Control (RBAC) resources should be created |
187+
| rbac.create | bool | `true` | Specifies whether a Role-Based Access Control (RBAC) resources should be created. |
188188
| replicaCount | int | `2` | The number of Operator replicas. |
189189
| securityContext | object | `{"runAsNonRoot":true}` | Deployment pod security context. More information in [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/). |
190190
| serviceAccount.annotations | object | `{}` | Additional annotations for the ServiceAccount. |

charts/hcp-terraform-operator/templates/clusterrole.yaml renamed to charts/hcp-terraform-operator/templates/clusterrole_manager.yaml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
{{- if .Values.rbac.create -}}
12
# Copyright (c) HashiCorp, Inc.
23
# SPDX-License-Identifier: MPL-2.0
3-
---
4-
{{- if .Values.rbac.create -}}
4+
55
apiVersion: rbac.authorization.k8s.io/v1
66
kind: ClusterRole
77
metadata:
@@ -72,32 +72,4 @@ rules:
7272
- patch
7373
- update
7474
- watch
75-
---
76-
apiVersion: rbac.authorization.k8s.io/v1
77-
kind: ClusterRole
78-
metadata:
79-
name: {{ .Release.Name }}-metrics-reader
80-
rules:
81-
- nonResourceURLs:
82-
- /metrics
83-
verbs:
84-
- get
85-
---
86-
apiVersion: rbac.authorization.k8s.io/v1
87-
kind: ClusterRole
88-
metadata:
89-
name: {{ .Release.Name }}-proxy-role
90-
rules:
91-
- apiGroups:
92-
- authentication.k8s.io
93-
resources:
94-
- tokenreviews
95-
verbs:
96-
- create
97-
- apiGroups:
98-
- authorization.k8s.io
99-
resources:
100-
- subjectaccessreviews
101-
verbs:
102-
- create
10375
{{- end -}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.rbac.create -}}
2+
# Copyright (c) HashiCorp, Inc.
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
apiVersion: rbac.authorization.k8s.io/v1
6+
kind: ClusterRole
7+
metadata:
8+
name: {{ .Release.Name }}-metrics-reader
9+
rules:
10+
- nonResourceURLs:
11+
- /metrics
12+
verbs:
13+
- get
14+
{{- end -}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{- if .Values.rbac.create -}}
2+
# Copyright (c) HashiCorp, Inc.
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
apiVersion: rbac.authorization.k8s.io/v1
6+
kind: ClusterRole
7+
metadata:
8+
name: {{ .Release.Name }}-proxy-role
9+
rules:
10+
- apiGroups:
11+
- authentication.k8s.io
12+
resources:
13+
- tokenreviews
14+
verbs:
15+
- create
16+
- apiGroups:
17+
- authorization.k8s.io
18+
resources:
19+
- subjectaccessreviews
20+
verbs:
21+
- create
22+
{{- end -}}

charts/hcp-terraform-operator/templates/clusterrolebinding.yaml renamed to charts/hcp-terraform-operator/templates/clusterrolebinding_manager.yaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
{{- if .Values.rbac.create -}}
12
# Copyright (c) HashiCorp, Inc.
23
# SPDX-License-Identifier: MPL-2.0
3-
---
4-
{{- if .Values.rbac.create -}}
4+
55
apiVersion: rbac.authorization.k8s.io/v1
66
kind: ClusterRoleBinding
77
metadata:
@@ -11,19 +11,6 @@ roleRef:
1111
kind: ClusterRole
1212
name: {{ .Release.Name }}-manager-role
1313
subjects:
14-
- kind: ServiceAccount
15-
name: {{ include "hcp-terraform-operator.serviceAccountName" . }}
16-
namespace: {{ .Release.Namespace }}
17-
---
18-
apiVersion: rbac.authorization.k8s.io/v1
19-
kind: ClusterRoleBinding
20-
metadata:
21-
name: {{ .Release.Name }}-proxy-rolebinding
22-
roleRef:
23-
apiGroup: rbac.authorization.k8s.io
24-
kind: ClusterRole
25-
name: {{ .Release.Name }}-proxy-role
26-
subjects:
2714
- kind: ServiceAccount
2815
name: {{ include "hcp-terraform-operator.serviceAccountName" . }}
2916
namespace: {{ .Release.Namespace }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- if .Values.rbac.create -}}
2+
# Copyright (c) HashiCorp, Inc.
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
apiVersion: rbac.authorization.k8s.io/v1
6+
kind: ClusterRoleBinding
7+
metadata:
8+
name: {{ .Release.Name }}-proxy-rolebinding
9+
roleRef:
10+
apiGroup: rbac.authorization.k8s.io
11+
kind: ClusterRole
12+
name: {{ .Release.Name }}-proxy-role
13+
subjects:
14+
- kind: ServiceAccount
15+
name: {{ include "hcp-terraform-operator.serviceAccountName" . }}
16+
namespace: {{ .Release.Namespace }}
17+
{{- end -}}

charts/hcp-terraform-operator/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
{{- include "hcp-terraform-operator.selectorLabels" . | nindent 8 }}
2222
control-plane: {{ .Release.Name }}-controller-manager
2323
{{- with .Values.podLabels }}
24-
{{- tpl (toYaml .) $ | nindent 8 }}
24+
{{- toYaml . | nindent 8 }}
2525
{{- end }}
2626
spec:
2727
{{- with .Values.priorityClassName }}

0 commit comments

Comments
 (0)