@@ -7,48 +7,11 @@ package crunchybridgecluster
7
7
import (
8
8
"context"
9
9
10
- "k8s.io/client-go/util/workqueue"
11
- ctrl "sigs.k8s.io/controller-runtime"
12
10
"sigs.k8s.io/controller-runtime/pkg/client"
13
- "sigs.k8s.io/controller-runtime/pkg/event"
14
- "sigs.k8s.io/controller-runtime/pkg/handler"
15
- "sigs.k8s.io/controller-runtime/pkg/reconcile"
16
11
17
12
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
18
13
)
19
14
20
- // watchForRelatedSecret handles create/update/delete events for secrets,
21
- // passing the Secret ObjectKey to findCrunchyBridgeClustersForSecret
22
- func (r * CrunchyBridgeClusterReconciler ) watchForRelatedSecret () handler.EventHandler {
23
- handle := func (ctx context.Context , secret client.Object , q workqueue.RateLimitingInterface ) {
24
- key := client .ObjectKeyFromObject (secret )
25
-
26
- for _ , cluster := range r .findCrunchyBridgeClustersForSecret (ctx , key ) {
27
- q .Add (ctrl.Request {
28
- NamespacedName : client .ObjectKeyFromObject (cluster ),
29
- })
30
- }
31
- }
32
-
33
- return handler.Funcs {
34
- CreateFunc : func (ctx context.Context , e event.CreateEvent , q workqueue.RateLimitingInterface ) {
35
- handle (ctx , e .Object , q )
36
- },
37
- UpdateFunc : func (ctx context.Context , e event.UpdateEvent , q workqueue.RateLimitingInterface ) {
38
- handle (ctx , e .ObjectNew , q )
39
- },
40
- // If the secret is deleted, we want to reconcile
41
- // in order to emit an event/status about this problem.
42
- // We will also emit a matching event/status about this problem
43
- // when we reconcile the cluster and can't find the secret.
44
- // That way, users will get two alerts: one when the secret is deleted
45
- // and another when the cluster is being reconciled.
46
- DeleteFunc : func (ctx context.Context , e event.DeleteEvent , q workqueue.RateLimitingInterface ) {
47
- handle (ctx , e .Object , q )
48
- },
49
- }
50
- }
51
-
52
15
//+kubebuilder:rbac:groups="postgres-operator.crunchydata.com",resources="crunchybridgeclusters",verbs={list}
53
16
54
17
// findCrunchyBridgeClustersForSecret returns CrunchyBridgeClusters
@@ -60,7 +23,7 @@ func (r *CrunchyBridgeClusterReconciler) findCrunchyBridgeClustersForSecret(
60
23
var clusters v1beta1.CrunchyBridgeClusterList
61
24
62
25
// NOTE: If this becomes slow due to a large number of CrunchyBridgeClusters in a single
63
- // namespace, we can configure the [ctrl .Manager] field indexer and pass a
26
+ // namespace, we can configure the [manager .Manager] field indexer and pass a
64
27
// [fields.Selector] here.
65
28
// - https://book.kubebuilder.io/reference/watching-resources/externally-managed.html
66
29
if err := r .List (ctx , & clusters , & client.ListOptions {
@@ -74,30 +37,3 @@ func (r *CrunchyBridgeClusterReconciler) findCrunchyBridgeClustersForSecret(
74
37
}
75
38
return matching
76
39
}
77
-
78
- //+kubebuilder:rbac:groups="postgres-operator.crunchydata.com",resources="crunchybridgeclusters",verbs={list}
79
-
80
- // Watch enqueues all existing CrunchyBridgeClusters for reconciles.
81
- func (r * CrunchyBridgeClusterReconciler ) Watch () handler.EventHandler {
82
- return handler .EnqueueRequestsFromMapFunc (func (ctx context.Context , _ client.Object ) []reconcile.Request {
83
- log := ctrl .LoggerFrom (ctx )
84
-
85
- crunchyBridgeClusterList := & v1beta1.CrunchyBridgeClusterList {}
86
- if err := r .List (ctx , crunchyBridgeClusterList ); err != nil {
87
- log .Error (err , "Error listing CrunchyBridgeClusters." )
88
- }
89
-
90
- reconcileRequests := []reconcile.Request {}
91
- for index := range crunchyBridgeClusterList .Items {
92
- reconcileRequests = append (reconcileRequests ,
93
- reconcile.Request {
94
- NamespacedName : client .ObjectKeyFromObject (
95
- & crunchyBridgeClusterList .Items [index ],
96
- ),
97
- },
98
- )
99
- }
100
-
101
- return reconcileRequests
102
- })
103
- }
0 commit comments