Skip to content

Commit

Permalink
Added rbac.existingServiceAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed Aug 29, 2023
1 parent 94b09ee commit b8844b1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions charts/generic-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ app:
| `sidecarTemplates` | `[]` | Strings to be templated providing additional sidecar containers to be added to the Pod |
| `rbac.roles` | `[]` | Namespace-specific Kubernetes RBAC Roles to assign to the service (supports templating) |
| `rbac.clusterRoles` | `[]` | Cluster-wide Kubernetes RBAC Roles to assign to the service (supports templating) |
| `rbac.existingServiceAccount` | | The name of an existing service account to use (instead of automatically creating one for the service) |
| `global.alertLabels` | `{}` | Additional labels to apply to alert rules |
| `global.grafana.url` | | The URL of a Grafana instance with access to the service's metrics |
| `global.grafana.dashboard` | `qqsCbY5Zz` | The UID of the Grafana dashboard visualizing the service's metrics |
Expand Down
8 changes: 8 additions & 0 deletions charts/generic-service/ci/rbac-existing-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# RBAC with existing ServiceAccount test

image:
repository: jwilder/whoami
tag: latest
rbac:
clusterRoles: [view]
existingServiceAccount: default
7 changes: 7 additions & 0 deletions charts/generic-service/ci/rbac-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# RBAC test

image:
repository: jwilder/whoami
tag: latest
rbac:
clusterRoles: [view]
4 changes: 2 additions & 2 deletions charts/generic-service/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ spec:
- name: {{ .Values.image.pullSecret }}
{{- end }}

{{- if or .Values.rbac.roles .Values.rbac.clusterRoles }}
serviceAccountName: {{ include "generic-service.fullname" . }}
{{- if or .Values.rbac.existingServiceAccount (or .Values.rbac.roles .Values.rbac.clusterRoles) }}
serviceAccountName: '{{ .Values.rbac.existingServiceAccount | default (include "generic-service.fullname" .) }}'
{{- end }}

terminationGracePeriodSeconds: {{ .Values.maxShutdownSeconds | int }}
Expand Down
6 changes: 3 additions & 3 deletions charts/generic-service/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ roleRef:
name: {{ tpl . $ }}
subjects:
- kind: ServiceAccount
name: '{{ include "generic-service.fullname" $ }}'
name: '{{ $.Values.rbac.existingServiceAccount | default (include "generic-service.fullname" $) }}'
---
{{- end }}

Expand All @@ -27,12 +27,12 @@ roleRef:
name: {{ tpl . $ }}
subjects:
- kind: ServiceAccount
name: '{{ include "generic-service.fullname" $ }}'
name: '{{ $.Values.rbac.existingServiceAccount | default (include "generic-service.fullname" $) }}'
namespace: '{{ $.Release.Namespace }}'
---
{{- end }}

{{- if or .Values.rbac.roles .Values.rbac.clusterRoles }}
{{- if and (not .Values.rbac.existingServiceAccount) (or .Values.rbac.roles .Values.rbac.clusterRoles) }}
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down
8 changes: 6 additions & 2 deletions charts/generic-service/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,12 +966,16 @@
"roles": {
"type": "array",
"items": {"type": "string"},
"description": "Namespace-specific Kubernetes RBAC Roles to assign to the service"
"description": "Namespace-specific Kubernetes RBAC Roles to assign to the service (supports templating)"
},
"clusterRoles": {
"type": "array",
"items": {"type": "string"},
"description": "Cluster-wide Kubernetes RBAC Roles to assign to the service"
"description": "Cluster-wide Kubernetes RBAC Roles to assign to the service (supports templating)"
},
"existingServiceAccount": {
"type": "string",
"description": "The name of an existing service account to use (instead of automatically creating one for the service)"
}
},
"additionalProperties": false
Expand Down
1 change: 1 addition & 0 deletions charts/generic-service/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ sidecarTemplates: []
rbac:
roles: []
clusterRoles: []
existingServiceAccount: ''

global:
alertLabels: {}
Expand Down

0 comments on commit b8844b1

Please sign in to comment.