Skip to content

Commit

Permalink
Remove collectorSelector field from TA CRD (#3039)
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Jun 15, 2024
1 parent 46b032c commit c490d80
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 73 deletions.
2 changes: 0 additions & 2 deletions apis/v1alpha1/targetallocator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ type TargetAllocatorStatus struct {
type TargetAllocatorSpec struct {
// Common defines fields that are common to all OpenTelemetry CRD workloads.
v1beta1.OpenTelemetryCommonFields `json:",inline"`
// CollectorSelector is the selector for Collector Pods the target allocator will allocate targets to.
CollectorSelector metav1.LabelSelector `json:"collectorSelector,omitempty"`
// AllocationStrategy determines which strategy the target allocator should use for allocation.
// The current options are least-weighted, consistent-hashing and per-node. The default is
// consistent-hashing.
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions config/crd/bases/opentelemetry.io_targetallocators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1078,30 +1078,6 @@ spec:
additionalProperties:
type: string
type: object
collectorSelector:
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
env:
items:
properties:
Expand Down
6 changes: 0 additions & 6 deletions internal/manifests/collector/targetallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
)

Expand All @@ -32,10 +31,6 @@ func TargetAllocator(params manifests.Params) (*v1alpha1.TargetAllocator, error)
return nil, nil
}

collectorSelector := metav1.LabelSelector{
MatchLabels: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector),
}

configStr, err := params.OtelCol.Spec.Config.Yaml()
if err != nil {
return nil, err
Expand Down Expand Up @@ -68,7 +63,6 @@ func TargetAllocator(params manifests.Params) (*v1alpha1.TargetAllocator, error)
PodAnnotations: params.OtelCol.Spec.PodAnnotations,
PodDisruptionBudget: taSpec.PodDisruptionBudget,
},
CollectorSelector: collectorSelector,
AllocationStrategy: taSpec.AllocationStrategy,
FilterStrategy: taSpec.FilterStrategy,
ScrapeConfigs: scrapeConfigs,
Expand Down
7 changes: 0 additions & 7 deletions internal/manifests/collector/targetallocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
)

func TestTargetAllocator(t *testing.T) {
Expand Down Expand Up @@ -91,9 +90,6 @@ func TestTargetAllocator(t *testing.T) {
want: &v1alpha1.TargetAllocator{
ObjectMeta: objectMetadata,
Spec: v1alpha1.TargetAllocatorSpec{
CollectorSelector: metav1.LabelSelector{
MatchLabels: manifestutils.SelectorLabels(objectMetadata, ComponentOpenTelemetryCollector),
},
ScrapeConfigs: []v1beta1.AnyConfig{},
},
},
Expand Down Expand Up @@ -282,9 +278,6 @@ func TestTargetAllocator(t *testing.T) {
},
},
},
CollectorSelector: metav1.LabelSelector{
MatchLabels: manifestutils.SelectorLabels(objectMetadata, ComponentOpenTelemetryCollector),
},
AllocationStrategy: v1beta1.TargetAllocatorAllocationStrategyConsistentHashing,
FilterStrategy: v1beta1.TargetAllocatorFilterStrategyRelabelConfig,
PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{
Expand Down
6 changes: 5 additions & 1 deletion internal/manifests/targetallocator/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
)
Expand All @@ -36,7 +37,10 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
taSpec := instance.Spec

taConfig := make(map[interface{}]interface{})
taConfig["collector_selector"] = taSpec.CollectorSelector

taConfig["collector_selector"] = metav1.LabelSelector{
MatchLabels: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, collector.ComponentOpenTelemetryCollector),
}

// Add scrape configs if present
if instance.Spec.ScrapeConfigs != nil && len(instance.Spec.ScrapeConfigs) > 0 {
Expand Down
48 changes: 16 additions & 32 deletions internal/manifests/targetallocator/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func TestDesiredConfigMap(t *testing.T) {
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "0.47.0",
}
collector := collectorInstance()
targetAllocator := targetAllocatorInstance()
cfg := config.New()
params := manifests.Params{
OtelCol: collector,
TargetAllocator: targetAllocator,
Config: cfg,
Log: logr.Discard(),
}

t.Run("should return expected target allocator config map", func(t *testing.T) {
expectedLabels["app.kubernetes.io/component"] = "opentelemetry-targetallocator"
Expand All @@ -60,15 +69,7 @@ config:
filter_strategy: relabel-config
`,
}
collector := collectorInstance()
targetAllocator := targetAllocatorInstance()
cfg := config.New()
params := manifests.Params{
OtelCol: collector,
TargetAllocator: targetAllocator,
Config: cfg,
Log: logr.Discard(),
}

actual, err := ConfigMap(params)
require.NoError(t, err)

Expand All @@ -93,16 +94,9 @@ collector_selector:
filter_strategy: relabel-config
`,
}
collector := collectorInstance()
targetAllocator := targetAllocatorInstance()
targetAllocator = targetAllocatorInstance()
targetAllocator.Spec.ScrapeConfigs = []v1beta1.AnyConfig{}
cfg := config.New()
params := manifests.Params{
OtelCol: collector,
TargetAllocator: targetAllocator,
Config: cfg,
Log: logr.Discard(),
}
params.TargetAllocator = targetAllocator
actual, err := ConfigMap(params)
require.NoError(t, err)

Expand Down Expand Up @@ -145,7 +139,7 @@ prometheus_cr:
matchexpressions: []
`,
}
targetAllocator := targetAllocatorInstance()
targetAllocator = targetAllocatorInstance()
targetAllocator.Spec.PrometheusCR.Enabled = true
targetAllocator.Spec.PrometheusCR.PodMonitorSelector = &metav1.LabelSelector{
MatchLabels: map[string]string{
Expand All @@ -156,12 +150,7 @@ prometheus_cr:
MatchLabels: map[string]string{
"release": "my-instance",
}}
cfg := config.New()
params := manifests.Params{
TargetAllocator: targetAllocator,
Config: cfg,
Log: logr.Discard(),
}
params.TargetAllocator = targetAllocator
actual, err := ConfigMap(params)
assert.NoError(t, err)

Expand Down Expand Up @@ -200,15 +189,10 @@ prometheus_cr:
`,
}

targetAllocator := targetAllocatorInstance()
targetAllocator = targetAllocatorInstance()
targetAllocator.Spec.PrometheusCR.Enabled = true
targetAllocator.Spec.PrometheusCR.ScrapeInterval = &metav1.Duration{Duration: time.Second * 30}
cfg := config.New()
params := manifests.Params{
TargetAllocator: targetAllocator,
Config: cfg,
Log: logr.Discard(),
}
params.TargetAllocator = targetAllocator
actual, err := ConfigMap(params)
assert.NoError(t, err)

Expand Down

0 comments on commit c490d80

Please sign in to comment.