diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 2daebb5c4a..35a2f7552d 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -371,8 +371,7 @@ type Nginx struct { } // InstrumentationStatus defines status of the instrumentation. -type InstrumentationStatus struct { -} +type InstrumentationStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:resource:shortName=otelinst;otelinsts diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index c074b91431..8bd4f5a93b 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -218,7 +218,6 @@ func (InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings, // Example: `endpoint=http://localhost:14250,pollingIntervalMs=5000,initialSamplingRate=0.25` if r.Spec.Argument != "" { err := validateJaegerRemoteSamplerArgument(r.Spec.Argument) - if err != nil { return warnings, fmt.Errorf("spec.sampler.argument is not a valid argument for sampler %s: %w", r.Spec.Type, err) } diff --git a/apis/v1alpha1/instrumentation_webhook_test.go b/apis/v1alpha1/instrumentation_webhook_test.go index a9b1b62466..71a16145be 100644 --- a/apis/v1alpha1/instrumentation_webhook_test.go +++ b/apis/v1alpha1/instrumentation_webhook_test.go @@ -621,6 +621,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) { }) } } + func TestInstrumentationValidatingWebhook_DeprecationWarnings(t *testing.T) { defaultSize := resource.MustParse("200Mi") diff --git a/apis/v1beta1/collector_webhook_test.go b/apis/v1beta1/collector_webhook_test.go index 6191f9e1e7..051b574696 100644 --- a/apis/v1beta1/collector_webhook_test.go +++ b/apis/v1beta1/collector_webhook_test.go @@ -37,9 +37,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/rbac" ) -var ( - testScheme = scheme.Scheme -) +var testScheme = scheme.Scheme func TestValidate(t *testing.T) { tests := []struct { diff --git a/apis/v1beta1/config.go b/apis/v1beta1/config.go index 4a07865b1b..2d5aa50c8d 100644 --- a/apis/v1beta1/config.go +++ b/apis/v1beta1/config.go @@ -70,8 +70,10 @@ func (c *AnyConfig) DeepCopy() *AnyConfig { return out } -var _ json.Marshaler = &AnyConfig{} -var _ json.Unmarshaler = &AnyConfig{} +var ( + _ json.Marshaler = &AnyConfig{} + _ json.Unmarshaler = &AnyConfig{} +) // UnmarshalJSON implements an alternative parser for this field. func (c *AnyConfig) UnmarshalJSON(b []byte) error { @@ -234,7 +236,7 @@ func (c *Config) getPortsForComponentKinds(logger logr.Logger, componentKinds .. // getEnvironmentVariablesForComponentKinds gets the environment variables for the given ComponentKind(s). func (c *Config) getEnvironmentVariablesForComponentKinds(logger logr.Logger, componentKinds ...ComponentKind) ([]corev1.EnvVar, error) { - var envVars = []corev1.EnvVar{} + envVars := []corev1.EnvVar{} enabledComponents := c.GetEnabledComponents() for _, componentKind := range componentKinds { var retriever components.ParserRetriever diff --git a/apis/v1beta1/config_test.go b/apis/v1beta1/config_test.go index 7c9d9ff76c..c8aef5adad 100644 --- a/apis/v1beta1/config_test.go +++ b/apis/v1beta1/config_test.go @@ -559,7 +559,6 @@ func TestConfig_GetEnabledComponents(t *testing.T) { file string want map[ComponentKind]map[string]any }{ - { name: "connectors", file: "testdata/otelcol-connectors.yaml", @@ -826,7 +825,6 @@ func TestConfig_GetExporterPorts(t *testing.T) { want []v1.ServicePort wantErr bool }{ - { name: "connectors", file: "testdata/otelcol-connectors.yaml", diff --git a/apis/v1beta1/metrics.go b/apis/v1beta1/metrics.go index b16e3225fa..48ec96c8c4 100644 --- a/apis/v1beta1/metrics.go +++ b/apis/v1beta1/metrics.go @@ -131,7 +131,7 @@ func (m *Metrics) delete(ctx context.Context, collector *OpenTelemetryCollector) m.updateGeneralCRMetricsComponents(ctx, collector, false) } -func (m *Metrics) update(ctx context.Context, oldCollector *OpenTelemetryCollector, newCollector *OpenTelemetryCollector) { +func (m *Metrics) update(ctx context.Context, oldCollector, newCollector *OpenTelemetryCollector) { m.delete(ctx, oldCollector) m.create(ctx, newCollector) } @@ -147,6 +147,7 @@ func (m *Metrics) updateGeneralCRMetricsComponents(ctx context.Context, collecto attribute.Key("type").String(string(collector.Spec.Mode)), )) } + func (m *Metrics) updateComponentCounters(ctx context.Context, collector *OpenTelemetryCollector, up bool) { components := getComponentsFromConfig(collector.Spec.Config) moveCounter(ctx, collector, components.receivers, m.receiversCounter, up) @@ -197,7 +198,8 @@ func getComponentsFromConfig(yamlContent Config) *componentDefinitions { } func moveCounter( - ctx context.Context, collector *OpenTelemetryCollector, types []string, upDown metric.Int64UpDownCounter, up bool) { + ctx context.Context, collector *OpenTelemetryCollector, types []string, upDown metric.Int64UpDownCounter, up bool, +) { for _, exporter := range types { inc := 1 if !up { diff --git a/apis/v1beta1/metrics_test.go b/apis/v1beta1/metrics_test.go index 12f347563b..f1a043c600 100644 --- a/apis/v1beta1/metrics_test.go +++ b/apis/v1beta1/metrics_test.go @@ -104,7 +104,7 @@ func TestOTELCollectorCRDMetrics(t *testing.T) { }, } - var tests = []struct { + tests := []struct { name string testFunction func(t *testing.T, m *Metrics, collectors []*OpenTelemetryCollector, reader metric.Reader) }{ diff --git a/apis/v1beta1/targetallocator_rbac.go b/apis/v1beta1/targetallocator_rbac.go index 09a0e78213..19063558c8 100644 --- a/apis/v1beta1/targetallocator_rbac.go +++ b/apis/v1beta1/targetallocator_rbac.go @@ -12,45 +12,43 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/rbac" ) -var ( - - // targetAllocatorCRPolicyRules are the policy rules required for the CR functionality. - targetAllocatorCRPolicyRules = []*rbacv1.PolicyRule{ - { - APIGroups: []string{"monitoring.coreos.com"}, - Resources: []string{"servicemonitors", "podmonitors"}, - Verbs: []string{"*"}, - }, { - APIGroups: []string{""}, - Resources: []string{"nodes", "nodes/metrics", "services", "endpoints", "pods", "namespaces"}, - Verbs: []string{"get", "list", "watch"}, - }, { - APIGroups: []string{""}, - Resources: []string{"configmaps"}, - Verbs: []string{"get"}, - }, { - APIGroups: []string{"discovery.k8s.io"}, - Resources: []string{"endpointslices"}, - Verbs: []string{"get", "list", "watch"}, - }, { - APIGroups: []string{"networking.k8s.io"}, - Resources: []string{"ingresses"}, - Verbs: []string{"get", "list", "watch"}, - }, { - NonResourceURLs: []string{"/metrics"}, - Verbs: []string{"get"}, - }, { - NonResourceURLs: []string{"/api", "/api/*", "/apis", "/apis/*"}, - Verbs: []string{"get"}, - }, - } -) +// targetAllocatorCRPolicyRules are the policy rules required for the CR functionality. +var targetAllocatorCRPolicyRules = []*rbacv1.PolicyRule{ + { + APIGroups: []string{"monitoring.coreos.com"}, + Resources: []string{"servicemonitors", "podmonitors"}, + Verbs: []string{"*"}, + }, { + APIGroups: []string{""}, + Resources: []string{"nodes", "nodes/metrics", "services", "endpoints", "pods", "namespaces"}, + Verbs: []string{"get", "list", "watch"}, + }, { + APIGroups: []string{""}, + Resources: []string{"configmaps"}, + Verbs: []string{"get"}, + }, { + APIGroups: []string{"discovery.k8s.io"}, + Resources: []string{"endpointslices"}, + Verbs: []string{"get", "list", "watch"}, + }, { + APIGroups: []string{"networking.k8s.io"}, + Resources: []string{"ingresses"}, + Verbs: []string{"get", "list", "watch"}, + }, { + NonResourceURLs: []string{"/metrics"}, + Verbs: []string{"get"}, + }, { + NonResourceURLs: []string{"/api", "/api/*", "/apis", "/apis/*"}, + Verbs: []string{"get"}, + }, +} func CheckTargetAllocatorPrometheusCRPolicyRules( ctx context.Context, reviewer *rbac.Reviewer, namespace string, - serviceAccountName string) (warnings []string, err error) { + serviceAccountName string, +) (warnings []string, err error) { subjectAccessReviews, err := reviewer.CheckPolicyRules( ctx, serviceAccountName,