Skip to content

Commit

Permalink
Merge branch 'main' into instrumentation-support-label
Browse files Browse the repository at this point in the history
# Conflicts:
#	apis/v1alpha1/zz_generated.deepcopy.go
  • Loading branch information
crossoverJie committed Apr 9, 2024
2 parents 8b7609a + e399e61 commit 80bc887
Show file tree
Hide file tree
Showing 25 changed files with 563 additions and 258 deletions.
16 changes: 16 additions & 0 deletions .chloggen/2763 - add hostPort support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add support for adding/extending otc-collector container ports."

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

# (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:
76 changes: 47 additions & 29 deletions apis/v1alpha1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,19 @@ func TestOTELColValidatingWebhook(t *testing.T) {
thrift_http:
endpoint: 0.0.0.0:15268
`,
Ports: []v1.ServicePort{
Ports: []PortsSpec{
{
Name: "port1",
Port: 5555,
ServicePort: v1.ServicePort{
Name: "port1",
Port: 5555,
},
},
{
Name: "port2",
Port: 5554,
Protocol: v1.ProtocolUDP,
ServicePort: v1.ServicePort{
Name: "port2",
Port: 5554,
Protocol: v1.ProtocolUDP,
},
},
},
Autoscaler: &AutoscalerSpec{
Expand Down Expand Up @@ -533,15 +537,19 @@ func TestOTELColValidatingWebhook(t *testing.T) {
thrift_http:
endpoint: 0.0.0.0:15268
`,
Ports: []v1.ServicePort{
Ports: []PortsSpec{
{
Name: "port1",
Port: 5555,
ServicePort: v1.ServicePort{
Name: "port1",
Port: 5555,
},
},
{
Name: "port2",
Port: 5554,
Protocol: v1.ProtocolUDP,
ServicePort: v1.ServicePort{
Name: "port2",
Port: 5554,
Protocol: v1.ProtocolUDP,
},
},
},
Autoscaler: &AutoscalerSpec{
Expand Down Expand Up @@ -601,15 +609,19 @@ func TestOTELColValidatingWebhook(t *testing.T) {
thrift_http:
endpoint: 0.0.0.0:15268
`,
Ports: []v1.ServicePort{
Ports: []PortsSpec{
{
Name: "port1",
Port: 5555,
ServicePort: v1.ServicePort{
Name: "port1",
Port: 5555,
},
},
{
Name: "port2",
Port: 5554,
Protocol: v1.ProtocolUDP,
ServicePort: v1.ServicePort{
Name: "port2",
Port: 5554,
Protocol: v1.ProtocolUDP,
},
},
},
Autoscaler: &AutoscalerSpec{
Expand Down Expand Up @@ -687,12 +699,14 @@ func TestOTELColValidatingWebhook(t *testing.T) {
name: "invalid port name",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
Ports: []v1.ServicePort{
Ports: []PortsSpec{
{
// this port name contains a non alphanumeric character, which is invalid.
Name: "-test🦄port",
Port: 12345,
Protocol: v1.ProtocolTCP,
ServicePort: v1.ServicePort{
// this port name contains a non alphanumeric character, which is invalid.
Name: "-test🦄port",
Port: 12345,
Protocol: v1.ProtocolTCP,
},
},
},
},
Expand All @@ -703,10 +717,12 @@ func TestOTELColValidatingWebhook(t *testing.T) {
name: "invalid port name, too long",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
Ports: []v1.ServicePort{
Ports: []PortsSpec{
{
Name: "aaaabbbbccccdddd", // len: 16, too long
Port: 5555,
ServicePort: v1.ServicePort{
Name: "aaaabbbbccccdddd", // len: 16, too long
Port: 5555,
},
},
},
},
Expand All @@ -717,10 +733,12 @@ func TestOTELColValidatingWebhook(t *testing.T) {
name: "invalid port num",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
Ports: []v1.ServicePort{
Ports: []PortsSpec{
{
Name: "aaaabbbbccccddd", // len: 15
// no port set means it's 0, which is invalid
ServicePort: v1.ServicePort{
Name: "aaaabbbbccccddd", // len: 15
// no port set means it's 0, which is invalid
},
},
},
},
Expand Down
45 changes: 43 additions & 2 deletions apis/v1alpha1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"gopkg.in/yaml.v3"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"

Expand Down Expand Up @@ -96,7 +97,7 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error
Image: copy.Spec.Image,
ImagePullPolicy: copy.Spec.ImagePullPolicy,
VolumeMounts: copy.Spec.VolumeMounts,
Ports: copy.Spec.Ports,
Ports: tov1beta1Ports(copy.Spec.Ports),
Env: copy.Spec.Env,
EnvFrom: copy.Spec.EnvFrom,
VolumeClaimTemplates: copy.Spec.VolumeClaimTemplates,
Expand Down Expand Up @@ -144,6 +145,26 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error
}, nil
}

func tov1beta1Ports(in []PortsSpec) []v1beta1.PortsSpec {
var ports []v1beta1.PortsSpec

for _, p := range in {
ports = append(ports, v1beta1.PortsSpec{
ServicePort: v1.ServicePort{
Name: p.Name,
Protocol: p.Protocol,
AppProtocol: p.AppProtocol,
Port: p.Port,
TargetPort: p.TargetPort,
NodePort: p.NodePort,
},
HostPort: p.HostPort,
})
}

return ports
}

func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedded {
return v1beta1.TargetAllocatorEmbedded{
Replicas: in.Replicas,
Expand Down Expand Up @@ -249,6 +270,26 @@ func tov1beta1ConfigMaps(in []ConfigMapsSpec) []v1beta1.ConfigMapsSpec {
return mapsSpecs
}

func tov1alpha1Ports(in []v1beta1.PortsSpec) []PortsSpec {
var ports []PortsSpec

for _, p := range in {
ports = append(ports, PortsSpec{
ServicePort: v1.ServicePort{
Name: p.Name,
Protocol: p.Protocol,
AppProtocol: p.AppProtocol,
Port: p.Port,
TargetPort: p.TargetPort,
NodePort: p.NodePort,
},
HostPort: p.HostPort,
})
}

return ports
}

func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, error) {
copy := in.DeepCopy()
configYaml, err := copy.Spec.Config.Yaml()
Expand Down Expand Up @@ -287,7 +328,7 @@ func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, err
ImagePullPolicy: copy.Spec.ImagePullPolicy,
Config: configYaml,
VolumeMounts: copy.Spec.VolumeMounts,
Ports: copy.Spec.Ports,
Ports: tov1alpha1Ports(copy.Spec.Ports),
Env: copy.Spec.Env,
EnvFrom: copy.Spec.EnvFrom,
VolumeClaimTemplates: copy.Spec.VolumeClaimTemplates,
Expand Down
7 changes: 4 additions & 3 deletions apis/v1alpha1/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ func Test_tov1beta1AndBack(t *testing.T) {
Name: "aaa",
},
},
Ports: []v1.ServicePort{
{
Ports: []PortsSpec{{
ServicePort: v1.ServicePort{
Name: "otlp",
},
},
HostPort: 0,
}},
Env: []v1.EnvVar{
{
Name: "foo",
Expand Down
12 changes: 11 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type OpenTelemetryCollectorSpec struct {
// used to open additional ports that can't be inferred by the operator, like for custom receivers.
// +optional
// +listType=atomic
Ports []v1.ServicePort `json:"ports,omitempty"`
Ports []PortsSpec `json:"ports,omitempty"`
// ENV vars to set on the OpenTelemetry Collector's Pods. These can then in certain cases be
// consumed in the config file for the Collector.
// +optional
Expand Down Expand Up @@ -291,6 +291,16 @@ type OpenTelemetryCollectorSpec struct {
DeploymentUpdateStrategy appsv1.DeploymentStrategy `json:"deploymentUpdateStrategy,omitempty"`
}

// PortsSpec defines the OpenTelemetryCollector's container/service ports additional specifications.
type PortsSpec struct {
// Allows defining which port to bind to the host in the Container.
// +optional
HostPort int32 `json:"hostPort,omitempty"`

// Maintain previous fields in new struct
v1.ServicePort `json:",inline"`
}

// OpenTelemetryTargetAllocator defines the configurations for the Prometheus target allocator.
type OpenTelemetryTargetAllocator struct {
// Replicas is the number of pod instances for the underlying TargetAllocator. This should only be set to a value
Expand Down
Loading

0 comments on commit 80bc887

Please sign in to comment.