From b4fdc05c34a6fa2ee639aa00b33236f564cfd86f Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Fri, 6 Mar 2026 09:09:58 +0100 Subject: [PATCH] [chore](internal): fix gofumpt issues part 3 #### Description fix gofumpt issues in internal/instrumentation --- This commit was automatically created by review-helper. Changes are split into focused commits grouped by directory to simplify the review process. Signed-off-by: Matthieu MOREL --- internal/components/component.go | 1 - internal/components/processors/k8sattribute.go | 2 +- internal/controllers/targetallocator_reconciler_test.go | 4 +--- internal/instrumentation/annotation.go | 2 +- internal/instrumentation/dotnet.go | 2 +- internal/instrumentation/podmutator.go | 2 +- internal/instrumentation/podmutator_test.go | 6 ++++-- internal/instrumentation/python.go | 2 +- internal/manifests/collector/configmap.go | 1 - internal/manifests/collector/suite_test.go | 3 +-- internal/manifests/manifestutils/annotations_test.go | 7 ++++--- internal/manifests/manifestutils/labels_test.go | 2 ++ internal/manifests/opampbridge/configmap_test.go | 3 ++- internal/manifests/opampbridge/container.go | 2 +- internal/manifests/targetallocator/container.go | 2 +- internal/manifests/targetallocator/container_test.go | 2 ++ internal/manifests/targetallocator/deployment_test.go | 6 ++++-- internal/manifests/targetallocator/volume.go | 3 ++- internal/naming/dns_test.go | 2 +- internal/operator-metrics/metrics_test.go | 2 +- 20 files changed, 31 insertions(+), 25 deletions(-) diff --git a/internal/components/component.go b/internal/components/component.go index 232273a1c0..5202b2a794 100644 --- a/internal/components/component.go +++ b/internal/components/component.go @@ -86,7 +86,6 @@ func PortFromEndpoint(endpoint string) (int32, error) { portStr := r.FindString(endpoint) cleanedPortStr := strings.ReplaceAll(portStr, ":", "") port, err = strconv.ParseInt(cleanedPortStr, 10, 32) - if err != nil { return UnsetPort, err } diff --git a/internal/components/processors/k8sattribute.go b/internal/components/processors/k8sattribute.go index 3e84d1de3a..1e7eca9544 100644 --- a/internal/components/processors/k8sattribute.go +++ b/internal/components/processors/k8sattribute.go @@ -33,7 +33,7 @@ type K8sAttributeConfig struct { func GenerateK8SAttrRbacRules(_ logr.Logger, config K8sAttributeConfig) ([]rbacv1.PolicyRule, error) { // These policies need to be added always - var prs = []rbacv1.PolicyRule{ + prs := []rbacv1.PolicyRule{ { APIGroups: []string{""}, Resources: []string{"pods", "namespaces"}, diff --git a/internal/controllers/targetallocator_reconciler_test.go b/internal/controllers/targetallocator_reconciler_test.go index ab7f3b414a..bc93d67501 100644 --- a/internal/controllers/targetallocator_reconciler_test.go +++ b/internal/controllers/targetallocator_reconciler_test.go @@ -30,9 +30,7 @@ import ( var testLogger = logf.Log.WithName("opamp-bridge-controller-unit-tests") -var ( - testScheme *runtime.Scheme = scheme.Scheme -) +var testScheme *runtime.Scheme = scheme.Scheme func init() { utilruntime.Must(monitoringv1.AddToScheme(testScheme)) diff --git a/internal/instrumentation/annotation.go b/internal/instrumentation/annotation.go index 39d74f590e..a0e95dadda 100644 --- a/internal/instrumentation/annotation.go +++ b/internal/instrumentation/annotation.go @@ -35,7 +35,7 @@ const ( ) // annotationValue returns the effective annotationInjectJava value, based on the annotations from the pod and namespace. -func annotationValue(ns metav1.ObjectMeta, pod metav1.ObjectMeta, annotation string) string { +func annotationValue(ns, pod metav1.ObjectMeta, annotation string) string { // is the pod annotated with instructions to inject sidecars? is the namespace annotated? // if any of those is true, a sidecar might be desired. podAnnValue := pod.Annotations[annotation] diff --git a/internal/instrumentation/dotnet.go b/internal/instrumentation/dotnet.go index 2b6a949863..7647384bc9 100644 --- a/internal/instrumentation/dotnet.go +++ b/internal/instrumentation/dotnet.go @@ -137,7 +137,7 @@ func injectDefaultDotNetEnvVars(container *corev1.Container, runtime string) { // setDotNetEnvVar function sets env var to the container if not exist already. // value of concatValues should be set to true if the env var supports multiple values separated by :. // If it is set to false, the original container's env var value has priority. -func setDotNetEnvVar(container *corev1.Container, envVarName string, envVarValue string, concatValues bool) { +func setDotNetEnvVar(container *corev1.Container, envVarName, envVarValue string, concatValues bool) { idx := getIndexOfEnv(container.Env, envVarName) if idx < 0 { container.Env = append(container.Env, corev1.EnvVar{ diff --git a/internal/instrumentation/podmutator.go b/internal/instrumentation/podmutator.go index fe361332ce..f59e1345ec 100644 --- a/internal/instrumentation/podmutator.go +++ b/internal/instrumentation/podmutator.go @@ -144,7 +144,7 @@ func (langInsts *languageInstrumentations) setCommonInstrumentedContainers(ns co return nil } -func (langInsts *languageInstrumentations) setLanguageSpecificContainers(ns metav1.ObjectMeta, pod metav1.ObjectMeta) error { +func (langInsts *languageInstrumentations) setLanguageSpecificContainers(ns, pod metav1.ObjectMeta) error { inst := []struct { iwc *instrumentationWithContainers annotation string diff --git a/internal/instrumentation/podmutator_test.go b/internal/instrumentation/podmutator_test.go index ac0763d182..73bb017782 100644 --- a/internal/instrumentation/podmutator_test.go +++ b/internal/instrumentation/podmutator_test.go @@ -2958,7 +2958,8 @@ func TestMutatePod(t *testing.T) { Image: "otel/apache-httpd:1", Command: []string{"/bin/sh", "-c"}, Args: []string{ - "cp -r /opt/opentelemetry/* /opt/opentelemetry-webserver/agent && export agentLogDir=$(echo \"/opt/opentelemetry-webserver/agent/logs\" | sed 's,/,\\\\/,g') && cat /opt/opentelemetry-webserver/agent/conf/opentelemetry_sdk_log4cxx.xml.template | sed 's/__agent_log_dir__/'${agentLogDir}'/g' > /opt/opentelemetry-webserver/agent/conf/opentelemetry_sdk_log4cxx.xml &&echo \"$OTEL_APACHE_AGENT_CONF\" > /opt/opentelemetry-webserver/source-conf/opentemetry_agent.conf && sed -i 's/<>/'${APACHE_SERVICE_INSTANCE_ID}'/g' /opt/opentelemetry-webserver/source-conf/opentemetry_agent.conf && echo -e '\nInclude /usr/local/apache2/conf/opentemetry_agent.conf' >> /opt/opentelemetry-webserver/source-conf/httpd.conf"}, + "cp -r /opt/opentelemetry/* /opt/opentelemetry-webserver/agent && export agentLogDir=$(echo \"/opt/opentelemetry-webserver/agent/logs\" | sed 's,/,\\\\/,g') && cat /opt/opentelemetry-webserver/agent/conf/opentelemetry_sdk_log4cxx.xml.template | sed 's/__agent_log_dir__/'${agentLogDir}'/g' > /opt/opentelemetry-webserver/agent/conf/opentelemetry_sdk_log4cxx.xml &&echo \"$OTEL_APACHE_AGENT_CONF\" > /opt/opentelemetry-webserver/source-conf/opentemetry_agent.conf && sed -i 's/<>/'${APACHE_SERVICE_INSTANCE_ID}'/g' /opt/opentelemetry-webserver/source-conf/opentemetry_agent.conf && echo -e '\nInclude /usr/local/apache2/conf/opentemetry_agent.conf' >> /opt/opentelemetry-webserver/source-conf/httpd.conf", + }, Env: []corev1.EnvVar{ { Name: apacheAttributesEnvVar, @@ -3217,7 +3218,8 @@ func TestMutatePod(t *testing.T) { { Name: "OTEL_NGINX_I13N_SCRIPT", Value: nginxSdkInitContainerI13nScript, - }, { + }, + { Name: nginxServiceInstanceIdEnvVar, ValueFrom: &corev1.EnvVarSource{ FieldRef: &corev1.ObjectFieldSelector{ diff --git a/internal/instrumentation/python.go b/internal/instrumentation/python.go index c1090f924b..605ac3e275 100644 --- a/internal/instrumentation/python.go +++ b/internal/instrumentation/python.go @@ -73,7 +73,7 @@ func injectPythonSDKToContainer(pythonSpec v1alpha1.Python, container *corev1.Co return nil } -func injectPythonSDKToPod(pythonSpec v1alpha1.Python, pod corev1.Pod, firstContainerName string, platform string, instSpec v1alpha1.InstrumentationSpec) corev1.Pod { +func injectPythonSDKToPod(pythonSpec v1alpha1.Python, pod corev1.Pod, firstContainerName, platform string, instSpec v1alpha1.InstrumentationSpec) corev1.Pod { volume := instrVolume(pythonSpec.VolumeClaimTemplate, pythonVolumeName, pythonSpec.VolumeSizeLimit) // This has been validated already diff --git a/internal/manifests/collector/configmap.go b/internal/manifests/collector/configmap.go index a402229342..cdc5a156e1 100644 --- a/internal/manifests/collector/configmap.go +++ b/internal/manifests/collector/configmap.go @@ -59,7 +59,6 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) { } replacedConf, err := ReplaceConfig(*otelCol, params.TargetAllocator, replaceCfgOpts...) - if err != nil { params.Log.V(2).Info("failed to update prometheus config to use sharded targets: ", "err", err) return nil, err diff --git a/internal/manifests/collector/suite_test.go b/internal/manifests/collector/suite_test.go index 9ccac43f78..c04a83d931 100644 --- a/internal/manifests/collector/suite_test.go +++ b/internal/manifests/collector/suite_test.go @@ -67,7 +67,6 @@ func paramsWithMode(mode v1beta1.Mode) manifests.Params { }, Spec: v1beta1.OpenTelemetryCollectorSpec{ OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.47.0", Ports: []v1beta1.PortsSpec{ { @@ -93,7 +92,7 @@ func paramsWithMode(mode v1beta1.Mode) manifests.Params { } } -func newParams(taContainerImage string, file string, cfg *config.Config) (manifests.Params, error) { +func newParams(taContainerImage, file string, cfg *config.Config) (manifests.Params, error) { replicas := int32(1) var configYAML []byte var err error diff --git a/internal/manifests/manifestutils/annotations_test.go b/internal/manifests/manifestutils/annotations_test.go index 5757a31c3a..b4f6f9329c 100644 --- a/internal/manifests/manifestutils/annotations_test.go +++ b/internal/manifests/manifestutils/annotations_test.go @@ -79,9 +79,10 @@ func TestUserAnnotations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", Namespace: "my-ns", - Annotations: map[string]string{"prometheus.io/scrape": "false", - "prometheus.io/port": "1234", - "prometheus.io/path": "/test", + Annotations: map[string]string{ + "prometheus.io/scrape": "false", + "prometheus.io/port": "1234", + "prometheus.io/path": "/test", }, }, Spec: v1beta1.OpenTelemetryCollectorSpec{ diff --git a/internal/manifests/manifestutils/labels_test.go b/internal/manifests/manifestutils/labels_test.go index e171676502..36a35df4c4 100644 --- a/internal/manifests/manifestutils/labels_test.go +++ b/internal/manifests/manifestutils/labels_test.go @@ -40,6 +40,7 @@ func TestLabelsCommonSet(t *testing.T) { assert.Equal(t, "opentelemetry", labels["app.kubernetes.io/part-of"]) assert.Equal(t, "opentelemetry-collector", labels["app.kubernetes.io/component"]) } + func TestLabelsSha256Set(t *testing.T) { // prepare otelcol := v1alpha1.OpenTelemetryCollector{ @@ -79,6 +80,7 @@ func TestLabelsSha256Set(t *testing.T) { assert.Equal(t, "opentelemetry", labelsTag["app.kubernetes.io/part-of"]) assert.Equal(t, "opentelemetry-collector", labelsTag["app.kubernetes.io/component"]) } + func TestLabelsTagUnset(t *testing.T) { // prepare otelcol := v1alpha1.OpenTelemetryCollector{ diff --git a/internal/manifests/opampbridge/configmap_test.go b/internal/manifests/opampbridge/configmap_test.go index da1d6c2ee6..1321f4b330 100644 --- a/internal/manifests/opampbridge/configmap_test.go +++ b/internal/manifests/opampbridge/configmap_test.go @@ -52,7 +52,8 @@ description: endpoint: ws://opamp-server:4320/v1/opamp headers: authorization: access-12345-token -`} +`, + } tests := []struct { description string image string diff --git a/internal/manifests/opampbridge/container.go b/internal/manifests/opampbridge/container.go index f7d90d07a5..76d3572460 100644 --- a/internal/manifests/opampbridge/container.go +++ b/internal/manifests/opampbridge/container.go @@ -30,7 +30,7 @@ func Container(cfg config.Config, _ logr.Logger, opampBridge v1alpha1.OpAMPBridg volumeMounts = append(volumeMounts, opampBridge.Spec.VolumeMounts...) } - var envVars = opampBridge.Spec.Env + envVars := opampBridge.Spec.Env if opampBridge.Spec.Env == nil { envVars = []corev1.EnvVar{} } diff --git a/internal/manifests/targetallocator/container.go b/internal/manifests/targetallocator/container.go index 0333dbf0c0..818d414a63 100644 --- a/internal/manifests/targetallocator/container.go +++ b/internal/manifests/targetallocator/container.go @@ -48,7 +48,7 @@ func Container(cfg config.Config, _ logr.Logger, instance v1alpha1.TargetAllocat }} volumeMounts = append(volumeMounts, instance.Spec.VolumeMounts...) - var envVars = instance.Spec.Env + envVars := instance.Spec.Env if envVars == nil { envVars = []corev1.EnvVar{} } diff --git a/internal/manifests/targetallocator/container_test.go b/internal/manifests/targetallocator/container_test.go index 032a409119..e307fced31 100644 --- a/internal/manifests/targetallocator/container_test.go +++ b/internal/manifests/targetallocator/container_test.go @@ -354,6 +354,7 @@ func TestContainerDoesNotOverrideEnvVars(t *testing.T) { // verify assert.Equal(t, expected, c) } + func TestReadinessProbe(t *testing.T) { targetAllocator := v1alpha1.TargetAllocator{} cfg := config.New() @@ -372,6 +373,7 @@ func TestReadinessProbe(t *testing.T) { // verify assert.Equal(t, expected, c.ReadinessProbe) } + func TestLivenessProbe(t *testing.T) { // prepare targetAllocator := v1alpha1.TargetAllocator{} diff --git a/internal/manifests/targetallocator/deployment_test.go b/internal/manifests/targetallocator/deployment_test.go index 2fb8a037a3..6d0863d055 100644 --- a/internal/manifests/targetallocator/deployment_test.go +++ b/internal/manifests/targetallocator/deployment_test.go @@ -61,8 +61,10 @@ var testAffinityValue = &v1.Affinity{ }, } -var runAsUser int64 = 1000 -var runAsGroup int64 = 1000 +var ( + runAsUser int64 = 1000 + runAsGroup int64 = 1000 +) var testSecurityContextValue = &v1.PodSecurityContext{ RunAsUser: &runAsUser, diff --git a/internal/manifests/targetallocator/volume.go b/internal/manifests/targetallocator/volume.go index ce0ab4056c..8354d08ea5 100644 --- a/internal/manifests/targetallocator/volume.go +++ b/internal/manifests/targetallocator/volume.go @@ -24,7 +24,8 @@ func Volumes(cfg config.Config, instance v1alpha1.TargetAllocator) []corev1.Volu { Key: cfg.TargetAllocatorConfigMapEntry, Path: cfg.TargetAllocatorConfigMapEntry, - }}, + }, + }, }, }, }} diff --git a/internal/naming/dns_test.go b/internal/naming/dns_test.go index b52d77e58d..9028ca55d6 100644 --- a/internal/naming/dns_test.go +++ b/internal/naming/dns_test.go @@ -14,7 +14,7 @@ import ( ) func TestDnsName(t *testing.T) { - var tests = []struct { + tests := []struct { in string out string }{ diff --git a/internal/operator-metrics/metrics_test.go b/internal/operator-metrics/metrics_test.go index e45412ce39..1b83c2b6dd 100644 --- a/internal/operator-metrics/metrics_test.go +++ b/internal/operator-metrics/metrics_test.go @@ -68,7 +68,7 @@ func TestOperatorMetrics_Start(t *testing.T) { defer cancelTimeout() // Wait until one service monitor is being created - var serviceMonitor = &monitoringv1.ServiceMonitor{} + serviceMonitor := &monitoringv1.ServiceMonitor{} err = wait.PollUntilContextTimeout( ctxTimeout, time.Millisecond*100,