Skip to content
Open
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
18 changes: 18 additions & 0 deletions .chloggen/traffic-distribution-field.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector, target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add TrafficDistribution support for OpenTelemetryCollector and TargetAllocator Services

# One or more tracking issues related to the change
issues: [4285]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
The TrafficDistribution field is now available in OpenTelemetryCollector and TargetAllocator.
This field allows setting the traffic distribution policy for Kubernetes Services.
2 changes: 2 additions & 0 deletions apis/v1alpha1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func tov1beta1(in OpenTelemetryCollector) v1beta1.OpenTelemetryCollector {
PriorityClassName: copy.Spec.PriorityClassName,
InitContainers: copy.Spec.InitContainers,
AdditionalContainers: copy.Spec.AdditionalContainers,
TrafficDistribution: copy.Spec.TrafficDistribution,
},
StatefulSetCommonFields: v1beta1.StatefulSetCommonFields{
VolumeClaimTemplates: copy.Spec.VolumeClaimTemplates,
Expand Down Expand Up @@ -371,6 +372,7 @@ func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, err
ConfigMaps: tov1alpha1ConfigMaps(copy.Spec.ConfigMaps),
UpdateStrategy: copy.Spec.DaemonSetUpdateStrategy,
DeploymentUpdateStrategy: copy.Spec.DeploymentUpdateStrategy,
TrafficDistribution: copy.Spec.TrafficDistribution,
},
}, nil
}
Expand Down
5 changes: 5 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ type OpenTelemetryCollectorSpec struct {
// If not specified, it will default to "<name>-headless".
// +optional
ServiceName string `json:"serviceName,omitempty"`
// TrafficDistribution specifies how traffic to this service is routed.
// https://kubernetes.io/docs/concepts/services-networking/service/#traffic-distribution
// This is only applicable to Service resources.
// +optional
TrafficDistribution *string `json:"trafficDistribution,omitempty"`

// AdditionalContainers allows injecting additional containers into the Collector's pod definition.
// These sidecar containers can be used for authentication proxies, log shipping sidecars, agents for shipping
Expand Down
5 changes: 5 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions apis/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ type OpenTelemetryCommonFields struct {
// +kubebuilder:default:=SingleStack
// +optional
IpFamilyPolicy *v1.IPFamilyPolicy `json:"ipFamilyPolicy,omitempty"`
// TrafficDistribution specifies how traffic to this service is routed.
// https://kubernetes.io/docs/concepts/services-networking/service/#traffic-distribution
// This is only applicable to Service resources.
// +optional
TrafficDistribution *string `json:"trafficDistribution,omitempty"`
}

type StatefulSetCommonFields struct {
Expand Down
5 changes: 5 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -3500,6 +3500,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
updateStrategy:
properties:
rollingUpdate:
Expand Down Expand Up @@ -8289,6 +8291,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
upgradeStrategy:
enum:
- automatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
volumeMounts:
items:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3499,6 +3499,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
updateStrategy:
properties:
rollingUpdate:
Expand Down Expand Up @@ -8288,6 +8290,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
upgradeStrategy:
enum:
- automatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
volumeMounts:
items:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3486,6 +3486,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
updateStrategy:
properties:
rollingUpdate:
Expand Down Expand Up @@ -8275,6 +8277,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
upgradeStrategy:
enum:
- automatic
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/opentelemetry.io_targetallocators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2578,6 +2578,8 @@ spec:
- whenUnsatisfiable
type: object
type: array
trafficDistribution:
type: string
volumeMounts:
items:
properties:
Expand Down
18 changes: 18 additions & 0 deletions docs/api/opentelemetrycollectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,15 @@ https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constrain
This is only relevant to statefulset, and deployment mode<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>trafficDistribution</b></td>
<td>string</td>
<td>
TrafficDistribution specifies how traffic to this service is routed.
https://kubernetes.io/docs/concepts/services-networking/service/#traffic-distribution
This is only applicable to Service resources.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspecupdatestrategy">updateStrategy</a></b></td>
<td>object</td>
Expand Down Expand Up @@ -19810,6 +19819,15 @@ https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constrain
This only works with the following OpenTelemetryCollector mode's: statefulset, and deployment.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>trafficDistribution</b></td>
<td>string</td>
<td>
TrafficDistribution specifies how traffic to this service is routed.
https://kubernetes.io/docs/concepts/services-networking/service/#traffic-distribution
This is only applicable to Service resources.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>upgradeStrategy</b></td>
<td>enum</td>
Expand Down
9 changes: 9 additions & 0 deletions docs/api/targetallocators.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constrain
This only works with the following OpenTelemetryCollector mode's: statefulset, and deployment.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>trafficDistribution</b></td>
<td>string</td>
<td>
TrafficDistribution specifies how traffic to this service is routed.
https://kubernetes.io/docs/concepts/services-networking/service/#traffic-distribution
This is only applicable to Service resources.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#targetallocatorspecvolumemountsindex">volumeMounts</a></b></td>
<td>[]object</td>
Expand Down
11 changes: 7 additions & 4 deletions internal/manifests/collector/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ func MonitoringService(params manifests.Params) (*corev1.Service, error) {
Name: "monitoring",
Port: metricsPort,
}},
IPFamilies: params.OtelCol.Spec.IpFamilies,
IPFamilyPolicy: params.OtelCol.Spec.IpFamilyPolicy,
IPFamilies: params.OtelCol.Spec.IpFamilies,
IPFamilyPolicy: params.OtelCol.Spec.IpFamilyPolicy,
TrafficDistribution: params.OtelCol.Spec.TrafficDistribution,
},
}, nil
}
Expand Down Expand Up @@ -124,8 +125,9 @@ func ExtensionService(params manifests.Params) (*corev1.Service, error) {
Annotations: annotations,
},
Spec: corev1.ServiceSpec{
Ports: ports,
Selector: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector),
Ports: ports,
Selector: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector),
TrafficDistribution: params.OtelCol.Spec.TrafficDistribution,
},
}, nil
}
Expand Down Expand Up @@ -199,6 +201,7 @@ func Service(params manifests.Params) (*corev1.Service, error) {
Ports: ports,
IPFamilies: params.OtelCol.Spec.IpFamilies,
IPFamilyPolicy: params.OtelCol.Spec.IpFamilyPolicy,
TrafficDistribution: params.OtelCol.Spec.TrafficDistribution,
},
}, nil
}
Expand Down
18 changes: 18 additions & 0 deletions internal/manifests/collector/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,21 @@ func TestServiceWithIpFamily(t *testing.T) {
assert.Equal(t, actual.Spec.IPFamilyPolicy, params.OtelCol.Spec.IpFamilyPolicy)
})
}

func TestServiceWithTrafficDistribution(t *testing.T) {
t.Run("should set TrafficDistribution when specified", func(t *testing.T) {
params := deploymentParams()
trafficDistribution := "PreferClose"
params.OtelCol.Spec.TrafficDistribution = &trafficDistribution
actual, err := Service(params)
assert.NoError(t, err)
assert.Equal(t, &trafficDistribution, actual.Spec.TrafficDistribution)
})

t.Run("should not set TrafficDistribution when not specified", func(t *testing.T) {
params := deploymentParams()
actual, err := Service(params)
assert.NoError(t, err)
assert.Nil(t, actual.Spec.TrafficDistribution)
})
}
9 changes: 5 additions & 4 deletions internal/manifests/targetallocator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ func Service(params Params) *corev1.Service {
Labels: labels,
},
Spec: corev1.ServiceSpec{
Selector: selector,
Ports: ports,
IPFamilies: params.TargetAllocator.Spec.IpFamilies,
IPFamilyPolicy: params.TargetAllocator.Spec.IpFamilyPolicy,
Selector: selector,
Ports: ports,
IPFamilies: params.TargetAllocator.Spec.IpFamilies,
IPFamilyPolicy: params.TargetAllocator.Spec.IpFamilyPolicy,
TrafficDistribution: params.TargetAllocator.Spec.TrafficDistribution,
},
}
}
1 change: 1 addition & 0 deletions tests/e2e/smoke-ports/00-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: smoke-ports
spec:
mode: daemonset
trafficDistribution: PreferClose
ports:
- appProtocol: grpc
name: otlp-grpc
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/smoke-ports/01-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: smoke-ports
spec:
mode: daemonset
trafficDistribution: PreferClose
ports:
- appProtocol: http
name: custom-port
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/smoke-ports/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,37 @@ metadata:
creationTimestamp: null
name: smoke-ports
spec:
bindings:
- name: version
value: (x_k8s_server_version($config))
- name: minorVersion
value: (to_number($version.minor))
steps:
- name: step-00
try:
- apply:
file: 00-install.yaml
- assert:
file: 00-assert.yaml
- script:
content: kubectl get svc smoke-ports-collector -n $NAMESPACE -o jsonpath='{.spec.trafficDistribution}' || echo ""
outputs:
- name: trafficDistribution
value: ($stdout)
- assert:
resource:
(($minorVersion >= `29` && $trafficDistribution == 'PreferClose') || ($minorVersion < `26` && $trafficDistribution == '')): true
- name: step-01
try:
- apply:
file: 01-install.yaml
- assert:
file: 01-assert.yaml
- script:
content: kubectl get svc smoke-ports-collector -n $NAMESPACE -o jsonpath='{.spec.trafficDistribution}' || echo ""
outputs:
- name: trafficDistribution
value: ($stdout)
- assert:
resource:
(($minorVersion >= `29` && $trafficDistribution == 'PreferClose') || ($minorVersion < `26` && $trafficDistribution == '')): true