Skip to content

Commit

Permalink
Add template for ServiceAccount annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Dueck <chris.dueck@wattpad.com>
  • Loading branch information
crdueck authored and eshepelyuk committed Nov 3, 2023
1 parent e862159 commit 358f1cc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions charts/opa-kube-mgmt/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "opa.serviceAccountName" .}}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{ toYaml . }}
{{- end }}
labels:
app: {{ template "opa.fullname" . }}
chart: {{ template "opa.chart" . }}
Expand Down
8 changes: 8 additions & 0 deletions charts/opa-kube-mgmt/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
"enabled": {"type": "boolean", "default": true},
"image": {"$ref": "#/definitions/image"}
}
},
"serviceAccount": {
"type": "object",
"properties": {
"create": {"type": "boolean", "default": true},
"annotations": {"type": "object", "additionalProperties": {"type": "string"}, "default": {}},
"name": {"type": ["string", "null"], "default": null}
}
}
}
}
2 changes: 2 additions & 0 deletions charts/opa-kube-mgmt/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ rbac:
serviceAccount:
# Specifies whether a ServiceAccount should be created
create: true
# Annotations for the ServiceAccount
annotations: {}
# The name of the ServiceAccount to use.
# If not set and create is true, a name is generated using the fullname template
name:
Expand Down
15 changes: 15 additions & 0 deletions test/lint/sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
suite: lint serviceaccount
templates:
- fake.yaml
tests:
- it: annotations not string
set:
serviceAccount:
annotations:
foo: 1
asserts:
- failedTemplate:
errorMessage: |
values don't meet the specifications of the schema(s) in the following chart(s):
opa-kube-mgmt:
- serviceAccount.annotations.foo: Invalid type. Expected: string, given: integer
19 changes: 19 additions & 0 deletions test/unit/sa_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
suite: test serviceaccount annotations
templates:
- serviceaccount.yaml
tests:
- it: should omit serviceaccount annotations by default
asserts:
- notExists:
path: metadata.annotations
- it: should render serviceaccount annotations when provided
set:
serviceAccount:
annotations:
foo: bar
asserts:
- exists:
path: metadata.annotations
- equal:
path: metadata.annotations.foo
value: bar

0 comments on commit 358f1cc

Please sign in to comment.