Skip to content

Commit 49e9edd

Browse files
authored
Merge pull request #40 from BuddhiWathsala/master
Add watch for used K8s resources in the operator
2 parents 69f7ac7 + 299a4f6 commit 49e9edd

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

pkg/controller/siddhiprocess/siddhiprocess_controller.go

Lines changed: 49 additions & 1 deletion
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,6 +97,51 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
9497
return err
9598
}
9699

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

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

0 commit comments

Comments
 (0)