forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd.go
More file actions
49 lines (40 loc) · 1.58 KB
/
add.go
File metadata and controls
49 lines (40 loc) · 1.58 KB
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
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package access
import (
"github.com/spf13/afero"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
resourcesv1alpha1 "github.com/gardener/gardener/pkg/apis/resources/v1alpha1"
)
// ControllerName is the name of this controller.
const ControllerName = "virtual-cluster-access"
// AddToManager adds Reconciler to the given manager.
func (r *Reconciler) AddToManager(mgr manager.Manager, namespace, secretName string) error {
if r.Client == nil {
r.Client = mgr.GetClient()
}
if r.FS == nil {
r.FS = afero.NewOsFs()
}
return builder.
ControllerManagedBy(mgr).
Named(ControllerName).
For(&corev1.Secret{}, builder.WithPredicates(HasRenewAnnotationPredicate(secretName, namespace))).
WithOptions(controller.Options{
MaxConcurrentReconciles: 1,
}).
Complete(r)
}
// HasRenewAnnotationPredicate is a predicate that returns true if the object has a 'resourcesv1alpha1.ServiceAccountTokenRenewTimestamp' annotation.
func HasRenewAnnotationPredicate(name, namespace string) predicate.Predicate {
return predicate.NewPredicateFuncs(func(o client.Object) bool {
_, hasRenewAnnotation := o.GetAnnotations()[resourcesv1alpha1.ServiceAccountTokenRenewTimestamp]
return o.GetNamespace() == namespace && o.GetName() == name && hasRenewAnnotation
})
}