Skip to content

Commit

Permalink
fix: use metadata informer for agent controller
Browse files Browse the repository at this point in the history
The Prometheus agent controller didn't use the metadata informer for
secrets and configmaps as implemented in #5424 and #5448 for the other
controllers.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
  • Loading branch information
simonpasquier committed Oct 10, 2023
1 parent 30f1b34 commit 6986ea7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/prometheus/agent/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/metadata"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/utils/ptr"
Expand All @@ -56,7 +57,9 @@ const (
// monitoring configurations.
type Operator struct {
kclient kubernetes.Interface
mdClient metadata.Interface
mclient monitoringclient.Interface

logger log.Logger
accessor *operator.Accessor

Expand Down Expand Up @@ -92,6 +95,11 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
return nil, fmt.Errorf("instantiating kubernetes client failed: %w", err)
}

mdClient, err := metadata.NewForConfig(restConfig)
if err != nil {
return nil, fmt.Errorf("instantiating metadata client failed: %w", err)
}

mclient, err := monitoringclient.NewForConfig(restConfig)
if err != nil {
return nil, fmt.Errorf("instantiating monitoring client failed: %w", err)
Expand All @@ -111,6 +119,7 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log

c := &Operator{
kclient: client,
mdClient: mdClient,
mclient: mclient,
logger: logger,
config: conf,
Expand Down Expand Up @@ -213,10 +222,10 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
}

c.cmapInfs, err = informers.NewInformersForResource(
informers.NewKubeInformerFactories(
informers.NewMetadataInformerFactory(
c.config.Namespaces.PrometheusAllowList,
c.config.Namespaces.DenyList,
c.kclient,
c.mdClient,
resyncPeriod,
func(options *metav1.ListOptions) {
options.LabelSelector = prompkg.LabelPrometheusName
Expand All @@ -229,10 +238,10 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
}

c.secrInfs, err = informers.NewInformersForResource(
informers.NewKubeInformerFactories(
informers.NewMetadataInformerFactory(
c.config.Namespaces.PrometheusAllowList,
c.config.Namespaces.DenyList,
c.kclient,
c.mdClient,
resyncPeriod,
func(options *metav1.ListOptions) {
options.FieldSelector = secretListWatchSelector.String()
Expand Down

0 comments on commit 6986ea7

Please sign in to comment.