diff --git a/jsonnet/components/cluster-monitoring-operator.libsonnet b/jsonnet/components/cluster-monitoring-operator.libsonnet index c9d2b9b8f5..da209e5643 100644 --- a/jsonnet/components/cluster-monitoring-operator.libsonnet +++ b/jsonnet/components/cluster-monitoring-operator.libsonnet @@ -247,6 +247,11 @@ function(params) { resources: ['featuregates'], verbs: ['get', 'list', 'watch'], }, + { + apiGroups: ['config.openshift.io'], + resources: ['clustermonitorings'], + verbs: ['get', 'list', 'watch'], + }, { apiGroups: ['certificates.k8s.io'], resources: ['certificatesigningrequests'], diff --git a/manifests/0000_50_cluster-monitoring-operator_02-role.yaml b/manifests/0000_50_cluster-monitoring-operator_02-role.yaml index 2c5a2ec6aa..b78ef950fc 100644 --- a/manifests/0000_50_cluster-monitoring-operator_02-role.yaml +++ b/manifests/0000_50_cluster-monitoring-operator_02-role.yaml @@ -135,6 +135,14 @@ rules: - get - list - watch +- apiGroups: + - config.openshift.io + resources: + - clustermonitorings + verbs: + - get + - list + - watch - apiGroups: - certificates.k8s.io resources: diff --git a/manifests/0000_50_cluster-monitoring-operator_06-clusteroperator.yaml b/manifests/0000_50_cluster-monitoring-operator_06-clusteroperator.yaml index d76a1747f6..5c3da8a36d 100644 --- a/manifests/0000_50_cluster-monitoring-operator_06-clusteroperator.yaml +++ b/manifests/0000_50_cluster-monitoring-operator_06-clusteroperator.yaml @@ -40,3 +40,6 @@ status: - group: monitoring.coreos.com name: '' resource: alertmanagerconfigs + - group: config.openshift.io + name: cluster + resource: clustermonitorings diff --git a/pkg/client/client.go b/pkg/client/client.go index e9058276f3..dc321d15c1 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -417,6 +417,19 @@ func (c *Client) ClusterOperatorListWatch(ctx context.Context, name string) *cac } } +func (c *Client) ClusterMonitoringListWatch(ctx context.Context) *cache.ListWatch { + clusterMonitoringInterface := c.oscclient.ConfigV1alpha1().ClusterMonitorings() + + return &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + return clusterMonitoringInterface.List(ctx, metav1.ListOptions{}) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + return clusterMonitoringInterface.Watch(ctx, options) + }, + } +} + func (c *Client) HasRouteCapability(ctx context.Context) (bool, error) { _, err := c.oscclient.ConfigV1().ClusterOperators().Get(ctx, "ingress", metav1.GetOptions{}) if apierrors.IsNotFound(err) { diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 91f8e6ecc7..5f211d4153 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -24,6 +24,7 @@ import ( "github.com/blang/semver/v4" configv1 "github.com/openshift/api/config/v1" + configv1alpha1 "github.com/openshift/api/config/v1alpha1" "github.com/openshift/api/features" configv1client "github.com/openshift/client-go/config/clientset/versioned" configv1informers "github.com/openshift/client-go/config/informers/externalversions" @@ -177,12 +178,13 @@ const ( type Operator struct { namespace, namespaceUserWorkload string - configMapName string - userWorkloadConfigMapName string - images map[string]string - telemetryMatches []string - remoteWrite bool - CollectionProfilesEnabled bool + configMapName string + userWorkloadConfigMapName string + images map[string]string + telemetryMatches []string + remoteWrite bool + CollectionProfilesEnabled bool + ClusterMonitoringConfigEnabled bool lastKnowInfrastructureConfig *InfrastructureConfig lastKnowProxyConfig *ProxyConfig @@ -452,10 +454,30 @@ func New( return nil, err } o.CollectionProfilesEnabled = featureGates.Enabled(features.FeatureGateMetricsCollectionProfiles) + o.ClusterMonitoringConfigEnabled = featureGates.Enabled(features.FeatureGateClusterMonitoringConfig) case <-time.After(1 * time.Minute): return nil, fmt.Errorf("timed out waiting for FeatureGate detection") } + // Watch the ClusterMonitoring config resource if the feature gate is enabled + if o.ClusterMonitoringConfigEnabled { + informer = cache.NewSharedIndexInformer( + o.client.ClusterMonitoringListWatch(ctx), + &configv1alpha1.ClusterMonitoring{}, + resyncPeriod, + cache.Indexers{}, + ) + _, err = informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: o.handleEvent, + UpdateFunc: func(_, newObj interface{}) { o.handleEvent(newObj) }, + DeleteFunc: o.handleEvent, + }) + if err != nil { + return nil, err + } + o.informers = append(o.informers, informer) + } + // csrController runs a controller that requests a client TLS certificate // for Prometheus k8s. This certificate is used to authenticate against the // /metrics endpoint of the targets. @@ -630,7 +652,8 @@ func (o *Operator) handleEvent(obj interface{}) { *configv1.APIServer, *configv1.Console, *configv1.ClusterOperator, - *configv1.ClusterVersion: + *configv1.ClusterVersion, + *configv1alpha1.ClusterMonitoring: // Log GroupKind and Name of the obj rtObj := obj.(k8sruntime.Object) gk := rtObj.GetObjectKind().GroupVersionKind().GroupKind()