Skip to content

Commit

Permalink
Use informer for service monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed Dec 11, 2020
1 parent 2c205d8 commit 423ae36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion pkg/csoclients/csoclients.go
Expand Up @@ -41,7 +41,9 @@ type Clients struct {
// config.openshift.io informers
ConfigInformers cfginformers.SharedInformerFactory

MonitoringClient promclient.Interface
// Client for talking using prometheus-operator APIs (ServiceMonitor)
MonitoringClient promclient.Interface
// informer for prometheus-operator APIs
MonitoringInformer prominformer.SharedInformerFactory

// Dynamic client for OLM and old CSI operator APIs
Expand Down Expand Up @@ -102,6 +104,12 @@ func NewClients(controllerConfig *controllercmd.ControllerContext, resync time.D
}
c.ExtensionInformer = apiextinformers.NewSharedInformerFactory(c.ExtensionClientSet, resync)

c.MonitoringClient, err = promclient.NewForConfig(controllerConfig.KubeConfig)
if err != nil {
return nil, err
}
c.MonitoringInformer = prominformer.NewSharedInformerFactory(c.MonitoringClient, resync)

c.OperatorClient = &operatorclient.OperatorClient{
Informers: c.OperatorInformers,
Client: c.OperatorClientSet,
Expand All @@ -117,6 +125,7 @@ func StartInformers(clients *Clients, stopCh <-chan struct{}) {
clients.OperatorInformers,
clients.ConfigInformers,
clients.ExtensionInformer,
clients.MonitoringInformer,
} {
informer.Start(stopCh)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/operator/vsphereproblemdetector/monitoring.go
Expand Up @@ -39,9 +39,11 @@ func newMonitoringController(
eventRecorder: eventRecorder,
}
return factory.New().
WithInformers(c.operatorClient.Informer()).
WithSync(c.sync).
ResyncEvery(time.Minute).
WithInformers(
c.operatorClient.Informer(),
clients.MonitoringInformer.Monitoring().V1().ServiceMonitors().Informer()).
ResyncEvery(resyncInterval).
WithSyncDegradedOnError(clients.OperatorClient).
ToController(monitoringControllerName, eventRecorder.WithComponentSuffix("vsphere-monitoring-controller"))
}
Expand Down

0 comments on commit 423ae36

Please sign in to comment.