forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.go
52 lines (44 loc) · 1.53 KB
/
add.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package token
import (
"context"
"github.com/spf13/afero"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)
// ControllerName is the name of this controller.
const ControllerName = "token"
// AddToManager adds Reconciler to the given manager.
func (r *Reconciler) AddToManager(mgr manager.Manager) error {
if r.APIReader == nil {
r.APIReader = mgr.GetAPIReader()
}
if r.FS.Fs == nil {
r.FS = afero.Afero{Fs: afero.NewOsFs()}
}
r.secretNameToPath = make(map[string]string, len(r.Config.SyncConfigs))
for _, config := range r.Config.SyncConfigs {
r.secretNameToPath[config.SecretName] = config.Path
}
return builder.
ControllerManagedBy(mgr).
Named(ControllerName).
WatchesRawSource(
source.Func(func(_ context.Context, q workqueue.TypedRateLimitingInterface[reconcile.Request]) error {
for _, config := range r.Config.SyncConfigs {
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{Name: config.SecretName, Namespace: metav1.NamespaceSystem}})
}
return nil
}),
).
WithOptions(controller.Options{MaxConcurrentReconciles: len(r.Config.SyncConfigs)}).
Complete(r)
}