Skip to content

Commit

Permalink
fix(generic): configure ServiceAccount when name is set or creation i…
Browse files Browse the repository at this point in the history
…s enabled
  • Loading branch information
morremeyer committed Sep 9, 2024
1 parent 081c089 commit 8d1cac3
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ jobs:
# renovate: datasource=github-releases depName=helm/helm
version: v3.15.4

- name: Install needed tools
run: make install

- name: Run unittests
run: helm unittest charts/*

- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5
with:
python-version: 3.12.5
Expand All @@ -42,7 +48,7 @@ jobs:

- name: Install CRDs
if: steps.list-changed.outputs.changed == 'true'
run: ./ci/setup.sh
run: ./ci/setup

- name: Run chart-testing (install)
run: ct install --config ct.yaml
15 changes: 15 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "pre-commit"

on:
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup for pre-commit
run: make install

- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ repos:
- id: commitlint
stages: [commit-msg]
additional_dependencies: ["@commitlint/config-conventional"]

- repo: local
hooks:
- id: helm unittest
name: Run helm unittests
language: script
pass_filenames: false
entry: ./ci/helm-unittest
files: ^charts/.*
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pip3 install pre-commit
# macOS
brew install pre-commit

# Install the unittest plugin
make install

pre-commit install --hook-type commit-msg --hook-type pre-commit
```

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SHELL := /bin/bash -o pipefail -o errexit

install:
helm plugin install https://github.com/helm-unittest/helm-unittest
2 changes: 1 addition & 1 deletion charts/generic/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: generic
description: A chart for generic applications. Use this if you need to deploy something without wanting to build a fully fledged new helm chart.
type: application
version: 7.6.0
version: 7.6.1
maintainers:
- name: morremeyer
- name: ekeih
2 changes: 1 addition & 1 deletion charts/generic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generic

![Version: 7.6.0](https://img.shields.io/badge/Version-7.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 7.6.1](https://img.shields.io/badge/Version-7.6.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

A chart for generic applications. Use this if you need to deploy something without wanting to build a fully fledged new helm chart.

Expand Down
2 changes: 1 addition & 1 deletion charts/generic/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets: {{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.serviceAccount.create }}
{{- if or .Values.serviceAccount.create .Values.serviceAccount.name }}
serviceAccountName: {{ include "generic.serviceAccountName" . }}
{{- end }}
{{- with .Values.podSecurityContext }}
Expand Down
36 changes: 36 additions & 0 deletions charts/generic/tests/serviceaccount_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
suite: test ServiceAccount
templates:
- templates/deployment.yaml
release:
name: test-release
namespace: test-namespace
tests:
- it: "verifies that the default configuration sets the ServiceAccount name"
asserts:
- equal:
path: spec.template.spec.serviceAccountName
value: test-release-generic

- it: "verifies that configuring the ServiceAccount name sets it accordingly"
set:
serviceAccount.name: test-sa
asserts:
- equal:
path: spec.template.spec.serviceAccountName
value: test-sa

- it: "verifies that configuring a ServiceAccount name with create: false still sets ServiceAccount"
set:
serviceAccount.create: false
serviceAccount.name: test-sa
asserts:
- equal:
path: spec.template.spec.serviceAccountName
value: test-sa

- it: "verifies that not setting a name with create: false does not set a ServiceAccount"
set:
serviceAccount.create: false
asserts:
- notExists:
path: spec.template.spec.serviceAccountName
2 changes: 2 additions & 0 deletions ci/helm-unittest
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
ls -1 charts | xargs -I {} helm unittest "charts/{}"
File renamed without changes.

0 comments on commit 8d1cac3

Please sign in to comment.