-
Notifications
You must be signed in to change notification settings - Fork 139
/
utils.go
61 lines (50 loc) · 1.9 KB
/
utils.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
53
54
55
56
57
58
59
60
61
package utils
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/cloud-credential-operator/pkg/operator/constants"
)
var cloudSecretKeyPassThru types.NamespacedName
// WatchCCOConfig will add a watch to the provided controller for the operator
// config resource which will schedule the provided secret for reconciliation.
func WatchCCOConfig(cache cache.Cache, c controller.Controller, cloudSecretKey types.NamespacedName, mgr manager.Manager) error {
cloudSecretKeyPassThru = cloudSecretKey
configPredicate := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
return cloudCredentialConfigObjectCheck(e.ObjectNew)
},
CreateFunc: func(e event.CreateEvent) bool {
return cloudCredentialConfigObjectCheck(e.Object)
},
DeleteFunc: func(e event.DeleteEvent) bool {
return cloudCredentialConfigObjectCheck(e.Object)
},
}
err := c.Watch(source.Kind(cache, &operatorv1.CloudCredential{}),
handler.EnqueueRequestsFromMapFunc(cloudCredSecretRequest),
configPredicate,
)
return err
}
func cloudCredentialConfigObjectCheck(conf metav1.Object) bool {
return conf.GetName() == constants.CloudCredOperatorConfig
}
func cloudCredSecretRequest(ctx context.Context, o client.Object) []reconcile.Request {
// Just requeue the cloud-cred secret for any change to the CCO config object
return []reconcile.Request{
{
NamespacedName: cloudSecretKeyPassThru,
},
}
}