diff --git a/internal/operator-metrics/metrics.go b/internal/operator-metrics/metrics.go index 43933d9d00..0fdf768685 100644 --- a/internal/operator-metrics/metrics.go +++ b/internal/operator-metrics/metrics.go @@ -39,26 +39,26 @@ var ( openshiftInClusterMonitoringNamespace = "openshift-monitoring" ) -var _ manager.Runnable = &OperatorMetrics{} +var _ manager.Runnable = operatorMetrics{} -type OperatorMetrics struct { +type operatorMetrics struct { kubeClient client.Client log logr.Logger } -func NewOperatorMetrics(config *rest.Config, scheme *runtime.Scheme, log logr.Logger) (OperatorMetrics, error) { +func NewOperatorMetrics(config *rest.Config, scheme *runtime.Scheme, log logr.Logger) (manager.Runnable, error) { kubeClient, err := client.New(config, client.Options{Scheme: scheme}) if err != nil { - return OperatorMetrics{}, err + return operatorMetrics{}, err } - return OperatorMetrics{ + return operatorMetrics{ kubeClient: kubeClient, log: log, }, nil } -func (om OperatorMetrics) Start(ctx context.Context) error { +func (om operatorMetrics) Start(ctx context.Context) error { err := om.createOperatorMetricsServiceMonitor(ctx) if err != nil { om.log.Error(err, "error creating Service Monitor for operator metrics") @@ -67,11 +67,11 @@ func (om OperatorMetrics) Start(ctx context.Context) error { return nil } -func (om OperatorMetrics) NeedLeaderElection() bool { +func (om operatorMetrics) NeedLeaderElection() bool { return true } -func (om OperatorMetrics) caConfigMapExists() bool { +func (om operatorMetrics) caConfigMapExists() bool { return om.kubeClient.Get(context.Background(), client.ObjectKey{ Name: caBundleConfigMap, Namespace: openshiftInClusterMonitoringNamespace, @@ -79,7 +79,7 @@ func (om OperatorMetrics) caConfigMapExists() bool { ) == nil } -func (om OperatorMetrics) getOwnerReferences(ctx context.Context, namespace string) (metav1.OwnerReference, error) { +func (om operatorMetrics) getOwnerReferences(ctx context.Context, namespace string) (metav1.OwnerReference, error) { var deploymentList appsv1.DeploymentList listOptions := []client.ListOption{ @@ -110,7 +110,7 @@ func (om OperatorMetrics) getOwnerReferences(ctx context.Context, namespace stri return ownerRef, nil } -func (om OperatorMetrics) createOperatorMetricsServiceMonitor(ctx context.Context) error { +func (om operatorMetrics) createOperatorMetricsServiceMonitor(ctx context.Context) error { rawNamespace, err := os.ReadFile(namespaceFile) if err != nil { return fmt.Errorf("error reading namespace file: %w", err) diff --git a/internal/operator-metrics/metrics_test.go b/internal/operator-metrics/metrics_test.go index 166d02ee16..0189e3ed46 100644 --- a/internal/operator-metrics/metrics_test.go +++ b/internal/operator-metrics/metrics_test.go @@ -31,7 +31,7 @@ func TestNewOperatorMetrics(t *testing.T) { scheme := runtime.NewScheme() metrics, err := NewOperatorMetrics(config, scheme, logr.Discard()) assert.NoError(t, err) - assert.NotNil(t, metrics.kubeClient) + assert.NotNil(t, metrics.(operatorMetrics).kubeClient) } func TestOperatorMetrics_Start(t *testing.T) { @@ -56,7 +56,7 @@ func TestOperatorMetrics_Start(t *testing.T) { }, ).Build() - metrics := OperatorMetrics{kubeClient: client} + metrics := operatorMetrics{kubeClient: client} ctx, cancel := context.WithCancel(context.Background()) errChan := make(chan error) @@ -94,7 +94,7 @@ func TestOperatorMetrics_Start(t *testing.T) { } func TestOperatorMetrics_NeedLeaderElection(t *testing.T) { - metrics := OperatorMetrics{} + metrics := operatorMetrics{} assert.True(t, metrics.NeedLeaderElection()) } @@ -112,13 +112,13 @@ func TestOperatorMetrics_caConfigMapExists(t *testing.T) { }, ).Build() - metrics := OperatorMetrics{kubeClient: client} + metrics := operatorMetrics{kubeClient: client} assert.True(t, metrics.caConfigMapExists()) // Test when the ConfigMap doesn't exist clientWithoutConfigMap := fake.NewClientBuilder().WithScheme(scheme).Build() - metricsWithoutConfigMap := OperatorMetrics{kubeClient: clientWithoutConfigMap} + metricsWithoutConfigMap := operatorMetrics{kubeClient: clientWithoutConfigMap} assert.False(t, metricsWithoutConfigMap.caConfigMapExists()) } @@ -172,7 +172,7 @@ func TestOperatorMetrics_getOwnerReferences(t *testing.T) { WithObjects(tt.objects...). Build() - om := OperatorMetrics{ + om := operatorMetrics{ kubeClient: fakeClient, log: logr.Discard(), }