Skip to content

Commit 97d1355

Browse files
Retr0-XDswiatekm
andauthored
feat(collector): add hostAliases support to OpenTelemetryCollector and TargetAllocator (#4902)
* feat(collector): add hostAliases support to OpenTelemetryCollector and TargetAllocator Adds the `hostAliases` field to `OpenTelemetryCommonFields`, which is embedded by both `OpenTelemetryCollectorSpec` (via `OpenTelemetryCollectorSpec`) and `TargetAllocatorSpec` (v1alpha1). This allows operators to inject custom entries into a collector pod's `/etc/hosts` file, which is useful when DNS resolution for specific hostnames must be overridden within a cluster. The field maps directly to `corev1.HostAlias` (Kubernetes `hostAliases` on PodSpec) and is propagated in the Deployment, DaemonSet, and StatefulSet manifests for the collector, as well as the TargetAllocator Deployment. The `DeepCopyInto` method in `zz_generated.deepcopy.go` is updated to include a proper slice deep copy for the new field. Example usage: ```yaml spec: hostAliases: - ip: "10.0.0.1" hostnames: - "internal.registry.local" ``` Closes #986 Signed-off-by: Sakthi Harish <sakthi.harish@edgeverve.com> * chore: add hostAliases to collector CRD schema Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com> * chore: add hostAliases to targetallocator CRD schema Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com> * test: add TestDeploymentHostAliases for collector deployment Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com> * test: add TestDaemonsetHostAliases for collector daemonset Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com> * test: add TestStatefulSetHostAliases for collector statefulset Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com> * test: add TestDeploymentHostAliases for targetallocator deployment Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com> * Enhance support for hostAliases in pods Added support for hostAliases in OpenTelemetryCollector and TargetAllocator pods. * Fix formatting of HostAliases assignment * Fix formatting of HostAliases assignment * Add x-kubernetes-list-type to hostnames field * Add x-kubernetes-list-type to collectors YAML * Add x-kubernetes-list-type to targetallocators.yaml * lint fixes * supression for newMetrics --------- Signed-off-by: Sakthi Harish <sakthi.harish@edgeverve.com> Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com> Co-authored-by: Mikołaj Świątek <mail+sumo@mikolajswiatek.com>
1 parent 9f02b16 commit 97d1355

19 files changed

Lines changed: 347 additions & 0 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
change_type: enhancement
2+
component: operator
3+
note: Added hostAliases support for OpenTelemetryCollector and TargetAllocator pods
4+
issues: [896]

apis/v1beta1/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ type OpenTelemetryCommonFields struct {
244244
// HostUsers isolates pod processes in a separate user namespace, reducing the risk of privilege escalation.
245245
// +optional
246246
HostUsers *bool `json:"hostUsers,omitempty"`
247+
// HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts file if specified.
248+
// This is only valid for non-hostNetwork pods and is not supported on Windows.
249+
// +optional
250+
// +listType=atomic
251+
HostAliases []v1.HostAlias `json:"hostAliases,omitempty"`
247252
}
248253

249254
type StatefulSetCommonFields struct {

apis/v1beta1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6303,6 +6303,21 @@ spec:
63036303
x-kubernetes-map-type: atomic
63046304
type: object
63056305
type: array
6306+
hostAliases:
6307+
items:
6308+
properties:
6309+
hostnames:
6310+
items:
6311+
type: string
6312+
type: array
6313+
x-kubernetes-list-type: atomic
6314+
ip:
6315+
type: string
6316+
required:
6317+
- ip
6318+
type: object
6319+
type: array
6320+
x-kubernetes-list-type: atomic
63066321
hostNetwork:
63076322
type: boolean
63086323
hostPID:

bundle/community/manifests/opentelemetry.io_targetallocators.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,21 @@ spec:
13331333
type: string
13341334
global:
13351335
type: object
1336+
hostAliases:
1337+
items:
1338+
properties:
1339+
hostnames:
1340+
items:
1341+
type: string
1342+
type: array
1343+
x-kubernetes-list-type: atomic
1344+
ip:
1345+
type: string
1346+
required:
1347+
- ip
1348+
type: object
1349+
type: array
1350+
x-kubernetes-list-type: atomic
13361351
hostNetwork:
13371352
type: boolean
13381353
hostPID:

bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6302,6 +6302,21 @@ spec:
63026302
x-kubernetes-map-type: atomic
63036303
type: object
63046304
type: array
6305+
hostAliases:
6306+
items:
6307+
properties:
6308+
hostnames:
6309+
items:
6310+
type: string
6311+
type: array
6312+
x-kubernetes-list-type: atomic
6313+
ip:
6314+
type: string
6315+
required:
6316+
- ip
6317+
type: object
6318+
type: array
6319+
x-kubernetes-list-type: atomic
63056320
hostNetwork:
63066321
type: boolean
63076322
hostPID:

bundle/openshift/manifests/opentelemetry.io_targetallocators.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,21 @@ spec:
13331333
type: string
13341334
global:
13351335
type: object
1336+
hostAliases:
1337+
items:
1338+
properties:
1339+
hostnames:
1340+
items:
1341+
type: string
1342+
type: array
1343+
x-kubernetes-list-type: atomic
1344+
ip:
1345+
type: string
1346+
required:
1347+
- ip
1348+
type: object
1349+
type: array
1350+
x-kubernetes-list-type: atomic
13361351
hostNetwork:
13371352
type: boolean
13381353
hostPID:

config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6289,6 +6289,21 @@ spec:
62896289
x-kubernetes-map-type: atomic
62906290
type: object
62916291
type: array
6292+
hostAliases:
6293+
items:
6294+
properties:
6295+
hostnames:
6296+
items:
6297+
type: string
6298+
type: array
6299+
x-kubernetes-list-type: atomic
6300+
ip:
6301+
type: string
6302+
required:
6303+
- ip
6304+
type: object
6305+
type: array
6306+
x-kubernetes-list-type: atomic
62926307
hostNetwork:
62936308
type: boolean
62946309
hostPID:

config/crd/bases/opentelemetry.io_targetallocators.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,21 @@ spec:
13311331
type: string
13321332
global:
13331333
type: object
1334+
hostAliases:
1335+
items:
1336+
properties:
1337+
hostnames:
1338+
items:
1339+
type: string
1340+
type: array
1341+
x-kubernetes-list-type: atomic
1342+
ip:
1343+
type: string
1344+
required:
1345+
- ip
1346+
type: object
1347+
type: array
1348+
x-kubernetes-list-type: atomic
13341349
hostNetwork:
13351350
type: boolean
13361351
hostPID:

docs/api/opentelemetrycollectors.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20243,6 +20243,14 @@ This is only applicable to Deployment mode.<br/>
2024320243
List of sources to populate environment variables on the generated pods.<br/>
2024420244
</td>
2024520245
<td>false</td>
20246+
</tr><tr>
20247+
<td><b><a href="#opentelemetrycollectorspechostaliasesindex">hostAliases</a></b></td>
20248+
<td>[]object</td>
20249+
<td>
20250+
HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts file if specified.
20251+
This is only valid for non-hostNetwork pods and is not supported on Windows.<br/>
20252+
</td>
20253+
<td>false</td>
2024620254
</tr><tr>
2024720255
<td><b>hostNetwork</b></td>
2024820256
<td>boolean</td>
@@ -26716,6 +26724,41 @@ More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/nam
2671626724
</table>
2671726725

2671826726

26727+
### OpenTelemetryCollector.spec.hostAliases[index]
26728+
<sup><sup>[↩ Parent](#opentelemetrycollectorspec-1)</sup></sup>
26729+
26730+
26731+
26732+
HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
26733+
pod's hosts file.
26734+
26735+
<table>
26736+
<thead>
26737+
<tr>
26738+
<th>Name</th>
26739+
<th>Type</th>
26740+
<th>Description</th>
26741+
<th>Required</th>
26742+
</tr>
26743+
</thead>
26744+
<tbody><tr>
26745+
<td><b>ip</b></td>
26746+
<td>string</td>
26747+
<td>
26748+
IP address of the host file entry.<br/>
26749+
</td>
26750+
<td>true</td>
26751+
</tr><tr>
26752+
<td><b>hostnames</b></td>
26753+
<td>[]string</td>
26754+
<td>
26755+
Hostnames for the above IP address.<br/>
26756+
</td>
26757+
<td>false</td>
26758+
</tr></tbody>
26759+
</table>
26760+
26761+
2671926762
### OpenTelemetryCollector.spec.ingress
2672026763
<sup><sup>[↩ Parent](#opentelemetrycollectorspec-1)</sup></sup>
2672126764

0 commit comments

Comments
 (0)