Skip to content

Commit b0808e1

Browse files
feat/add support in v1alpha
1 parent 4763471 commit b0808e1

8 files changed

+143
-82
lines changed

apis/v1alpha1/collector_webhook_test.go

+47-29
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,19 @@ func TestOTELColValidatingWebhook(t *testing.T) {
475475
thrift_http:
476476
endpoint: 0.0.0.0:15268
477477
`,
478-
Ports: []v1.ServicePort{
478+
Ports: []PortsSpec{
479479
{
480-
Name: "port1",
481-
Port: 5555,
480+
ServicePort: v1.ServicePort{
481+
Name: "port1",
482+
Port: 5555,
483+
},
482484
},
483485
{
484-
Name: "port2",
485-
Port: 5554,
486-
Protocol: v1.ProtocolUDP,
486+
ServicePort: v1.ServicePort{
487+
Name: "port2",
488+
Port: 5554,
489+
Protocol: v1.ProtocolUDP,
490+
},
487491
},
488492
},
489493
Autoscaler: &AutoscalerSpec{
@@ -533,15 +537,19 @@ func TestOTELColValidatingWebhook(t *testing.T) {
533537
thrift_http:
534538
endpoint: 0.0.0.0:15268
535539
`,
536-
Ports: []v1.ServicePort{
540+
Ports: []PortsSpec{
537541
{
538-
Name: "port1",
539-
Port: 5555,
542+
ServicePort: v1.ServicePort{
543+
Name: "port1",
544+
Port: 5555,
545+
},
540546
},
541547
{
542-
Name: "port2",
543-
Port: 5554,
544-
Protocol: v1.ProtocolUDP,
548+
ServicePort: v1.ServicePort{
549+
Name: "port2",
550+
Port: 5554,
551+
Protocol: v1.ProtocolUDP,
552+
},
545553
},
546554
},
547555
Autoscaler: &AutoscalerSpec{
@@ -601,15 +609,19 @@ func TestOTELColValidatingWebhook(t *testing.T) {
601609
thrift_http:
602610
endpoint: 0.0.0.0:15268
603611
`,
604-
Ports: []v1.ServicePort{
612+
Ports: []PortsSpec{
605613
{
606-
Name: "port1",
607-
Port: 5555,
614+
ServicePort: v1.ServicePort{
615+
Name: "port1",
616+
Port: 5555,
617+
},
608618
},
609619
{
610-
Name: "port2",
611-
Port: 5554,
612-
Protocol: v1.ProtocolUDP,
620+
ServicePort: v1.ServicePort{
621+
Name: "port2",
622+
Port: 5554,
623+
Protocol: v1.ProtocolUDP,
624+
},
613625
},
614626
},
615627
Autoscaler: &AutoscalerSpec{
@@ -687,12 +699,14 @@ func TestOTELColValidatingWebhook(t *testing.T) {
687699
name: "invalid port name",
688700
otelcol: OpenTelemetryCollector{
689701
Spec: OpenTelemetryCollectorSpec{
690-
Ports: []v1.ServicePort{
702+
Ports: []PortsSpec{
691703
{
692-
// this port name contains a non alphanumeric character, which is invalid.
693-
Name: "-test🦄port",
694-
Port: 12345,
695-
Protocol: v1.ProtocolTCP,
704+
ServicePort: v1.ServicePort{
705+
// this port name contains a non alphanumeric character, which is invalid.
706+
Name: "-test🦄port",
707+
Port: 12345,
708+
Protocol: v1.ProtocolTCP,
709+
},
696710
},
697711
},
698712
},
@@ -703,10 +717,12 @@ func TestOTELColValidatingWebhook(t *testing.T) {
703717
name: "invalid port name, too long",
704718
otelcol: OpenTelemetryCollector{
705719
Spec: OpenTelemetryCollectorSpec{
706-
Ports: []v1.ServicePort{
720+
Ports: []PortsSpec{
707721
{
708-
Name: "aaaabbbbccccdddd", // len: 16, too long
709-
Port: 5555,
722+
ServicePort: v1.ServicePort{
723+
Name: "aaaabbbbccccdddd", // len: 16, too long
724+
Port: 5555,
725+
},
710726
},
711727
},
712728
},
@@ -717,10 +733,12 @@ func TestOTELColValidatingWebhook(t *testing.T) {
717733
name: "invalid port num",
718734
otelcol: OpenTelemetryCollector{
719735
Spec: OpenTelemetryCollectorSpec{
720-
Ports: []v1.ServicePort{
736+
Ports: []PortsSpec{
721737
{
722-
Name: "aaaabbbbccccddd", // len: 15
723-
// no port set means it's 0, which is invalid
738+
ServicePort: v1.ServicePort{
739+
Name: "aaaabbbbccccddd", // len: 15
740+
// no port set means it's 0, which is invalid
741+
},
724742
},
725743
},
726744
},

apis/v1alpha1/convert.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error
145145
}, nil
146146
}
147147

148-
func tov1beta1Ports(in []v1.ServicePort) []v1beta1.PortsSpec {
148+
func tov1beta1Ports(in []PortsSpec) []v1beta1.PortsSpec {
149149
var ports []v1beta1.PortsSpec
150150

151151
for _, p := range in {
@@ -158,7 +158,7 @@ func tov1beta1Ports(in []v1.ServicePort) []v1beta1.PortsSpec {
158158
TargetPort: p.TargetPort,
159159
NodePort: p.NodePort,
160160
},
161-
HostPort: 0,
161+
HostPort: p.HostPort,
162162
})
163163
}
164164

@@ -270,11 +270,21 @@ func tov1beta1ConfigMaps(in []ConfigMapsSpec) []v1beta1.ConfigMapsSpec {
270270
return mapsSpecs
271271
}
272272

273-
func tov1alpha1Ports(in []v1beta1.PortsSpec) []v1.ServicePort {
274-
var ports []v1.ServicePort
273+
func tov1alpha1Ports(in []v1beta1.PortsSpec) []PortsSpec {
274+
var ports []PortsSpec
275275

276276
for _, p := range in {
277-
ports = append(ports, p.ServicePort)
277+
ports = append(ports, PortsSpec{
278+
ServicePort: v1.ServicePort{
279+
Name: p.Name,
280+
Protocol: p.Protocol,
281+
AppProtocol: p.AppProtocol,
282+
Port: p.Port,
283+
TargetPort: p.TargetPort,
284+
NodePort: p.NodePort,
285+
},
286+
HostPort: p.HostPort,
287+
})
278288
}
279289

280290
return ports

apis/v1alpha1/convert_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,12 @@ func Test_tov1beta1AndBack(t *testing.T) {
177177
Name: "aaa",
178178
},
179179
},
180-
Ports: []v1.ServicePort{
181-
{
180+
Ports: []PortsSpec{{
181+
ServicePort: v1.ServicePort{
182182
Name: "otlp",
183183
},
184-
},
184+
HostPort: 0,
185+
}},
185186
Env: []v1.EnvVar{
186187
{
187188
Name: "foo",

apis/v1alpha1/opentelemetrycollector_types.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ type OpenTelemetryCollectorSpec struct {
186186
// used to open additional ports that can't be inferred by the operator, like for custom receivers.
187187
// +optional
188188
// +listType=atomic
189-
Ports []v1.ServicePort `json:"ports,omitempty"`
189+
Ports []PortsSpec `json:"ports,omitempty"`
190190
// ENV vars to set on the OpenTelemetry Collector's Pods. These can then in certain cases be
191191
// consumed in the config file for the Collector.
192192
// +optional
@@ -291,6 +291,16 @@ type OpenTelemetryCollectorSpec struct {
291291
DeploymentUpdateStrategy appsv1.DeploymentStrategy `json:"deploymentUpdateStrategy,omitempty"`
292292
}
293293

294+
// PortsSpec defines the OpenTelemetryCollector's container/service ports additional specifications.
295+
type PortsSpec struct {
296+
// Allows defining which port to bind to the host in the Container.
297+
// +optional
298+
HostPort int32 `json:"hostPort,omitempty"`
299+
300+
// Maintain previous fields in new struct
301+
v1.ServicePort `json:",inline"`
302+
}
303+
294304
// OpenTelemetryTargetAllocator defines the configurations for the Prometheus target allocator.
295305
type OpenTelemetryTargetAllocator struct {
296306
// Replicas is the number of pod instances for the underlying TargetAllocator. This should only be set to a value

apis/v1alpha1/zz_generated.deepcopy.go

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1beta1/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type PodDisruptionBudgetSpec struct {
8484
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
8585
}
8686

87-
// PortsSpec defines the OpenTelemetryCollector's container/service ports additional specifications
87+
// PortsSpec defines the OpenTelemetryCollector's container/service ports additional specifications.
8888
type PortsSpec struct {
8989
// Allows defining which port to bind to the host in the Container.
9090
// +optional

controllers/reconcile_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ const (
5959
)
6060

6161
var (
62-
extraPorts = v1.ServicePort{
63-
Name: "port-web",
64-
Protocol: "TCP",
65-
Port: 8080,
66-
TargetPort: intstr.FromInt32(8080),
62+
extraPorts = v1alpha1.PortsSpec{
63+
ServicePort: v1.ServicePort{
64+
Name: "port-web",
65+
Protocol: "TCP",
66+
Port: 8080,
67+
TargetPort: intstr.FromInt32(8080),
68+
},
6769
}
6870
)
6971

@@ -629,7 +631,7 @@ func TestOpAMPBridgeReconciler_Reconcile(t *testing.T) {
629631
annotationName: annotationVal,
630632
}
631633
deploymentExtraPorts := opampBridgeParams()
632-
deploymentExtraPorts.OpAMPBridge.Spec.Ports = append(deploymentExtraPorts.OpAMPBridge.Spec.Ports, extraPorts)
634+
deploymentExtraPorts.OpAMPBridge.Spec.Ports = append(deploymentExtraPorts.OpAMPBridge.Spec.Ports, extraPorts.ServicePort)
633635

634636
type args struct {
635637
params manifests.Params

controllers/suite_test.go

+40-36
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,16 @@ func testCollectorWithModeAndReplicas(mode v1alpha1.Mode, replicas int32) v1alph
255255
},
256256
Spec: v1alpha1.OpenTelemetryCollectorSpec{
257257
Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.47.0",
258-
Ports: []v1.ServicePort{{
259-
Name: "web",
260-
Port: 80,
261-
TargetPort: intstr.IntOrString{
262-
Type: intstr.Int,
263-
IntVal: 80,
264-
},
265-
NodePort: 0,
266-
}},
258+
Ports: []v1alpha1.PortsSpec{{
259+
ServicePort: v1.ServicePort{
260+
Name: "web",
261+
Port: 80,
262+
TargetPort: intstr.IntOrString{
263+
Type: intstr.Int,
264+
IntVal: 80,
265+
},
266+
NodePort: 0,
267+
}}},
267268
Replicas: &replicas,
268269
Config: string(configYAML),
269270
Mode: mode,
@@ -304,15 +305,16 @@ func testCollectorWithConfigFile(taContainerImage string, file string) (v1alpha1
304305
},
305306
Spec: v1alpha1.OpenTelemetryCollectorSpec{
306307
Mode: v1alpha1.ModeStatefulSet,
307-
Ports: []v1.ServicePort{{
308-
Name: "web",
309-
Port: 80,
310-
TargetPort: intstr.IntOrString{
311-
Type: intstr.Int,
312-
IntVal: 80,
313-
},
314-
NodePort: 0,
315-
}},
308+
Ports: []v1alpha1.PortsSpec{{
309+
ServicePort: v1.ServicePort{
310+
Name: "web",
311+
Port: 80,
312+
TargetPort: intstr.IntOrString{
313+
Type: intstr.Int,
314+
IntVal: 80,
315+
},
316+
NodePort: 0,
317+
}}},
316318
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
317319
Enabled: true,
318320
Image: taContainerImage,
@@ -341,15 +343,16 @@ func testCollectorWithHPA(minReps, maxReps int32) v1alpha1.OpenTelemetryCollecto
341343
UID: instanceUID,
342344
},
343345
Spec: v1alpha1.OpenTelemetryCollectorSpec{
344-
Ports: []v1.ServicePort{{
345-
Name: "web",
346-
Port: 80,
347-
TargetPort: intstr.IntOrString{
348-
Type: intstr.Int,
349-
IntVal: 80,
350-
},
351-
NodePort: 0,
352-
}},
346+
Ports: []v1alpha1.PortsSpec{{
347+
ServicePort: v1.ServicePort{
348+
Name: "web",
349+
Port: 80,
350+
TargetPort: intstr.IntOrString{
351+
Type: intstr.Int,
352+
IntVal: 80,
353+
},
354+
NodePort: 0,
355+
}}},
353356
Config: string(configYAML),
354357
Autoscaler: &v1alpha1.AutoscalerSpec{
355358
MinReplicas: &minReps,
@@ -400,15 +403,16 @@ func testCollectorWithPDB(minAvailable, maxUnavailable int32) v1alpha1.OpenTelem
400403
UID: instanceUID,
401404
},
402405
Spec: v1alpha1.OpenTelemetryCollectorSpec{
403-
Ports: []v1.ServicePort{{
404-
Name: "web",
405-
Port: 80,
406-
TargetPort: intstr.IntOrString{
407-
Type: intstr.Int,
408-
IntVal: 80,
409-
},
410-
NodePort: 0,
411-
}},
406+
Ports: []v1alpha1.PortsSpec{{
407+
ServicePort: v1.ServicePort{
408+
Name: "web",
409+
Port: 80,
410+
TargetPort: intstr.IntOrString{
411+
Type: intstr.Int,
412+
IntVal: 80,
413+
},
414+
NodePort: 0,
415+
}}},
412416
Config: string(configYAML),
413417
PodDisruptionBudget: pdb,
414418
},

0 commit comments

Comments
 (0)