@@ -26,12 +26,10 @@ import (
2626 configv1 "github.com/openshift/api/config/v1"
2727 configv1alpha1 "github.com/openshift/api/config/v1alpha1"
2828 "github.com/openshift/api/features"
29- configv1client "github.com/openshift/client-go/config/clientset/versioned"
3029 configv1informers "github.com/openshift/client-go/config/informers/externalversions"
3130 "github.com/openshift/library-go/pkg/operator/certrotation"
3231 "github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
3332 "github.com/openshift/library-go/pkg/operator/csr"
34- "github.com/openshift/library-go/pkg/operator/events"
3533 certapiv1 "k8s.io/api/certificates/v1"
3634 v1 "k8s.io/api/core/v1"
3735 apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -40,12 +38,9 @@ import (
4038 apiutilerrors "k8s.io/apimachinery/pkg/util/errors"
4139 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
4240 "k8s.io/client-go/informers"
43- "k8s.io/client-go/kubernetes"
44- "k8s.io/client-go/rest"
4541 "k8s.io/client-go/tools/cache"
4642 "k8s.io/client-go/util/workqueue"
4743 "k8s.io/klog/v2"
48- "k8s.io/utils/clock"
4944 "k8s.io/utils/ptr"
5045
5146 "github.com/openshift/cluster-monitoring-operator/pkg/alert"
@@ -186,9 +181,10 @@ type Operator struct {
186181 remoteWrite bool
187182 ClusterMonitoringConfigEnabled bool
188183
184+ apiServerConfig * manifests.APIServerConfig
185+
189186 lastKnowInfrastructureConfig * InfrastructureConfig
190187 lastKnowProxyConfig * ProxyConfig
191- lastKnownApiServerConfig * manifests.APIServerConfig
192188 lastKnownConsoleConfig * configv1.Console
193189
194190 client * client.Client
@@ -210,40 +206,14 @@ type Operator struct {
210206
211207func New (
212208 ctx context.Context ,
213- config * rest.Config ,
209+ c * client.Client ,
210+ apiServerConfig * manifests.APIServerConfig ,
214211 version , namespace , namespaceUserWorkload , configMapName , userWorkloadConfigMapName string ,
215212 remoteWrite bool ,
216213 images map [string ]string ,
217214 telemetryMatches []string ,
218215 a * manifests.Assets ,
219216) (* Operator , error ) {
220- kclient , err := kubernetes .NewForConfig (config )
221- if err != nil {
222- return nil , fmt .Errorf ("creating kubernetes clientset client: %w" , err )
223- }
224- controllerRef , err := events .GetControllerReferenceForCurrentPod (ctx , kclient , namespace , nil )
225- if err != nil {
226- klog .Warningf ("unable to get owner reference (falling back to namespace): %v" , err )
227- }
228-
229- eventRecorder := events .NewKubeRecorderWithOptions (
230- kclient .CoreV1 ().Events (namespace ),
231- events .RecommendedClusterSingletonCorrelatorOptions (),
232- "cluster-monitoring-operator" ,
233- controllerRef ,
234- clock.RealClock {},
235- )
236-
237- configClient , err := configv1client .NewForConfig (config )
238- if err != nil {
239- return nil , err
240- }
241-
242- c , err := client .NewForConfig (config , version , namespace , namespaceUserWorkload , client .KubernetesClient (kclient ), client .OpenshiftConfigClient (configClient ), client .EventRecorder (eventRecorder ))
243- if err != nil {
244- return nil , err
245- }
246-
247217 ruleController , err := alert .NewRuleController (ctx , c , version )
248218 if err != nil {
249219 return nil , fmt .Errorf ("failed to create alerting rule controller: %w" , err )
@@ -259,6 +229,7 @@ func New(
259229 telemetryMatches : telemetryMatches ,
260230 configMapName : configMapName ,
261231 userWorkloadConfigMapName : userWorkloadConfigMapName ,
232+ apiServerConfig : apiServerConfig ,
262233 remoteWrite : remoteWrite ,
263234 namespace : namespace ,
264235 namespaceUserWorkload : namespaceUserWorkload ,
@@ -432,7 +403,7 @@ func New(
432403 )
433404 o .informerFactories = append (o .informerFactories , kubeInformersOperatorNS )
434405
435- configInformers := configv1informers .NewSharedInformerFactory (configClient , 10 * time .Minute )
406+ configInformers := configv1informers .NewSharedInformerFactory (c . OpenShiftConfigClientset () , 10 * time .Minute )
436407 missingVersion := "0.0.1-snapshot"
437408
438409 // By default, when the enabled/disabled list of featuregates changes,
@@ -442,7 +413,7 @@ func New(
442413 version , missingVersion ,
443414 configInformers .Config ().V1 ().ClusterVersions (),
444415 configInformers .Config ().V1 ().FeatureGates (),
445- eventRecorder ,
416+ c . EventsRecorder () ,
446417 )
447418 go featureGateAccessor .Run (ctx )
448419 go configInformers .Start (ctx .Done ())
@@ -802,14 +773,6 @@ func (o *Operator) sync(ctx context.Context, key string) error {
802773
803774 var proxyConfig = getProxyReader (ctx , config , o .loadProxyConfig )
804775
805- var apiServerConfig * manifests.APIServerConfig
806- apiServerConfig , err = o .loadApiServerConfig (ctx )
807-
808- if err != nil {
809- o .reportFailed (ctx , newRunReportForError ("APIServerConfigError" , err ))
810- return err
811- }
812-
813776 consoleConfig , err := o .loadConsoleConfig (ctx )
814777 if err != nil {
815778 klog .Warningf ("Fail to load ConsoleConfig, AlertManager's externalURL may be outdated" )
@@ -822,7 +785,7 @@ func (o *Operator) sync(ctx context.Context, key string) error {
822785 o .loadInfrastructureConfig (ctx ),
823786 proxyConfig ,
824787 o .assets ,
825- apiServerConfig ,
788+ o . apiServerConfig ,
826789 consoleConfig ,
827790 )
828791
@@ -959,20 +922,6 @@ func (o *Operator) loadProxyConfig(ctx context.Context) (*ProxyConfig, error) {
959922 return o .lastKnowProxyConfig , nil
960923}
961924
962- func (o * Operator ) loadApiServerConfig (ctx context.Context ) (* manifests.APIServerConfig , error ) {
963- config , err := o .client .GetAPIServerConfig (ctx , "cluster" )
964- if err != nil {
965- klog .Warningf ("failed to get api server config: %v" , err )
966-
967- if o .lastKnownApiServerConfig == nil {
968- return nil , fmt .Errorf ("no last known api server configuration" )
969- }
970- } else {
971- o .lastKnownApiServerConfig = manifests .NewAPIServerConfig (config )
972- }
973- return o .lastKnownApiServerConfig , nil
974- }
975-
976925func (o * Operator ) loadConsoleConfig (ctx context.Context ) (* configv1.Console , error ) {
977926 config , err := o .client .GetConsoleConfig (ctx , "cluster" )
978927 if err == nil {
0 commit comments