Skip to content

Commit d229b82

Browse files
committed
chore(informer): Configure controller-runtime to not use shared list+watch informer for secrets
Signed-off-by: Hayden Roszell <[email protected]>
1 parent 1e05c5e commit d229b82

File tree

14 files changed

+70
-141
lines changed

14 files changed

+70
-141
lines changed

cmd/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ import (
2828
_ "k8s.io/client-go/plugin/pkg/client/auth"
2929
"k8s.io/utils/clock"
3030

31+
corev1 "k8s.io/api/core/v1"
3132
"k8s.io/apimachinery/pkg/runtime"
3233
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3334
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3435
ctrl "sigs.k8s.io/controller-runtime"
36+
"sigs.k8s.io/controller-runtime/pkg/cache"
37+
"sigs.k8s.io/controller-runtime/pkg/client"
3538
"sigs.k8s.io/controller-runtime/pkg/healthz"
3639
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3740
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -122,10 +125,18 @@ func main() {
122125
}
123126
}
124127

128+
var cacheOpts cache.Options
125129
if secretAccessGrantedAtClusterLevel {
126-
setupLog.Info("expecting secret access at cluster level")
130+
setupLog.Info("expecting SA to have Get+List+Watch permissions for corev1 Secret resources at cluster level")
127131
} else {
128-
setupLog.Info(fmt.Sprintf("expecting secret access at namespace level (%s)", clusterResourceNamespace))
132+
setupLog.Info(fmt.Sprintf("expecting SA to have Get+List+Watch permissions for corev1 Secret resources in the %q namespace", clusterResourceNamespace))
133+
cacheOpts = cache.Options{
134+
ByObject: map[client.Object]cache.ByObject{
135+
&corev1.Secret{}: {
136+
Namespaces: map[string]cache.Config{clusterResourceNamespace: cache.Config{}},
137+
},
138+
},
139+
}
129140
}
130141

131142
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
@@ -135,6 +146,7 @@ func main() {
135146
SecureServing: secureMetrics,
136147
TLSOpts: tlsOpts,
137148
},
149+
Cache: cacheOpts,
138150
WebhookServer: webhookServer,
139151
HealthProbeBindAddress: probeAddr,
140152
LeaderElection: enableLeaderElection,

deploy/charts/command-cert-manager-issuer/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,4 @@ The following table lists the configurable parameters of the `command-cert-manag
8585
| `resources` | CPU/Memory resource requests/limits | `{}` (with commented out options) |
8686
| `nodeSelector` | Node labels for pod assignment | `{}` |
8787
| `tolerations` | Tolerations for pod assignment | `[]` |
88-
| `secureMetrics.enabled` | Whether to enable and configure the kube-rbac-proxy sidecar for authorized and authenticated use of the /metrics endpoint by Prometheus. | `false` |
8988
| `secretConfig.useClusterRoleForSecretAccess` | Specifies if the ServiceAccount should be granted access to the Secret resource using a ClusterRole | `false` |

deploy/charts/command-cert-manager-issuer/templates/clusterrole.yaml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,37 +45,3 @@ rules:
4545
- issuers/finalizers
4646
verbs:
4747
- update
48-
{{- if .Values.secureMetrics.enabled }}
49-
---
50-
apiVersion: rbac.authorization.k8s.io/v1
51-
kind: ClusterRole
52-
metadata:
53-
labels:
54-
{{- include "command-cert-manager-issuer.labels" . | nindent 4 }}
55-
name: {{ include "command-cert-manager-issuer.name" . }}-proxy-role
56-
rules:
57-
- apiGroups:
58-
- authentication.k8s.io
59-
resources:
60-
- tokenreviews
61-
verbs:
62-
- create
63-
- apiGroups:
64-
- authorization.k8s.io
65-
resources:
66-
- subjectaccessreviews
67-
verbs:
68-
- create
69-
---
70-
apiVersion: rbac.authorization.k8s.io/v1
71-
kind: ClusterRole
72-
metadata:
73-
labels:
74-
{{- include "command-cert-manager-issuer.labels" . | nindent 4 }}
75-
name: {{ include "command-cert-manager-issuer.name" . }}-metrics-reader
76-
rules:
77-
- nonResourceURLs:
78-
- /metrics
79-
verbs:
80-
- get
81-
{{- end }}

deploy/charts/command-cert-manager-issuer/templates/clusterrolebinding.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,3 @@ subjects:
1212
- kind: ServiceAccount
1313
name: {{ include "command-cert-manager-issuer.serviceAccountName" . }}
1414
namespace: {{ .Release.Namespace }}
15-
{{- if .Values.secureMetrics.enabled }}
16-
---
17-
apiVersion: rbac.authorization.k8s.io/v1
18-
kind: ClusterRoleBinding
19-
metadata:
20-
labels:
21-
{{- include "command-cert-manager-issuer.labels" . | nindent 4 }}
22-
name: {{ include "command-cert-manager-issuer.name" . }}-proxy-rolebinding
23-
roleRef:
24-
apiGroup: rbac.authorization.k8s.io
25-
kind: ClusterRole
26-
name: {{ include "command-cert-manager-issuer.name" . }}-proxy-role
27-
subjects:
28-
- kind: ServiceAccount
29-
name: {{ include "command-cert-manager-issuer.serviceAccountName" . }}
30-
namespace: {{ .Release.Namespace }}
31-
{{- end }}

deploy/charts/command-cert-manager-issuer/templates/deployment.yaml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ spec:
1717
{{- end }}
1818
labels:
1919
{{- include "command-cert-manager-issuer.selectorLabels" . | nindent 8 }}
20+
{{- with .Values.podLabels }}
21+
{{- toYaml . | nindent 8 }}
22+
{{- end }}
2023
spec:
2124
{{- with .Values.imagePullSecrets }}
2225
imagePullSecrets:
@@ -26,31 +29,6 @@ spec:
2629
securityContext:
2730
{{- toYaml .Values.podSecurityContext | nindent 8 }}
2831
containers:
29-
{{- if .Values.secureMetrics.enabled }}
30-
- args:
31-
- --secure-listen-address=0.0.0.0:8443
32-
- --upstream=http://127.0.0.1:8080/
33-
- --logtostderr=true
34-
- --v=0
35-
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.1
36-
name: kube-rbac-proxy
37-
ports:
38-
- containerPort: 8443
39-
name: https
40-
protocol: TCP
41-
resources:
42-
limits:
43-
cpu: 500m
44-
memory: 128Mi
45-
requests:
46-
cpu: 5m
47-
memory: 64Mi
48-
securityContext:
49-
allowPrivilegeEscalation: false
50-
capabilities:
51-
drop:
52-
- ALL
53-
{{- end }}
5432
- args:
5533
- --health-probe-bind-address=:8081
5634
- --metrics-bind-address=127.0.0.1:8080

deploy/charts/command-cert-manager-issuer/templates/role.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@ rules:
2323
- events
2424
verbs:
2525
- create
26-
- patch
26+
- patch
27+
---
28+
apiVersion: rbac.authorization.k8s.io/v1
29+
kind: {{ if .Values.secretConfig.useClusterRoleForSecretAccess }}ClusterRole{{ else }}Role{{ end }}
30+
metadata:
31+
labels:
32+
{{- include "command-cert-manager-issuer.labels" . | nindent 4 }}
33+
name: {{ include "command-cert-manager-issuer.name" . }}-secret-reader-role
34+
rules:
35+
- apiGroups:
36+
- ""
37+
resources:
38+
- secrets
39+
verbs:
40+
- get
41+
- list
42+
- watch

deploy/charts/command-cert-manager-issuer/templates/rolebinding.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ roleRef:
1111
subjects:
1212
- kind: ServiceAccount
1313
name: {{ include "command-cert-manager-issuer.serviceAccountName" . }}
14-
namespace: {{ .Release.Namespace }}
14+
namespace: {{ .Release.Namespace }}
15+
---
16+
apiVersion: rbac.authorization.k8s.io/v1
17+
kind: {{ if .Values.secretConfig.useClusterRoleForSecretAccess }}ClusterRoleBinding{{ else }}RoleBinding{{ end }}
18+
metadata:
19+
labels:
20+
{{- include "command-cert-manager-issuer.labels" . | nindent 4 }}
21+
name: {{ include "command-cert-manager-issuer.name" . }}-secret-reader-rolebinding
22+
roleRef:
23+
apiGroup: rbac.authorization.k8s.io
24+
kind: {{ if .Values.secretConfig.useClusterRoleForSecretAccess }}ClusterRole{{ else }}Role{{ end }}
25+
name: {{ include "command-cert-manager-issuer.name" . }}-secret-reader-role
26+
subjects:
27+
- kind: ServiceAccount
28+
name: {{ include "command-cert-manager-issuer.serviceAccountName" . }}
29+
namespace: {{ .Release.Namespace }}

deploy/charts/command-cert-manager-issuer/templates/secretrole.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

deploy/charts/command-cert-manager-issuer/templates/service.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

deploy/charts/command-cert-manager-issuer/templates/serviceaccount.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ metadata:
55
name: {{ include "command-cert-manager-issuer.serviceAccountName" . }}
66
labels:
77
{{- include "command-cert-manager-issuer.labels" . | nindent 4 }}
8+
{{- if .Values.serviceAccount.labels }}
9+
{{- toYaml .Values.serviceAccount.labels | nindent 4 }}
10+
{{- end }}
811
{{- with .Values.serviceAccount.annotations }}
912
annotations:
1013
{{- toYaml . | nindent 4 }}

0 commit comments

Comments
 (0)