Skip to content
Merged
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
3 changes: 1 addition & 2 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions apis/v1alpha1/instrumentation_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
})
}
}

func TestInstrumentationValidatingWebhook_DeprecationWarnings(t *testing.T) {
defaultSize := resource.MustParse("200Mi")

Expand Down
4 changes: 1 addition & 3 deletions apis/v1beta1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions apis/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions apis/v1beta1/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -826,7 +825,6 @@ func TestConfig_GetExporterPorts(t *testing.T) {
want []v1.ServicePort
wantErr bool
}{

{
name: "connectors",
file: "testdata/otelcol-connectors.yaml",
Expand Down
6 changes: 4 additions & 2 deletions apis/v1beta1/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand 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 {
Expand Down
2 changes: 1 addition & 1 deletion apis/v1beta1/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}{
Expand Down
66 changes: 32 additions & 34 deletions apis/v1beta1/targetallocator_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading