Skip to content

Commit da581cf

Browse files
refactor(cf-common): update rbac template (#11)
1 parent 9614198 commit da581cf

File tree

10 files changed

+55
-76
lines changed

10 files changed

+55
-76
lines changed

charts/cf-common-test/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ Codefresh library chart - test chart - not for deployment!
3535
| nodeSelector | object | `{}` | |
3636
| pdb | object | `{}` | |
3737
| podSecurityContext | object | `{}` | |
38-
| rbac.serviceAccount | object | `{}` | |
38+
| rbac | object | `{}` | |
3939
| secrets | object | `{}` | |
4040
| service | object | `{}` | |
41+
| serviceAccount | object | `{}` | |
4142
| tolerations | list | `[]` | |
4243
| volumes | object | `{}` | |
4344

charts/cf-common-test/tests/rbac/metadata_test.yaml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ tests:
77
- it: Test SA default metadata
88
template: rbac.yaml
99
set:
10-
rbac:
10+
serviceAccount:
1111
enabled: true
12-
serviceAccount:
13-
enabled: true
1412
asserts:
1513
- hasDocuments:
1614
count: 1
@@ -32,13 +30,11 @@ tests:
3230
- it: Test SA custom metadata
3331
template: rbac.yaml
3432
set:
35-
rbac:
33+
serviceAccount:
3634
enabled: true
37-
serviceAccount:
38-
enabled: true
39-
nameOverride: "alice"
40-
annotations:
41-
foo: bar
35+
nameOverride: "alice"
36+
annotations:
37+
foo: bar
4238
asserts:
4339
- hasDocuments:
4440
count: 1
@@ -59,10 +55,10 @@ tests:
5955
- it: Test Role default metadata
6056
template: rbac.yaml
6157
set:
58+
serviceAccount:
59+
enabled: true
6260
rbac:
6361
enabled: true
64-
serviceAccount:
65-
enabled: true
6662
rules:
6763
- apiGroups:
6864
- ""
@@ -98,10 +94,10 @@ tests:
9894
- it: Test RoleBinding default metadata
9995
template: rbac.yaml
10096
set:
97+
serviceAccount:
98+
enabled: true
10199
rbac:
102100
enabled: true
103-
serviceAccount:
104-
enabled: true
105101
rules:
106102
- apiGroups:
107103
- ""

charts/cf-common-test/tests/rbac/spec_test.yaml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ tests:
99
values:
1010
- values.yaml
1111
set:
12-
rbac:
12+
serviceAccount:
1313
enabled: true
14-
serviceAccount:
15-
enabled: true
1614
asserts:
1715
- equal:
1816
path: spec.template.spec.serviceAccountName
@@ -22,10 +20,8 @@ tests:
2220
- it: Test SA secret
2321
template: templates/rbac.yaml
2422
set:
25-
rbac:
23+
serviceAccount:
2624
enabled: true
27-
serviceAccount:
28-
enabled: true
2925
asserts:
3026
- contains:
3127
path: secrets
@@ -35,10 +31,10 @@ tests:
3531
- it: Test Role should contains valid rules set
3632
template: rbac.yaml
3733
set:
34+
serviceAccount:
35+
enabled: true
3836
rbac:
3937
enabled: true
40-
serviceAccount:
41-
enabled: true
4238
rules:
4339
- apiGroups:
4440
- ""
@@ -63,10 +59,10 @@ tests:
6359
- it: Test RoleBinding should reference to the correct role and SA
6460
template: rbac.yaml
6561
set:
62+
serviceAccount:
63+
enabled: true
6664
rbac:
6765
enabled: true
68-
serviceAccount:
69-
enabled: true
7066
rules:
7167
- apiGroups:
7268
- ""
@@ -92,11 +88,11 @@ tests:
9288
values:
9389
- values.yaml
9490
set:
91+
serviceAccount:
92+
enabled: true
93+
nameOverride: alice
9594
rbac:
9695
enabled: true
97-
serviceAccount:
98-
enabled: true
99-
nameOverride: alice
10096
rules:
10197
- apiGroups:
10298
- ""
@@ -123,10 +119,8 @@ tests:
123119
values:
124120
- values.yaml
125121
set:
126-
rbac:
122+
serviceAccount:
127123
enabled: false
128-
serviceAccount:
129-
enabled: false
130124
asserts:
131125
- equal:
132126
path: spec.template.spec.serviceAccountName
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mock deployment for HPA
1+
# mock values
22
controller:
33
enabled: true
44
type: deployment
@@ -14,21 +14,7 @@ container:
1414
tag: master
1515
pullPolicy: Always
1616

17-
### comment when you want to see templates with `helm template . -f tests/rbac/values.yaml --show-only templates/rbac.yaml`
17+
serviceAccount:
18+
enabled: true
1819
rbac:
1920
enabled: true
20-
serviceAccount:
21-
enabled: true
22-
# nameOverride: ""
23-
# annotations:
24-
# foo: bar
25-
# rules:
26-
# - apiGroups:
27-
# - ""
28-
# resources:
29-
# - pods
30-
# verbs:
31-
# - get
32-
# - list
33-
# - watch
34-
# - update

charts/cf-common-test/values.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ hpa: {}
1919

2020
pdb: {}
2121

22-
rbac:
23-
serviceAccount: {}
22+
serviceAccount: {}
23+
24+
rbac: {}
2425

2526
podSecurityContext: {}
2627

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.0.10
5+
version: 0.0.11
66
type: library
77
keywords:
88
- codefresh

charts/cf-common/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Codefresh library chart
44

5-
![Version: 0.0.10](https://img.shields.io/badge/Version-0.0.10-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
5+
![Version: 0.0.11](https://img.shields.io/badge/Version-0.0.11-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
66

77
## Installing the Chart
88

@@ -18,7 +18,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
1818
# Chart.yaml
1919
dependencies:
2020
- name: cf-common
21-
version: 0.0.10
21+
version: 0.0.11
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
@@ -105,10 +105,6 @@ dependencies:
105105
| rbac | object | See below | Configure RBAC parameters |
106106
| rbac.enabled | bool | `false` | Enable RBAC resources |
107107
| rbac.rules | list | `[]` | Create custom rules |
108-
| rbac.serviceAccount | object | `{"annotations":{},"enabled":false,"nameOverride":""}` | Configure Service Account |
109-
| rbac.serviceAccount.annotations | object | `{}` | Set annotations for Service Account |
110-
| rbac.serviceAccount.enabled | bool | `false` | Enable Service Account |
111-
| rbac.serviceAccount.nameOverride | string | `""` | Override Service Account name (by default, name is generated with `fullname` template) |
112108
| secrets.secret | object | `{"annotation":{},"data":{},"enabled":false,"labels":{},"stringData":{},"type":"Opaque"}` | Secret name. Make sure to use the same name in `volumes` and `container.volumeMounts` |
113109
| secrets.secret.annotation | object | `{}` | Add additional annotations to the secret |
114110
| secrets.secret.enabled | bool | `false` | Enable the secret |
@@ -128,6 +124,10 @@ dependencies:
128124
| service.main.ports.http.targetPort | string | `nil` | Set a service targetPort if you wish to differ the service port from the application port. |
129125
| service.main.primary | bool | `true` | Make this the primary service (used in probes, notes, etc...). If there is more than 1 service, make sure that only 1 service is marked as primary. |
130126
| service.main.type | string | `"ClusterIP"` | Set the service type |
127+
| serviceAccount | object | See below | Configure Service Account |
128+
| serviceAccount.annotations | object | `{}` | Set annotations for Service Account |
129+
| serviceAccount.enabled | bool | `false` | Enable and create Service Account |
130+
| serviceAccount.nameOverride | string | `""` | Override Service Account name (by default, name is generated with `fullname` template) |
131131
| tolerations | list | `[]` | Set tolerations constrains |
132132
| topologySpreadConstraints | list | `[]` | Set topologySpreadConstraints rules. Helm template supported. Passed through `tpl`, should be configured as string |
133133
| volumes | object | See below | Configure volume for the controller. Additional items can be added by adding a dictionary key similar to the 'config'/`secret` key. |

charts/cf-common/templates/common/_names.tpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ If release name contains chart name it will be used as a full name.
3434
ServiceAccount Name
3535
*/}}
3636
{{- define "cf-common.names.serviceAccountName" -}}
37-
{{- if .Values.rbac.enabled -}}
38-
{{- if .Values.rbac.serviceAccount.enabled -}}
39-
{{- .Values.rbac.serviceAccount.nameOverride | default (include "cf-common.names.fullname" .) -}}
40-
{{- end -}}
37+
{{- if .Values.serviceAccount.enabled -}}
38+
{{- .Values.serviceAccount.nameOverride | default (include "cf-common.names.fullname" .) -}}
4139
{{- else -}}
42-
{{- .Values.rbac.serviceAccount.nameOverride | default "default" -}}
40+
{{- print "default" -}}
4341
{{- end -}}
4442
{{- end -}}

charts/cf-common/templates/render/_rbac.tpl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ Usage:
66

77
{{- define "cf-common.rbac" -}}
88

9-
{{- if and .Values.rbac.enabled .Values.rbac.serviceAccount.enabled }}
9+
{{- if .Values.serviceAccount.enabled }}
1010
---
1111
apiVersion: v1
1212
kind: ServiceAccount
1313
metadata:
14-
name: {{ default ( include "cf-common.names.fullname" $) .Values.rbac.serviceAccount.nameOverride }}
14+
name: {{ default ( include "cf-common.names.fullname" $) .Values.serviceAccount.nameOverride }}
1515
labels: {{ include "cf-common.labels.standard" . | nindent 4 }}
16-
{{- if .Values.rbac.serviceAccount.annotations }}
17-
annotations: {{ include "cf-common.tplrender" (dict "Values" .Values.rbac.serviceAccount.annotations "context" $) | nindent 4 }}
16+
{{- if .Values.serviceAccount.annotations }}
17+
annotations: {{ include "cf-common.tplrender" (dict "Values" .Values.serviceAccount.annotations "context" $) | nindent 4 }}
1818
{{- end }}
1919
secrets:
2020
- name: {{ include "cf-common.names.fullname" $ }}-sa-token
2121
{{- end }}
2222

23-
{{- if and .Values.rbac.enabled .Values.rbac.rules .Values.rbac.serviceAccount.enabled }}
23+
24+
{{- if and .Values.serviceAccount.enabled .Values.rbac.enabled }}
2425
---
2526
apiVersion: rbac.authorization.k8s.io/v1
2627
kind: Role
@@ -40,8 +41,8 @@ roleRef:
4041
apiGroup: rbac.authorization.k8s.io
4142
subjects:
4243
- kind: ServiceAccount
43-
name: {{ default ( include "cf-common.names.fullname" $) .Values.rbac.serviceAccount.nameOverride }}
44+
name: {{ default ( include "cf-common.names.fullname" $) .Values.serviceAccount.nameOverride }}
4445
namespace: {{ .Release.Namespace }}
4546
{{- end }}
4647

47-
{{- end -}}
48+
{{- end -}}

charts/cf-common/values.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,21 @@ pdb:
390390
# -- Set number of pods that are unavailable after eviction as number of percentage
391391
maxUnavailable: ""
392392

393+
# -- Configure Service Account
394+
# @default -- See below
395+
serviceAccount:
396+
# -- Enable and create Service Account
397+
enabled: false
398+
# -- Override Service Account name (by default, name is generated with `fullname` template)
399+
nameOverride: ""
400+
# -- Set annotations for Service Account
401+
annotations: {}
402+
393403
# -- Configure RBAC parameters
394404
# @default -- See below
395405
rbac:
396406
# -- Enable RBAC resources
397407
enabled: false
398-
# -- Configure Service Account
399-
serviceAccount:
400-
# -- Enable Service Account
401-
enabled: false
402-
# -- Override Service Account name (by default, name is generated with `fullname` template)
403-
nameOverride: ""
404-
# -- Set annotations for Service Account
405-
annotations: {}
406408
# -- Create custom rules
407409
rules: []
408410
# E.g.

0 commit comments

Comments
 (0)