diff --git a/templates/sync-catalog-deployment.yaml b/templates/sync-catalog-deployment.yaml index 937891d62..674d0d8e6 100644 --- a/templates/sync-catalog-deployment.yaml +++ b/templates/sync-catalog-deployment.yaml @@ -1,4 +1,5 @@ # The deployment for running the Connect sidecar injector +{{- $rbacEnabled := (or (and (ne (.Values.syncCatalog.rbac.enabled | toString) "-") .Values.syncCatalog.rbac.enabled) (and (eq (.Values.syncCatalog.rbac.enabled | toString) "-") .Values.global.enabled)) }} {{- if (or (and (ne (.Values.syncCatalog.enabled | toString) "-") .Values.syncCatalog.enabled) (and (eq (.Values.syncCatalog.enabled | toString) "-") .Values.global.enabled)) }} apiVersion: apps/v1 kind: Deployment @@ -25,6 +26,9 @@ spec: release: {{ .Release.Name }} component: sync-catalog spec: + {{- if $rbacEnabled }} + serviceAccountName: {{ template "consul.fullname" . }}:sync-catalog + {{- end }} containers: - name: consul-sync-catalog image: "{{ default .Values.global.imageK8S .Values.syncCatalog.image }}" diff --git a/templates/sync-cluster-role-binding.yaml b/templates/sync-cluster-role-binding.yaml index a7787f23d..2c7950f75 100644 --- a/templates/sync-cluster-role-binding.yaml +++ b/templates/sync-cluster-role-binding.yaml @@ -4,7 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: consul:sync + name: {{ template "consul.fullname" . }}:sync-catalog labels: app: {{ template "consul.name" . }} chart: {{ template "consul.chart" . }} @@ -13,9 +13,9 @@ metadata: roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: consul:sync + name: {{ template "consul.fullname" . }}:sync-catalog subjects: - - kind: Group - name: system:serviceaccounts:{{ .Release.Namespace }} - apiGroup: rbac.authorization.k8s.io + - kind: ServiceAccount + name: {{ template "consul.fullname" . }}:sync-catalog + namespace: {{ .Release.Namespace }} {{- end }} diff --git a/templates/sync-cluster-role.yaml b/templates/sync-cluster-role.yaml index 18ef732dc..2458bfff1 100644 --- a/templates/sync-cluster-role.yaml +++ b/templates/sync-cluster-role.yaml @@ -4,7 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: consul:sync + name: {{ template "consul.fullname" . }}:sync-catalog labels: app: {{ template "consul.name" . }} chart: {{ template "consul.chart" . }} diff --git a/test/unit/sync-catalog-deployment.bats b/test/unit/sync-catalog-deployment.bats index c9f0f30bd..c7079e60c 100755 --- a/test/unit/sync-catalog-deployment.bats +++ b/test/unit/sync-catalog-deployment.bats @@ -149,3 +149,17 @@ load _helpers yq '.spec.template.spec.containers[0].command | any(contains("-k8s-service-prefix=\"foo-\""))' | tee /dev/stderr) [ "${actual}" = "true" ] } + +#-------------------------------------------------------------------- +# serviceAccount + +@test "syncCatalog/Deployment: serviceAccount set with rbac.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/sync-catalog-deployment.yaml \ + --set 'syncCatalog.enabled=true' \ + --set 'syncCatalog.rbac.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.serviceAccountName | contains("sync-catalog")' | tee /dev/stderr) + [ "${actual}" = "true" ] +}