Skip to content

Commit 25cf311

Browse files
committed
Set up controller-gen to generate the RBAC config in the Helm chart
1 parent 71aaa24 commit 25cf311

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed

helm/.helmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
.idea/
2222
*.tmproj
2323
.vscode/
24+
# helper scripts
25+
helmify.sh

helm/helmify.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# This script is used to tweak manifests generated by controller-gen to make them
4+
# compatible with the rest of the chart.
5+
#
6+
# It is not intended to be run directly, but is invoked when running `go generate ./...`
7+
8+
here=$(realpath "$(dirname "$0")")
9+
10+
# this mv is a hack; it will no longer be necessary once controller-gen supports
11+
# specifying the filename; see https://github.com/kubernetes-sigs/controller-tools/pull/1169
12+
mv "$here"/templates/role.yaml "$here"/templates/controller.static.rbac.yaml
13+
printf "%s\n%s\n%s\n" \
14+
'{{- if eq .Values.rbac.mode "aggregation" }}' \
15+
"$(sed -E "s/name: kro:(.*)/name: '{{ include \"kro.fullname\" . }}:\1'/" "$here"/templates/controller.static.rbac.yaml)" \
16+
'{{- end }}' > temp && mv temp "$here"/templates/controller.static.rbac.yaml

helm/templates/cluster-role.yaml renamed to helm/templates/controller.rbac.yaml

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,53 +31,4 @@ aggregationRule:
3131
clusterRoleSelectors:
3232
- matchLabels:
3333
'rbac.kro.run/aggregate-to-controller': "true"
34-
---
35-
apiVersion: rbac.authorization.k8s.io/v1
36-
kind: ClusterRole
37-
metadata:
38-
annotations:
39-
kubernetes.io/description: |
40-
This ClusterRole grants access for the kro controller to resources it always needs access to.
41-
labels:
42-
{{- include "kro.labels" . | nindent 4 }}
43-
rbac.kro.run/aggregate-to-controller: "true"
44-
name: {{ include "kro.fullname" . }}:controller:static
45-
rules:
46-
- apiGroups:
47-
- kro.run
48-
resources:
49-
- resourcegraphdefinitions
50-
verbs:
51-
- create
52-
- delete
53-
- get
54-
- list
55-
- patch
56-
- update
57-
- watch
58-
- apiGroups:
59-
- kro.run
60-
resources:
61-
- resourcegraphdefinitions/finalizers
62-
verbs:
63-
- update
64-
- apiGroups:
65-
- kro.run
66-
resources:
67-
- resourcegraphdefinitions/status
68-
verbs:
69-
- get
70-
- patch
71-
- update
72-
- apiGroups:
73-
- apiextensions.k8s.io
74-
resources:
75-
- customresourcedefinitions
76-
verbs:
77-
- get
78-
- list
79-
- watch
80-
- patch
81-
- update
82-
- delete
8334
{{- end }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if eq .Values.rbac.mode "aggregation" }}
2+
---
3+
apiVersion: rbac.authorization.k8s.io/v1
4+
kind: ClusterRole
5+
metadata:
6+
name: '{{ include "kro.fullname" . }}:controller:static'
7+
rules:
8+
- apiGroups:
9+
- kro.run
10+
resources:
11+
- resourcegraphdefinitions
12+
verbs:
13+
- create
14+
- delete
15+
- get
16+
- list
17+
- patch
18+
- update
19+
- watch
20+
- apiGroups:
21+
- kro.run
22+
resources:
23+
- resourcegraphdefinitions/finalizers
24+
verbs:
25+
- update
26+
- apiGroups:
27+
- kro.run
28+
resources:
29+
- resourcegraphdefinitions/status
30+
verbs:
31+
- get
32+
- patch
33+
- update
34+
{{- end }}

pkg/codegen.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package pkg
2+
3+
//go:generate go tool controller-gen rbac:roleName="kro:controller:static" crd paths="../..." output:crd:artifacts:config=../helm/crds output:rbac:artifacts:config=../helm/templates
4+
//go:generate ../helm/helmify.sh

0 commit comments

Comments
 (0)