Skip to content

Commit

Permalink
[chore] unexport OperatorMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Jan 20, 2025
1 parent a36367b commit d59447a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions internal/operator-metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -78,19 +78,19 @@ 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,
}, &corev1.ConfigMap{},
) == 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{
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/operator-metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}

Expand All @@ -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())
}

Expand Down Expand Up @@ -183,7 +183,7 @@ func TestOperatorMetrics_getOwnerReferences(t *testing.T) {
WithObjects(tt.objects...).
Build()

om := OperatorMetrics{
om := operatorMetrics{
kubeClient: fakeClient,
log: logr.Discard(),
}
Expand Down

0 comments on commit d59447a

Please sign in to comment.