Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to specify externally created service account and just to override sa name without overriding fullname from tpl #192

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
env:
# UPDATE_HERE
# https://hub.docker.com/r/rancher/k3s/tags
K3S_VERSION: v1.31.1-k3s1
K3S_VERSION: v1.31.2-k3s1
# https://github.com/helm-unittest/helm-unittest/releases
HELM_UNITTEST_VERSION: 0.6.2
HELM_UNITTEST_VERSION: 0.6.3

steps:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ encrypted files stored in `git` repository.

| Kubernetes | Sops | Chart | Operator |
|---|---|---|---|
| v1.31.x | v3.9.1 | 0.20.2 | 0.14.1 |
| v1.31.x | v3.9.1 | 0.20.3 | 0.14.1 |
| v1.30.x | v3.9.0 | 0.19.4 | 0.13.3 |
| v1.29.x | v3.8.1 | 0.18.6 | 0.12.6 |
| v1.28.x | v3.8.1 | 0.17.4 | 0.11.4 |
Expand Down
2 changes: 1 addition & 1 deletion chart/helm3/sops-secrets-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
# UPDATE_HERE
version: 0.20.2
version: 0.20.3
appVersion: 0.14.1
type: application
description: Helm chart deploys sops-secrets-operator
Expand Down
2 changes: 2 additions & 0 deletions chart/helm3/sops-secrets-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ The following table lists the configurable parameters of the Sops-secrets-operat
| securityContext.seccompProfileName | string | `""` | if seccompProfile.type is set to Localhost, set localhostProfile to value of seccompProfileName (user must specify value) |
| securityContext.seccompProfileType | string | `"RuntimeDefault"` | seccompProfile.type |
| serviceAccount.annotations | object | `{}` | Annotations to be added to the service account |
| serviceAccount.enabled | bool | `true` | |
| serviceAccount.name | string | `""` | Custom service account name to use instead of automatically generated name (if enabled - chart will generate SA, if not enabled - will use preconfigured) |
| tolerations | list | `[]` | Tolerations to be applied to operator pod |

Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metadata:
{{ include "sops-secrets-operator.labels" . | indent 4 }}
subjects:
- kind: ServiceAccount
name: {{ include "sops-secrets-operator.fullname" . }}
name: {{ .Values.serviceAccount.name | default (tpl ( include "sops-secrets-operator.fullname" . ) .) }}
namespace: {{ .Release.Namespace }}
roleRef:
{{- if .Values.namespaced }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "sops-secrets-operator.fullname" . }}
serviceAccountName: {{ .Values.serviceAccount.name | default (tpl ( include "sops-secrets-operator.fullname" . ) .) }}
{{- if .Values.gpg.enabled }}
initContainers:
- name: init-myservice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if .Values.rbac.enabled }}
{{- if (and .Values.rbac.enabled .Values.serviceAccount.enabled) }}
apiVersion: v1
kind: ServiceAccount
metadata:
{{- with .Values.serviceAccount.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
name: {{ include "sops-secrets-operator.fullname" . }}
name: {{ .Values.serviceAccount.name | default (tpl ( include "sops-secrets-operator.fullname" . ) .) }}
labels:
{{ include "sops-secrets-operator.labels" . | indent 4 }}
{{- end }}
3 changes: 3 additions & 0 deletions chart/helm3/sops-secrets-operator/templates/validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if and (not .Values.serviceAccount.enabled) (not .Values.serviceAccount.name) }}
{{- fail "Error: serviceAccount 'name' must be set if serviceAccount 'enabled' is set to false" }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ tests:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: sops-secrets-operator
app.kubernetes.io/version: "0.14.1"
helm.sh/chart: sops-secrets-operator-0.20.2
helm.sh/chart: sops-secrets-operator-0.20.3
custom-label: custom-value
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tests:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: sops-secrets-operator
app.kubernetes.io/version: 0.14.1
helm.sh/chart: sops-secrets-operator-0.20.2
helm.sh/chart: sops-secrets-operator-0.20.3

# custom name
- it: should correctly render custome name
Expand Down
103 changes: 103 additions & 0 deletions chart/helm3/sops-secrets-operator/tests/service_account_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
suite: operator service account tests
templates:
- service_account.yaml

tests:

# api
- it: should set correct kind and apiVersion
asserts:
- isKind:
of: ServiceAccount
- isAPIVersion:
of: v1
- hasDocuments:
count: 1

# deployment metadata and labels
- it: should correctly render default service account metadata
release:
name: sops
namespace: sops
asserts:
- equal:
path: metadata.name
value: sops-sops-secrets-operator
- equal:
path: metadata.labels
# UPDATE_HERE
value:
app.kubernetes.io/instance: sops
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: sops-secrets-operator
app.kubernetes.io/version: 0.14.1
helm.sh/chart: sops-secrets-operator-0.20.3

# custom name
- it: should correctly render custome service account name
release:
name: sops
namespace: sops
set:
serviceAccount:
name: AzureSA
asserts:
- equal:
path: metadata.name
value: AzureSA

# sa disabled
- it: should not render service account if disabled
release:
name: sops
namespace: sops
set:
serviceAccount:
enabled: false
asserts:
- hasDocuments:
count: 0

# rbac disabled
- it: should not render service account if rbac disabled
release:
name: sops
namespace: sops
set:
rbac:
enabled: false
asserts:
- hasDocuments:
count: 0

# both sa and rbac are disabled
- it: should not render service account if rbac and sa are disabled
release:
name: sops
namespace: sops
set:
serviceAccount:
enabled: false
rbac:
enabled: false
asserts:
- hasDocuments:
count: 0

# sa empty annotations
- it: sa annotations should be empty by default
asserts:
- notExists:
path: metadata.annotations

# sa annotations
- it: sa annotations should be empty by default
set:
serviceAccount:
annotations:
abc: "abc"
asserts:
- equal:
path: metadata.annotations
value:
abc: abc
30 changes: 30 additions & 0 deletions chart/helm3/sops-secrets-operator/tests/validation_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
suite: "Validation Tests"

templates:
- "templates/validation.yaml"

tests:
- it: "should succeed if '.serviceAccount.enabled' is true (default case)"
set:
serviceAccount:
enabled: true
name:
asserts:
- notFailedTemplate: {}

- it: "should succeed if '.serviceAccount.enabled' is false and 'name' is set"
set:
serviceAccount:
enabled: false
name: "AzureSA"
asserts:
- notFailedTemplate: {}

- it: "should fail if '.serviceAccount.enabled' is false and '.serviceAccount.name' is not set"
set:
serviceAccount:
enabled: false
name: ""
asserts:
- failedTemplate:
errorMessage: "Error: serviceAccount 'name' must be set if serviceAccount 'enabled' is set to false"
3 changes: 3 additions & 0 deletions chart/helm3/sops-secrets-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ podAnnotations: {}
podLabels: {}

serviceAccount:
enabled: true
# -- Custom service account name to use instead of automatically generated name (if enabled - chart will generate SA, if not enabled - will use preconfigured)
name: ""
# -- Annotations to be added to the service account
annotations: {}

Expand Down
Loading