Skip to content

Commit

Permalink
Remove unused watch events in metrics controller (#1926)
Browse files Browse the repository at this point in the history
* removed unsed watch events
  • Loading branch information
jintusebastian authored Sep 26, 2023
1 parent b0e1e99 commit 7ffd7d4
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"

osbv1alpha1 "github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/api/osb/v1alpha1"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/controllers/multiclusterdeploy/watchmanager"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/internal/config"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/pkg/cluster/registry"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/pkg/watches"
Expand All @@ -31,9 +30,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/source"
)

var (
Expand All @@ -59,8 +56,6 @@ var (
)
)

var getWatchChannel = watchmanager.GetWatchChannel

type BindingMetrics struct {
client.Client
Log logr.Logger
Expand Down Expand Up @@ -129,11 +124,6 @@ func (r *BindingMetrics) SetupWithManager(mgr ctrl.Manager) error {
}
interoperatorCfg := cfgManager.GetConfig()
r.cfgManager = cfgManager
// Watch for changes to SFServiceBinding in sister clusters
watchEvents, err := getWatchChannel("sfservicebindings")
if err != nil {
return err
}

metrics.Registry.MustRegister(bindingsMetric)

Expand All @@ -143,7 +133,6 @@ func (r *BindingMetrics) SetupWithManager(mgr ctrl.Manager) error {
MaxConcurrentReconciles: interoperatorCfg.BindingWorkerCount,
}).
For(&osbv1alpha1.SFServiceBinding{}).
Watches(&source.Channel{Source: watchEvents}, &handler.EnqueueRequestForObject{}).
WithEventFilter(watches.NamespaceLabelFilter())

return builder.Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"k8s.io/apimachinery/pkg/types"
ctrlrun "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

Expand Down Expand Up @@ -85,20 +84,10 @@ var binding = &osbv1alpha1.SFServiceBinding{
var binding2 = &osbv1alpha1.SFServiceBinding{}

func TestReconcileSFServiceBindingMetrics(t *testing.T) {
watchChannel := make(chan event.GenericEvent)

g := gomega.NewGomegaWithT(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()

_getWatchChannel := getWatchChannel
defer func() {
getWatchChannel = _getWatchChannel
}()
getWatchChannel = func(controllerName string) (<-chan event.GenericEvent, error) {
return watchChannel, nil
}

// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
// channel when it is finished.
mgr, err := manager.New(cfg, manager.Options{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"

osbv1alpha1 "github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/api/osb/v1alpha1"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/controllers/multiclusterdeploy/watchmanager"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/internal/config"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/pkg/cluster/registry"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/pkg/watches"
Expand All @@ -31,9 +30,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/source"
)

var (
Expand All @@ -60,9 +57,6 @@ var (
)
)

// To the function mock
var getWatchChannel = watchmanager.GetWatchChannel

// InstanceReplicator replicates a SFServiceInstance object to sister cluster
type InstanceMetrics struct {
client.Client
Expand Down Expand Up @@ -134,13 +128,6 @@ func (r *InstanceMetrics) SetupWithManager(mgr ctrl.Manager) error {
}
r.cfgManager = cfgManager
interoperatorCfg := cfgManager.GetConfig()
//r.cfgManager = cfgManager

// Watch for changes to SFServiceInstance in sister clusters
watchEvents, err := getWatchChannel("sfserviceinstances")
if err != nil {
return err
}

metrics.Registry.MustRegister(instancesMetric)

Expand All @@ -150,7 +137,6 @@ func (r *InstanceMetrics) SetupWithManager(mgr ctrl.Manager) error {
MaxConcurrentReconciles: interoperatorCfg.InstanceWorkerCount,
}).
For(&osbv1alpha1.SFServiceInstance{}).
Watches(&source.Channel{Source: watchEvents}, &handler.EnqueueRequestForObject{}).
WithEventFilter(watches.NamespaceLabelFilter())

return builder.Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"k8s.io/apimachinery/pkg/types"
ctrlrun "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

Expand Down Expand Up @@ -70,20 +69,10 @@ var instance = &osbv1alpha1.SFServiceInstance{
var instance2 = &osbv1alpha1.SFServiceInstance{}

func TestReconcileSFServiceInstanceMetrics(t *testing.T) {
watchChannel := make(chan event.GenericEvent)

g := gomega.NewGomegaWithT(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()

_getWatchChannel := getWatchChannel
defer func() {
getWatchChannel = _getWatchChannel
}()
getWatchChannel = func(controllerName string) (<-chan event.GenericEvent, error) {
return watchChannel, nil
}

// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
// channel when it is finished.
mgr, err := manager.New(cfg, manager.Options{
Expand Down

0 comments on commit 7ffd7d4

Please sign in to comment.