From 17c39e9c164240a8b6edf8eb0e07e58ee8fdc75c Mon Sep 17 00:00:00 2001 From: Yuri Sa <48062171+yuriolisa@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:36:45 +0100 Subject: [PATCH] Added linters (#1287) * Added linters * Small changes into golanci Signed-off-by: Yuri Sa * Small changes into golanci Signed-off-by: Yuri Sa Signed-off-by: Yuri Sa --- .golangci.yaml | 6 +++ apis/v1alpha1/instrumentation_webhook.go | 40 +++++++++---------- cmd/otel-allocator/discovery/discovery.go | 4 +- .../discovery/discovery_test.go | 2 +- cmd/otel-allocator/main.go | 6 +-- cmd/otel-allocator/prehook/relabel.go | 4 +- .../opentelemetrycollector_controller_test.go | 4 +- pkg/collector/daemonset.go | 2 +- pkg/collector/daemonset_test.go | 24 +++++------ pkg/collector/deployment.go | 2 +- pkg/collector/deployment_test.go | 32 +++++++-------- pkg/collector/reconcile/config_replace.go | 2 +- pkg/collector/reconcile/ingress_test.go | 8 ++-- pkg/collector/statefulset.go | 2 +- pkg/collector/statefulset_test.go | 32 +++++++-------- pkg/collector/upgrade/v0_36_0.go | 10 ++--- pkg/collector/utils.go | 2 +- pkg/instrumentation/dotnet.go | 4 +- pkg/instrumentation/dotnet_test.go | 2 +- pkg/instrumentation/podmutator_test.go | 2 +- pkg/instrumentation/sdk_test.go | 2 +- 21 files changed, 99 insertions(+), 93 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index f1a7317c86..e763616e1e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -24,3 +24,9 @@ linters: - exhaustive - godot - unparam + - gosimple + - unused + - staticcheck + - ineffassign + - typecheck + - unparam \ No newline at end of file diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index 0a19653ce8..39ab6c8662 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -86,59 +86,59 @@ func (r *Instrumentation) Default() { var _ webhook.Validator = &Instrumentation{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type. -func (in *Instrumentation) ValidateCreate() error { - instrumentationlog.Info("validate create", "name", in.Name) - return in.validate() +func (r *Instrumentation) ValidateCreate() error { + instrumentationlog.Info("validate create", "name", r.Name) + return r.validate() } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. -func (in *Instrumentation) ValidateUpdate(old runtime.Object) error { - instrumentationlog.Info("validate update", "name", in.Name) - return in.validate() +func (r *Instrumentation) ValidateUpdate(old runtime.Object) error { + instrumentationlog.Info("validate update", "name", r.Name) + return r.validate() } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type. -func (in *Instrumentation) ValidateDelete() error { - instrumentationlog.Info("validate delete", "name", in.Name) +func (r *Instrumentation) ValidateDelete() error { + instrumentationlog.Info("validate delete", "name", r.Name) return nil } -func (in *Instrumentation) validate() error { - switch in.Spec.Sampler.Type { +func (r *Instrumentation) validate() error { + switch r.Spec.Sampler.Type { case TraceIDRatio, ParentBasedTraceIDRatio: - if in.Spec.Sampler.Argument != "" { - rate, err := strconv.ParseFloat(in.Spec.Sampler.Argument, 64) + if r.Spec.Sampler.Argument != "" { + rate, err := strconv.ParseFloat(r.Spec.Sampler.Argument, 64) if err != nil { - return fmt.Errorf("spec.sampler.argument is not a number: %s", in.Spec.Sampler.Argument) + return fmt.Errorf("spec.sampler.argument is not a number: %s", r.Spec.Sampler.Argument) } if rate < 0 || rate > 1 { - return fmt.Errorf("spec.sampler.argument should be in rage [0..1]: %s", in.Spec.Sampler.Argument) + return fmt.Errorf("spec.sampler.argument should be in rage [0..1]: %s", r.Spec.Sampler.Argument) } } case AlwaysOn, AlwaysOff, JaegerRemote, ParentBasedAlwaysOn, ParentBasedAlwaysOff, XRaySampler: } // validate env vars - if err := in.validateEnv(in.Spec.Env); err != nil { + if err := r.validateEnv(r.Spec.Env); err != nil { return err } - if err := in.validateEnv(in.Spec.Java.Env); err != nil { + if err := r.validateEnv(r.Spec.Java.Env); err != nil { return err } - if err := in.validateEnv(in.Spec.NodeJS.Env); err != nil { + if err := r.validateEnv(r.Spec.NodeJS.Env); err != nil { return err } - if err := in.validateEnv(in.Spec.Python.Env); err != nil { + if err := r.validateEnv(r.Spec.Python.Env); err != nil { return err } - if err := in.validateEnv(in.Spec.DotNet.Env); err != nil { + if err := r.validateEnv(r.Spec.DotNet.Env); err != nil { return err } return nil } -func (in *Instrumentation) validateEnv(envs []corev1.EnvVar) error { +func (r *Instrumentation) validateEnv(envs []corev1.EnvVar) error { for _, env := range envs { if !strings.HasPrefix(env.Name, envPrefix) && !strings.HasPrefix(env.Name, envSplunkPrefix) { return fmt.Errorf("env name should start with \"OTEL_\" or \"SPLUNK_\": %s", env.Name) diff --git a/cmd/otel-allocator/discovery/discovery.go b/cmd/otel-allocator/discovery/discovery.go index a68bebc261..814e302ef2 100644 --- a/cmd/otel-allocator/discovery/discovery.go +++ b/cmd/otel-allocator/discovery/discovery.go @@ -50,7 +50,7 @@ type discoveryHook interface { SetConfig(map[string][]*relabel.Config) } -func NewManager(log logr.Logger, ctx context.Context, logger log.Logger, hook discoveryHook, options ...func(*discovery.Manager)) *Manager { +func NewManager(ctx context.Context, log logr.Logger, logger log.Logger, hook discoveryHook, options ...func(*discovery.Manager)) *Manager { manager := discovery.NewManager(ctx, logger, options...) go func() { @@ -110,7 +110,7 @@ func (m *Manager) Watch(fn func(targets map[string]*target.Item)) { targets := map[string]*target.Item{} for jobName, tgs := range tsets { - var count float64 = 0 + var count float64 for _, tg := range tgs { for _, t := range tg.Targets { count++ diff --git a/cmd/otel-allocator/discovery/discovery_test.go b/cmd/otel-allocator/discovery/discovery_test.go index cadc9d8ef7..11de1b7ee7 100644 --- a/cmd/otel-allocator/discovery/discovery_test.go +++ b/cmd/otel-allocator/discovery/discovery_test.go @@ -52,7 +52,7 @@ func TestDiscovery(t *testing.T) { want: []string{"prom.domain:9004", "prom.domain:9005", "promfile.domain:1001", "promfile.domain:3000"}, }, } - manager := NewManager(ctrl.Log.WithName("test"), context.Background(), gokitlog.NewNopLogger(), nil) + manager := NewManager(context.Background(), ctrl.Log.WithName("test"), gokitlog.NewNopLogger(), nil) defer close(manager.close) results := make(chan []string) diff --git a/cmd/otel-allocator/main.go b/cmd/otel-allocator/main.go index 07d1373f17..6df8be6077 100644 --- a/cmd/otel-allocator/main.go +++ b/cmd/otel-allocator/main.go @@ -96,12 +96,12 @@ func main() { }() // creates a new discovery manager - discoveryManager := lbdiscovery.NewManager(log, ctx, gokitlog.NewNopLogger(), allocatorPrehook) + discoveryManager := lbdiscovery.NewManager(ctx, log, gokitlog.NewNopLogger(), allocatorPrehook) defer discoveryManager.Close() discoveryManager.Watch(allocator.SetTargets) - k8sclient, err := configureFileDiscovery(log, allocator, discoveryManager, context.Background(), cliConf) + k8sclient, err := configureFileDiscovery(context.Background(), log, allocator, discoveryManager, cliConf) if err != nil { setupLog.Error(err, "Can't start the k8s client") os.Exit(1) @@ -184,7 +184,7 @@ func newServer(log logr.Logger, allocator allocation.Allocator, discoveryManager return s } -func configureFileDiscovery(log logr.Logger, allocator allocation.Allocator, discoveryManager *lbdiscovery.Manager, ctx context.Context, cliConfig config.CLIConfig) (*collector.Client, error) { +func configureFileDiscovery(ctx context.Context, log logr.Logger, allocator allocation.Allocator, discoveryManager *lbdiscovery.Manager, cliConfig config.CLIConfig) (*collector.Client, error) { cfg, err := config.Load(*cliConfig.ConfigFilePath) if err != nil { return nil, err diff --git a/cmd/otel-allocator/prehook/relabel.go b/cmd/otel-allocator/prehook/relabel.go index 9786932571..6bd67a420b 100644 --- a/cmd/otel-allocator/prehook/relabel.go +++ b/cmd/otel-allocator/prehook/relabel.go @@ -60,11 +60,11 @@ func (tf *RelabelConfigTargetFilter) Apply(targets map[string]*target.Item) map[ keepTarget := true lset := convertLabelToPromLabelSet(tItem.Label) for _, cfg := range tf.relabelCfg[tItem.JobName] { - if new_lset := relabel.Process(lset, cfg); new_lset == nil { + if newLset := relabel.Process(lset, cfg); newLset == nil { keepTarget = false break // inner loop } else { - lset = new_lset + lset = newLset } } diff --git a/controllers/opentelemetrycollector_controller_test.go b/controllers/opentelemetrycollector_controller_test.go index b9324225b1..9b52cbb185 100644 --- a/controllers/opentelemetrycollector_controller_test.go +++ b/controllers/opentelemetrycollector_controller_test.go @@ -229,7 +229,7 @@ func TestContinueOnRecoverableFailure(t *testing.T) { { Name: "should-fail", Do: func(context.Context, reconcile.Params) error { - return errors.New("should fail!") + return errors.New("should fail") }, BailOnError: false, }, @@ -255,7 +255,7 @@ func TestBreakOnUnrecoverableError(t *testing.T) { // prepare cfg := config.New() taskCalled := false - expectedErr := errors.New("should fail!") + expectedErr := errors.New("should fail") nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} reconciler := controllers.NewReconciler(controllers.Params{ Client: k8sClient, diff --git a/pkg/collector/daemonset.go b/pkg/collector/daemonset.go index f8e1dcece7..565d1a92bc 100644 --- a/pkg/collector/daemonset.go +++ b/pkg/collector/daemonset.go @@ -55,7 +55,7 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem Tolerations: otelcol.Spec.Tolerations, NodeSelector: otelcol.Spec.NodeSelector, HostNetwork: otelcol.Spec.HostNetwork, - DNSPolicy: getDnsPolicy(otelcol), + DNSPolicy: getDNSPolicy(otelcol), SecurityContext: otelcol.Spec.PodSecurityContext, PriorityClassName: otelcol.Spec.PriorityClassName, Affinity: otelcol.Spec.Affinity, diff --git a/pkg/collector/daemonset_test.go b/pkg/collector/daemonset_test.go index fec8f7e9ab..e56187a735 100644 --- a/pkg/collector/daemonset_test.go +++ b/pkg/collector/daemonset_test.go @@ -177,7 +177,7 @@ func TestDaemonsetFilterLabels(t *testing.T) { func TestDaemonSetNodeSelector(t *testing.T) { // Test default - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -185,12 +185,12 @@ func TestDaemonSetNodeSelector(t *testing.T) { cfg := config.New() - d1 := DaemonSet(cfg, logger, otelcol_1) + d1 := DaemonSet(cfg, logger, otelcol1) assert.Empty(t, d1.Spec.Template.Spec.NodeSelector) // Test nodeSelector - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-nodeselector", }, @@ -204,12 +204,12 @@ func TestDaemonSetNodeSelector(t *testing.T) { cfg = config.New() - d2 := DaemonSet(cfg, logger, otelcol_2) + d2 := DaemonSet(cfg, logger, otelcol2) assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"}) } func TestDaemonSetPriorityClassName(t *testing.T) { - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -217,12 +217,12 @@ func TestDaemonSetPriorityClassName(t *testing.T) { cfg := config.New() - d1 := DaemonSet(cfg, logger, otelcol_1) + d1 := DaemonSet(cfg, logger, otelcol1) assert.Empty(t, d1.Spec.Template.Spec.PriorityClassName) priorityClassName := "test-class" - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-priortyClassName", }, @@ -233,12 +233,12 @@ func TestDaemonSetPriorityClassName(t *testing.T) { cfg = config.New() - d2 := DaemonSet(cfg, logger, otelcol_2) + d2 := DaemonSet(cfg, logger, otelcol2) assert.Equal(t, priorityClassName, d2.Spec.Template.Spec.PriorityClassName) } func TestDaemonSetAffinity(t *testing.T) { - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -246,10 +246,10 @@ func TestDaemonSetAffinity(t *testing.T) { cfg := config.New() - d1 := DaemonSet(cfg, logger, otelcol_1) + d1 := DaemonSet(cfg, logger, otelcol1) assert.Nil(t, d1.Spec.Template.Spec.Affinity) - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-priortyClassName", }, @@ -260,7 +260,7 @@ func TestDaemonSetAffinity(t *testing.T) { cfg = config.New() - d2 := DaemonSet(cfg, logger, otelcol_2) + d2 := DaemonSet(cfg, logger, otelcol2) assert.NotNil(t, d2.Spec.Template.Spec.Affinity) assert.Equal(t, *testAffinityValue, *d2.Spec.Template.Spec.Affinity) } diff --git a/pkg/collector/deployment.go b/pkg/collector/deployment.go index 116790751c..cb0211fbf8 100644 --- a/pkg/collector/deployment.go +++ b/pkg/collector/deployment.go @@ -54,7 +54,7 @@ func Deployment(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTele ServiceAccountName: ServiceAccountName(otelcol), Containers: []corev1.Container{Container(cfg, logger, otelcol)}, Volumes: Volumes(cfg, otelcol), - DNSPolicy: getDnsPolicy(otelcol), + DNSPolicy: getDNSPolicy(otelcol), HostNetwork: otelcol.Spec.HostNetwork, Tolerations: otelcol.Spec.Tolerations, NodeSelector: otelcol.Spec.NodeSelector, diff --git a/pkg/collector/deployment_test.go b/pkg/collector/deployment_test.go index 435d49e949..601f22c595 100644 --- a/pkg/collector/deployment_test.go +++ b/pkg/collector/deployment_test.go @@ -161,7 +161,7 @@ func TestDeploymenttPodSecurityContext(t *testing.T) { func TestDeploymentHostNetwork(t *testing.T) { // Test default - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -169,13 +169,13 @@ func TestDeploymentHostNetwork(t *testing.T) { cfg := config.New() - d1 := Deployment(cfg, logger, otelcol_1) + d1 := Deployment(cfg, logger, otelcol1) assert.Equal(t, d1.Spec.Template.Spec.HostNetwork, false) assert.Equal(t, d1.Spec.Template.Spec.DNSPolicy, v1.DNSClusterFirst) // Test hostNetwork=true - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-hostnetwork", }, @@ -186,7 +186,7 @@ func TestDeploymentHostNetwork(t *testing.T) { cfg = config.New() - d2 := Deployment(cfg, logger, otelcol_2) + d2 := Deployment(cfg, logger, otelcol2) assert.Equal(t, d2.Spec.Template.Spec.HostNetwork, true) assert.Equal(t, d2.Spec.Template.Spec.DNSPolicy, v1.DNSClusterFirstWithHostNet) } @@ -217,7 +217,7 @@ func TestDeploymentFilterLabels(t *testing.T) { func TestDeploymentNodeSelector(t *testing.T) { // Test default - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -225,12 +225,12 @@ func TestDeploymentNodeSelector(t *testing.T) { cfg := config.New() - d1 := Deployment(cfg, logger, otelcol_1) + d1 := Deployment(cfg, logger, otelcol1) assert.Empty(t, d1.Spec.Template.Spec.NodeSelector) // Test nodeSelector - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-nodeselector", }, @@ -244,12 +244,12 @@ func TestDeploymentNodeSelector(t *testing.T) { cfg = config.New() - d2 := Deployment(cfg, logger, otelcol_2) + d2 := Deployment(cfg, logger, otelcol2) assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"}) } func TestDeploymentPriorityClassName(t *testing.T) { - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -257,12 +257,12 @@ func TestDeploymentPriorityClassName(t *testing.T) { cfg := config.New() - d1 := Deployment(cfg, logger, otelcol_1) + d1 := Deployment(cfg, logger, otelcol1) assert.Empty(t, d1.Spec.Template.Spec.PriorityClassName) priorityClassName := "test-class" - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-priortyClassName", }, @@ -273,12 +273,12 @@ func TestDeploymentPriorityClassName(t *testing.T) { cfg = config.New() - d2 := Deployment(cfg, logger, otelcol_2) + d2 := Deployment(cfg, logger, otelcol2) assert.Equal(t, priorityClassName, d2.Spec.Template.Spec.PriorityClassName) } func TestDeploymentAffinity(t *testing.T) { - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -286,10 +286,10 @@ func TestDeploymentAffinity(t *testing.T) { cfg := config.New() - d1 := Deployment(cfg, logger, otelcol_1) + d1 := Deployment(cfg, logger, otelcol1) assert.Nil(t, d1.Spec.Template.Spec.Affinity) - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-priortyClassName", }, @@ -300,7 +300,7 @@ func TestDeploymentAffinity(t *testing.T) { cfg = config.New() - d2 := Deployment(cfg, logger, otelcol_2) + d2 := Deployment(cfg, logger, otelcol2) assert.NotNil(t, d2.Spec.Template.Spec.Affinity) assert.Equal(t, *testAffinityValue, *d2.Spec.Template.Spec.Affinity) } diff --git a/pkg/collector/reconcile/config_replace.go b/pkg/collector/reconcile/config_replace.go index 3d18d2d15f..7de12081bd 100644 --- a/pkg/collector/reconcile/config_replace.go +++ b/pkg/collector/reconcile/config_replace.go @@ -22,7 +22,7 @@ import ( promconfig "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/discovery" "github.com/prometheus/prometheus/discovery/http" - _ "github.com/prometheus/prometheus/discovery/install" + _ "github.com/prometheus/prometheus/discovery/install" // Package install has the side-effect of registering all builtin. "gopkg.in/yaml.v2" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters" diff --git a/pkg/collector/reconcile/ingress_test.go b/pkg/collector/reconcile/ingress_test.go index 7324a14812..8608011bd2 100644 --- a/pkg/collector/reconcile/ingress_test.go +++ b/pkg/collector/reconcile/ingress_test.go @@ -31,7 +31,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/pkg/naming" ) -const test_file_ingress = "../testdata/ingress_testdata.yaml" +const testFileIngress = "../testdata/ingress_testdata.yaml" func TestDesiredIngresses(t *testing.T) { t.Run("should return nil invalid ingress type", func(t *testing.T) { @@ -97,7 +97,7 @@ func TestDesiredIngresses(t *testing.T) { ingressClassName = "nginx" ) - params, err := newParams("something:tag", test_file_ingress) + params, err := newParams("something:tag", testFileIngress) if err != nil { t.Fatal(err) } @@ -183,7 +183,7 @@ func TestExpectedIngresses(t *testing.T) { t.Run("should create and update ingress entry", func(t *testing.T) { ctx := context.Background() - params, err := newParams("something:tag", test_file_ingress) + params, err := newParams("something:tag", testFileIngress) if err != nil { t.Fatal(err) } @@ -225,7 +225,7 @@ func TestDeleteIngresses(t *testing.T) { // create ctx := context.Background() - myParams, err := newParams("something:tag", test_file_ingress) + myParams, err := newParams("something:tag", testFileIngress) if err != nil { t.Fatal(err) } diff --git a/pkg/collector/statefulset.go b/pkg/collector/statefulset.go index 76bd1c6dcb..ba76d47324 100644 --- a/pkg/collector/statefulset.go +++ b/pkg/collector/statefulset.go @@ -54,7 +54,7 @@ func StatefulSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTel ServiceAccountName: ServiceAccountName(otelcol), Containers: []corev1.Container{Container(cfg, logger, otelcol)}, Volumes: Volumes(cfg, otelcol), - DNSPolicy: getDnsPolicy(otelcol), + DNSPolicy: getDNSPolicy(otelcol), HostNetwork: otelcol.Spec.HostNetwork, Tolerations: otelcol.Spec.Tolerations, NodeSelector: otelcol.Spec.NodeSelector, diff --git a/pkg/collector/statefulset_test.go b/pkg/collector/statefulset_test.go index c71823ce54..66ccbae389 100644 --- a/pkg/collector/statefulset_test.go +++ b/pkg/collector/statefulset_test.go @@ -202,7 +202,7 @@ func TestStatefulSetPodSecurityContext(t *testing.T) { func TestStatefulSetHostNetwork(t *testing.T) { // Test default - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -210,13 +210,13 @@ func TestStatefulSetHostNetwork(t *testing.T) { cfg := config.New() - d1 := StatefulSet(cfg, logger, otelcol_1) + d1 := StatefulSet(cfg, logger, otelcol1) assert.Equal(t, d1.Spec.Template.Spec.HostNetwork, false) assert.Equal(t, d1.Spec.Template.Spec.DNSPolicy, v1.DNSClusterFirst) // Test hostNetwork=true - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-hostnetwork", }, @@ -227,7 +227,7 @@ func TestStatefulSetHostNetwork(t *testing.T) { cfg = config.New() - d2 := StatefulSet(cfg, logger, otelcol_2) + d2 := StatefulSet(cfg, logger, otelcol2) assert.Equal(t, d2.Spec.Template.Spec.HostNetwork, true) assert.Equal(t, d2.Spec.Template.Spec.DNSPolicy, v1.DNSClusterFirstWithHostNet) } @@ -258,7 +258,7 @@ func TestStatefulSetFilterLabels(t *testing.T) { func TestStatefulSetNodeSelector(t *testing.T) { // Test default - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -266,12 +266,12 @@ func TestStatefulSetNodeSelector(t *testing.T) { cfg := config.New() - d1 := StatefulSet(cfg, logger, otelcol_1) + d1 := StatefulSet(cfg, logger, otelcol1) assert.Empty(t, d1.Spec.Template.Spec.NodeSelector) // Test nodeSelector - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-nodeselector", }, @@ -285,12 +285,12 @@ func TestStatefulSetNodeSelector(t *testing.T) { cfg = config.New() - d2 := StatefulSet(cfg, logger, otelcol_2) + d2 := StatefulSet(cfg, logger, otelcol2) assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"}) } func TestStatefulSetPriorityClassName(t *testing.T) { - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -298,12 +298,12 @@ func TestStatefulSetPriorityClassName(t *testing.T) { cfg := config.New() - sts1 := StatefulSet(cfg, logger, otelcol_1) + sts1 := StatefulSet(cfg, logger, otelcol1) assert.Empty(t, sts1.Spec.Template.Spec.PriorityClassName) priorityClassName := "test-class" - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-priortyClassName", }, @@ -314,12 +314,12 @@ func TestStatefulSetPriorityClassName(t *testing.T) { cfg = config.New() - sts2 := StatefulSet(cfg, logger, otelcol_2) + sts2 := StatefulSet(cfg, logger, otelcol2) assert.Equal(t, priorityClassName, sts2.Spec.Template.Spec.PriorityClassName) } func TestStatefulSetAffinity(t *testing.T) { - otelcol_1 := v1alpha1.OpenTelemetryCollector{ + otelcol1 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -327,10 +327,10 @@ func TestStatefulSetAffinity(t *testing.T) { cfg := config.New() - sts1 := Deployment(cfg, logger, otelcol_1) + sts1 := Deployment(cfg, logger, otelcol1) assert.Nil(t, sts1.Spec.Template.Spec.Affinity) - otelcol_2 := v1alpha1.OpenTelemetryCollector{ + otelcol2 := v1alpha1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-priortyClassName", }, @@ -341,7 +341,7 @@ func TestStatefulSetAffinity(t *testing.T) { cfg = config.New() - sts2 := StatefulSet(cfg, logger, otelcol_2) + sts2 := StatefulSet(cfg, logger, otelcol2) assert.NotNil(t, sts2.Spec.Template.Spec.Affinity) assert.Equal(t, *testAffinityValue, *sts2.Spec.Template.Spec.Affinity) } diff --git a/pkg/collector/upgrade/v0_36_0.go b/pkg/collector/upgrade/v0_36_0.go index 2460154ebd..875b7a04c5 100644 --- a/pkg/collector/upgrade/v0_36_0.go +++ b/pkg/collector/upgrade/v0_36_0.go @@ -65,16 +65,16 @@ func upgrade0_36_0(u VersionUpgrade, otelcol *v1alpha1.OpenTelemetryCollector) ( for k3, v3 := range protocConfig { // grpc config if k3 == "grpc" || k3 == "http" { - grpcHttpConfig, ok := v3.(map[interface{}]interface{}) + grpcHTTPConfig, ok := v3.(map[interface{}]interface{}) if !ok { - // no grpcHttpConfig? no need to fail because of that + // no grpcHTTPConfig? no need to fail because of that return otelcol, nil } - for k4, v4 := range grpcHttpConfig { + for k4, v4 := range grpcHTTPConfig { // change tls_settings to tls if k4.(string) == "tls_settings" { - grpcHttpConfig["tls"] = v4 - delete(grpcHttpConfig, "tls_settings") + grpcHTTPConfig["tls"] = v4 + delete(grpcHTTPConfig, "tls_settings") existing := &corev1.ConfigMap{} updated := existing.DeepCopy() u.Recorder.Event(updated, "Normal", "Upgrade", fmt.Sprintf("upgrade to v0.36.0 has changed the tls_settings field name to tls in %s protocol of %s receiver", k3, k1)) diff --git a/pkg/collector/utils.go b/pkg/collector/utils.go index 813910bc45..36d6833455 100644 --- a/pkg/collector/utils.go +++ b/pkg/collector/utils.go @@ -20,7 +20,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" ) -func getDnsPolicy(otelcol v1alpha1.OpenTelemetryCollector) corev1.DNSPolicy { +func getDNSPolicy(otelcol v1alpha1.OpenTelemetryCollector) corev1.DNSPolicy { dnsPolicy := corev1.DNSClusterFirst if otelcol.Spec.HostNetwork { dnsPolicy = corev1.DNSClusterFirstWithHostNet diff --git a/pkg/instrumentation/dotnet.go b/pkg/instrumentation/dotnet.go index aecf7c3e89..d10d7ad93f 100644 --- a/pkg/instrumentation/dotnet.go +++ b/pkg/instrumentation/dotnet.go @@ -32,7 +32,7 @@ const ( envDotNetStartupHook = "DOTNET_STARTUP_HOOKS" envDotNetOTelAutoHome = "OTEL_DOTNET_AUTO_HOME" dotNetCoreClrEnableProfilingEnabled = "1" - dotNetCoreClrProfilerId = "{918728DD-259F-4A6A-AC2B-B85E1B658318}" + dotNetCoreClrProfilerID = "{918728DD-259F-4A6A-AC2B-B85E1B658318}" dotNetCoreClrProfilerPath = "/otel-auto-instrumentation/OpenTelemetry.AutoInstrumentation.Native.so" dotNetAdditionalDepsPath = "/otel-auto-instrumentation/AdditionalDeps" dotNetOTelAutoHomePath = "/otel-auto-instrumentation" @@ -77,7 +77,7 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int) (cor setDotNetEnvVar(container, envDotNetCoreClrEnableProfiling, dotNetCoreClrEnableProfilingEnabled, doNotConcatEnvValues) - setDotNetEnvVar(container, envDotNetCoreClrProfiler, dotNetCoreClrProfilerId, doNotConcatEnvValues) + setDotNetEnvVar(container, envDotNetCoreClrProfiler, dotNetCoreClrProfilerID, doNotConcatEnvValues) setDotNetEnvVar(container, envDotNetCoreClrProfilerPath, dotNetCoreClrProfilerPath, doNotConcatEnvValues) diff --git a/pkg/instrumentation/dotnet_test.go b/pkg/instrumentation/dotnet_test.go index eab7fb85c2..7bfc78a358 100644 --- a/pkg/instrumentation/dotnet_test.go +++ b/pkg/instrumentation/dotnet_test.go @@ -78,7 +78,7 @@ func TestInjectDotNetSDK(t *testing.T) { }, { Name: envDotNetCoreClrProfiler, - Value: dotNetCoreClrProfilerId, + Value: dotNetCoreClrProfilerID, }, { Name: envDotNetCoreClrProfilerPath, diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 3418b5533b..352f208d63 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -664,7 +664,7 @@ func TestMutatePod(t *testing.T) { }, { Name: envDotNetCoreClrProfiler, - Value: dotNetCoreClrProfilerId, + Value: dotNetCoreClrProfilerID, }, { Name: envDotNetCoreClrProfilerPath, diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index c900193f2d..077b0f34df 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -740,7 +740,7 @@ func TestInjectDotNet(t *testing.T) { }, { Name: envDotNetCoreClrProfiler, - Value: dotNetCoreClrProfilerId, + Value: dotNetCoreClrProfilerID, }, { Name: envDotNetCoreClrProfilerPath,