Skip to content

Commit

Permalink
gha: Allow the controller to watch Secrets / ConfigMaps in the single…
Browse files Browse the repository at this point in the history
… namespace mode
  • Loading branch information
tfujiwar committed Nov 22, 2024
1 parent 8728190 commit f5d9ae8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ rules:
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- configmaps
verbs:
- list
- watch
- apiGroups:
- rbac.authorization.k8s.io
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ func TestTemplate_CreateManagerSingleNamespaceRole(t *testing.T) {

assert.Equal(t, "test-arc-gha-rs-controller-single-namespace-watch", managerSingleNamespaceWatchRole.Name)
assert.Equal(t, "demo", managerSingleNamespaceWatchRole.Namespace)
assert.Equal(t, 14, len(managerSingleNamespaceWatchRole.Rules))
assert.Equal(t, 16, len(managerSingleNamespaceWatchRole.Rules))
}

func TestTemplate_ManagerSingleNamespaceRoleBinding(t *testing.T) {
Expand Down
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ func main() {
cfg.QPS = float32(rateLimiterQPS)
cfg.Burst = rateLimiterBurst

clientOptions := client.Options{}
if watchSingleNamespace == "" {
clientOptions.Cache = &client.CacheOptions{
DisableFor: []client.Object{
&corev1.Secret{},
&corev1.ConfigMap{},
},
}
}

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
Expand All @@ -246,14 +256,7 @@ func main() {
WebhookServer: webhookServer,
LeaderElection: enableLeaderElection,
LeaderElectionID: leaderElectionId,
Client: client.Options{
Cache: &client.CacheOptions{
DisableFor: []client.Object{
&corev1.Secret{},
&corev1.ConfigMap{},
},
},
},
Client: clientOptions,
PprofBindAddress: pprofAddr,
})
if err != nil {
Expand Down

0 comments on commit f5d9ae8

Please sign in to comment.