Skip to content

Commit 53566c0

Browse files
committed
pkg/start: Register metrics directly
Pulling this up out of cvo.New() while working to decouple metrics handling from the core CVO goroutine.
1 parent b30aa0e commit 53566c0

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

pkg/cvo/cvo.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ func New(
169169
proxyInformer configinformersv1.ProxyInformer,
170170
client clientset.Interface,
171171
kubeClient kubernetes.Interface,
172-
enableMetrics bool,
173172
exclude string,
174173
) *Operator {
175174
eventBroadcaster := record.NewBroadcaster()
@@ -214,11 +213,6 @@ func New(
214213
// make sure this is initialized after all the listers are initialized
215214
optr.upgradeableChecks = optr.defaultUpgradeableChecks()
216215

217-
if enableMetrics {
218-
if err := optr.registerMetrics(coInformer.Informer()); err != nil {
219-
panic(err)
220-
}
221-
}
222216
return optr
223217
}
224218

pkg/cvo/metrics.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
"github.com/openshift/cluster-version-operator/pkg/internal"
2323
)
2424

25-
func (optr *Operator) registerMetrics(coInformer cache.SharedInformer) error {
25+
// RegisterMetrics initializes metrics and registers them with the
26+
// Prometheus implementation.
27+
func (optr *Operator) RegisterMetrics(coInformer cache.SharedInformer) error {
2628
m := newOperatorMetrics(optr)
2729
coInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
2830
UpdateFunc: m.clusterOperatorChanged,

pkg/start/start.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ func (o *Options) makeTLSConfig() (*tls.Config, error) {
184184

185185
func (o *Options) run(ctx context.Context, controllerCtx *Context, lock *resourcelock.ConfigMapLock) {
186186
runContext, runCancel := context.WithCancel(ctx)
187+
defer runCancel()
187188
shutdownContext, shutdownCancel := context.WithCancel(ctx)
189+
defer shutdownCancel()
188190
errorChannel := make(chan error, 1)
189191
errorChannelCount := 0
190192
if o.ListenAddr != "" {
@@ -392,6 +394,7 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {
392394

393395
sharedInformers := externalversions.NewSharedInformerFactory(client, resyncPeriod(o.ResyncInterval)())
394396

397+
coInformer := sharedInformers.Config().V1().ClusterOperators()
395398
ctx := &Context{
396399
CVInformerFactory: cvInformer,
397400
OpenshiftConfigInformerFactory: openshiftConfigInformer,
@@ -405,12 +408,11 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {
405408
o.PayloadOverride,
406409
resyncPeriod(o.ResyncInterval)(),
407410
cvInformer.Config().V1().ClusterVersions(),
408-
sharedInformers.Config().V1().ClusterOperators(),
411+
coInformer,
409412
openshiftConfigInformer.Core().V1().ConfigMaps(),
410413
sharedInformers.Config().V1().Proxies(),
411414
cb.ClientOrDie(o.Namespace),
412415
cb.KubeClientOrDie(o.Namespace, useProtobuf),
413-
o.ListenAddr != "",
414416
o.Exclude,
415417
),
416418
}
@@ -423,6 +425,11 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {
423425
cb.KubeClientOrDie(o.Namespace),
424426
)
425427
}
428+
if o.ListenAddr != "" {
429+
if err := ctx.CVO.RegisterMetrics(coInformer.Informer()); err != nil {
430+
panic(err)
431+
}
432+
}
426433
return ctx
427434
}
428435

0 commit comments

Comments
 (0)