Repository: open-telemetry/opentelemetry-operator

Issue:
Remove not used method GetPortsForConfig
### Component(s)

collector

### Describe the issue you're reporting

I think that method was not removed during the refactor.

https://github.com/open-telemetry/opentelemetry-operator/blob/bc45d6336d845b5d36c842559c58a5cc20dd44d9/internal/components/component.go#L140

It seems it is only used for one test and not called from the real code.

Hints from issue comments:

Solution patch:
diff --git a/Makefile b/Makefile
index dbeb12d7..ea6fdd94 100644
--- a/Makefile
+++ b/Makefile
@@ -497,7 +497,7 @@ KUSTOMIZE_VERSION ?= v5.6.0
 # renovate: datasource=go depName=sigs.k8s.io/controller-tools/cmd/controller-gen
 CONTROLLER_TOOLS_VERSION ?= v0.17.1
 # renovate: datasource=github-releases depName=golangci/golangci-lint
-GOLANGCI_LINT_VERSION ?= v1.64.6
+GOLANGCI_LINT_VERSION ?= v1.64.7
 # renovate: datasource=go depName=sigs.k8s.io/kind
 KIND_VERSION ?= v0.27.0
 # renovate: datasource=go depName=github.com/kyverno/chainsaw
diff --git a/internal/components/component.go b/internal/components/component.go
index fca12988..7745bff7 100644
--- a/internal/components/component.go
+++ b/internal/components/component.go
@@ -125,16 +125,3 @@ func ConstructServicePort(current *corev1.ServicePort, port int32) corev1.Servic
 	}
 	return svc
 }
-
-func GetPortsForConfig(logger logr.Logger, config map[string]interface{}, retriever ParserRetriever) ([]corev1.ServicePort, error) {
-	var ports []corev1.ServicePort
-	for componentName, componentDef := range config {
-		parser := retriever(componentName)
-		if parsedPorts, err := parser.Ports(logger, componentName, componentDef); err != nil {
-			return nil, err
-		} else {
-			ports = append(ports, parsedPorts...)
-		}
-	}
-	return ports, nil
-}



Test patch:
diff --git a/internal/components/component_test.go b/internal/components/component_test.go
index 0951e8d5..d4689894 100644
--- a/internal/components/component_test.go
+++ b/internal/components/component_test.go
@@ -4,16 +4,11 @@
 package components_test
 
 import (
-	"fmt"
 	"testing"
 
-	"github.com/go-logr/logr"
 	"github.com/stretchr/testify/assert"
-	corev1 "k8s.io/api/core/v1"
-	"k8s.io/apimachinery/pkg/util/intstr"
 
 	"github.com/open-telemetry/opentelemetry-operator/internal/components"
-	"github.com/open-telemetry/opentelemetry-operator/internal/components/receivers"
 )
 
 func TestComponentType(t *testing.T) {
@@ -59,68 +54,3 @@ func TestReceiverParsePortFromEndpoint(t *testing.T) {
 		})
 	}
 }
-
-func TestGetPortsForConfig(t *testing.T) {
-	type args struct {
-		config    map[string]interface{}
-		retriever components.ParserRetriever
-	}
-	tests := []struct {
-		name    string
-		args    args
-		want    []corev1.ServicePort
-		wantErr assert.ErrorAssertionFunc
-	}{
-		{
-			name: "nothing",
-			args: args{
-				config:    nil,
-				retriever: receivers.ReceiverFor,
-			},
-			want:    nil,
-			wantErr: assert.NoError,
-		},
-		{
-			name: "bad config",
-			args: args{
-				config: map[string]interface{}{
-					"test": "garbage",
-				},
-				retriever: receivers.ReceiverFor,
-			},
-			want:    nil,
-			wantErr: assert.Error,
-		},
-		{
-			name: "receivers",
-			args: args{
-				config: map[string]interface{}{
-					"otlp": map[string]interface{}{
-						"protocols": map[string]interface{}{
-							"grpc": map[string]interface{}{},
-						},
-					},
-				},
-				retriever: receivers.ReceiverFor,
-			},
-			want: []corev1.ServicePort{
-				{
-					Name:        "otlp-grpc",
-					Port:        4317,
-					TargetPort:  intstr.FromInt32(4317),
-					AppProtocol: &components.GrpcProtocol,
-				},
-			},
-			wantErr: assert.NoError,
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			got, err := components.GetPortsForConfig(logr.Discard(), tt.args.config, tt.args.retriever)
-			if !tt.wantErr(t, err, fmt.Sprintf("GetPortsForConfig(%v)", tt.args.config)) {
-				return
-			}
-			assert.Equalf(t, tt.want, got, "GetPortsForConfig(%v)", tt.args.config)
-		})
-	}
-}