Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] unexport OperatorMetrics #3637

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 6 additions & 6 deletions internal/operator-metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Loading