Skip to content

Commit

Permalink
Merge pull request #40 from BuddhiWathsala/master
Browse files Browse the repository at this point in the history
Add watch for used K8s resources in the operator
  • Loading branch information
pcnfernando authored Jul 8, 2019
2 parents 69f7ac7 + 299a4f6 commit 49e9edd
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion pkg/controller/siddhiprocess/siddhiprocess_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ package siddhiprocess
import (
"context"

natsv1alpha2 "github.com/siddhi-io/siddhi-operator/pkg/apis/nats/v1alpha2"
siddhiv1alpha2 "github.com/siddhi-io/siddhi-operator/pkg/apis/siddhi/v1alpha2"
streamingv1alpha1 "github.com/siddhi-io/siddhi-operator/pkg/apis/streaming/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"

Expand Down Expand Up @@ -94,6 +97,51 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

// Watch for changes to secondary resource Deployments and requeue the owner SiddhiProcess
err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
})
if err != nil {
return err
}

// Watch for changes to secondary resource Services and requeue the owner SiddhiProcess
err = c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
})
if err != nil {
return err
}

// Watch for changes to secondary resource PersistentVolumeClaims and requeue the owner SiddhiProcess
err = c.Watch(&source.Kind{Type: &corev1.PersistentVolumeClaim{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
})
if err != nil {
return err
}

// Watch for changes to secondary resource NatsClusters and requeue the owner SiddhiProcess
err = c.Watch(&source.Kind{Type: &natsv1alpha2.NatsCluster{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
})
if err != nil {
return err
}

// Watch for changes to secondary resource NatsStreamingClusters and requeue the owner SiddhiProcess
err = c.Watch(&source.Kind{Type: &streamingv1alpha1.NatsStreamingCluster{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &siddhiv1alpha2.SiddhiProcess{},
})
if err != nil {
return err
}

// Watch for changes to secondary resource Pods and requeue the owner SiddhiProcess
err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{
IsController: true,
Expand All @@ -120,7 +168,7 @@ type ReconcileSiddhiProcess struct {
// and what is in the SiddhiProcess.Spec
func (rsp *ReconcileSiddhiProcess) Reconcile(request reconcile.Request) (reconcile.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling SiddhiProcess")
reqLogger.V(1).Info("Reconciling SiddhiProcess")

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

0 comments on commit 49e9edd

Please sign in to comment.