From 11500c0d129cdbc6dd262797957435d8295a77cc Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Sun, 19 Jan 2025 20:18:53 -0800 Subject: [PATCH] [chore] unexport OperatorMetrics --- internal/operator-metrics/metrics.go | 20 ++++++++++---------- internal/operator-metrics/metrics_test.go | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/operator-metrics/metrics.go b/internal/operator-metrics/metrics.go index dd95e16e7e..b52b43e8cc 100644 --- a/internal/operator-metrics/metrics.go +++ b/internal/operator-metrics/metrics.go @@ -50,26 +50,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") @@ -78,11 +78,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, @@ -90,7 +90,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{ @@ -121,7 +121,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 a0293fa2e5..90fe9dd838 100644 --- a/internal/operator-metrics/metrics_test.go +++ b/internal/operator-metrics/metrics_test.go @@ -42,7 +42,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) { @@ -67,7 +67,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) @@ -105,7 +105,7 @@ func TestOperatorMetrics_Start(t *testing.T) { } func TestOperatorMetrics_NeedLeaderElection(t *testing.T) { - metrics := OperatorMetrics{} + metrics := operatorMetrics{} assert.True(t, metrics.NeedLeaderElection()) } @@ -123,13 +123,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()) } @@ -183,7 +183,7 @@ func TestOperatorMetrics_getOwnerReferences(t *testing.T) { WithObjects(tt.objects...). Build() - om := OperatorMetrics{ + om := operatorMetrics{ kubeClient: fakeClient, log: logr.Discard(), }