Skip to content

Commit d1182b8

Browse files
Buddhi KothalawalaBuddhi Kothalawala
authored andcommitted
Add watch for used K8s resources in the operator
1 parent 063fcf7 commit d1182b8

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

pkg/controller/siddhiprocess/siddhiprocess_controller.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ package siddhiprocess
2121
import (
2222
"context"
2323

24+
natsv1alpha2 "github.com/siddhi-io/siddhi-operator/pkg/apis/nats/v1alpha2"
2425
siddhiv1alpha2 "github.com/siddhi-io/siddhi-operator/pkg/apis/siddhi/v1alpha2"
26+
streamingv1alpha1 "github.com/siddhi-io/siddhi-operator/pkg/apis/streaming/v1alpha1"
27+
appsv1 "k8s.io/api/apps/v1"
2528
corev1 "k8s.io/api/core/v1"
2629
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
2730

@@ -94,7 +97,46 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
9497
return err
9598
}
9699

97-
// Watch for changes to secondary resource Pods and requeue the owner SiddhiProcess
100+
err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{
101+
IsController: true,
102+
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
103+
})
104+
if err != nil {
105+
return err
106+
}
107+
108+
err = c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{
109+
IsController: true,
110+
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
111+
})
112+
if err != nil {
113+
return err
114+
}
115+
116+
err = c.Watch(&source.Kind{Type: &corev1.PersistentVolumeClaim{}}, &handler.EnqueueRequestForOwner{
117+
IsController: true,
118+
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
119+
})
120+
if err != nil {
121+
return err
122+
}
123+
124+
err = c.Watch(&source.Kind{Type: &natsv1alpha2.NatsCluster{}}, &handler.EnqueueRequestForOwner{
125+
IsController: true,
126+
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
127+
})
128+
if err != nil {
129+
return err
130+
}
131+
132+
err = c.Watch(&source.Kind{Type: &streamingv1alpha1.NatsStreamingCluster{}}, &handler.EnqueueRequestForOwner{
133+
IsController: true,
134+
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
135+
})
136+
if err != nil {
137+
return err
138+
}
139+
98140
err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{
99141
IsController: true,
100142
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
@@ -120,7 +162,7 @@ type ReconcileSiddhiProcess struct {
120162
// and what is in the SiddhiProcess.Spec
121163
func (rsp *ReconcileSiddhiProcess) Reconcile(request reconcile.Request) (reconcile.Result, error) {
122164
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
123-
reqLogger.Info("Reconciling SiddhiProcess")
165+
reqLogger.V(1).Info("Reconciling SiddhiProcess")
124166

125167
sp := &siddhiv1alpha2.SiddhiProcess{}
126168
err := rsp.client.Get(context.TODO(), request.NamespacedName, sp)

0 commit comments

Comments
 (0)