From c9150cd16d478ad2415636efedaefec8f385a6a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Nov=C3=A1k?= Date: Tue, 26 Nov 2024 02:43:04 +0100 Subject: [PATCH] feat: add HostAliases support to Fluent Bit and Fluentd specifications (#1413) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add HostAliases support to Fluent Bit and Fluentd specifications Signed-off-by: Tomáš Novák * feat: autogenerate HostAliases documentation and structure in CRDs Signed-off-by: Tomáš Novák * feat: add DeepCopy support for HostAliases in Fluent Bit and Fluentd specifications Signed-off-by: Tomáš Novák --------- Signed-off-by: Tomáš Novák --- apis/fluentbit/v1alpha2/fluentbit_types.go | 2 + .../plugins/custom/zz_generated.deepcopy.go | 1 - .../plugins/filter/zz_generated.deepcopy.go | 1 - .../plugins/input/zz_generated.deepcopy.go | 1 - .../multilineparser/zz_generated.deepcopy.go | 1 - .../plugins/output/zz_generated.deepcopy.go | 1 - .../plugins/parser/zz_generated.deepcopy.go | 1 - .../v1alpha2/plugins/zz_generated.deepcopy.go | 1 - .../v1alpha2/zz_generated.deepcopy.go | 8 +++- apis/fluentd/v1alpha1/fluentd_types.go | 2 + .../plugins/common/zz_generated.deepcopy.go | 1 - .../fluentd/v1alpha1/zz_generated.deepcopy.go | 8 +++- .../crds/fluentbit.fluent.io_fluentbits.yaml | 21 ++++++++++ .../crds/fluentd.fluent.io_fluentds.yaml | 21 ++++++++++ .../bases/fluentbit.fluent.io_fluentbits.yaml | 21 ++++++++++ .../crd/bases/fluentd.fluent.io_fluentds.yaml | 21 ++++++++++ docs/fluentbit.md | 1 + docs/fluentd.md | 1 + manifests/setup/fluent-operator-crd.yaml | 42 +++++++++++++++++++ manifests/setup/setup.yaml | 42 +++++++++++++++++++ pkg/operator/daemonset.go | 1 + pkg/operator/fluentd-daemonset.go | 1 + pkg/operator/sts.go | 1 + 23 files changed, 191 insertions(+), 10 deletions(-) diff --git a/apis/fluentbit/v1alpha2/fluentbit_types.go b/apis/fluentbit/v1alpha2/fluentbit_types.go index 5f9047116..83d63f90e 100644 --- a/apis/fluentbit/v1alpha2/fluentbit_types.go +++ b/apis/fluentbit/v1alpha2/fluentbit_types.go @@ -107,6 +107,8 @@ type FluentBitSpec struct { SchedulerName string `json:"schedulerName,omitempty"` // Optional duration in seconds the pod needs to terminate gracefully. Value must be non-negative integer. TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + // HostAliases is an optional list of IPs and hostnames that will be injected into the pod's hosts file if specified. + HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"` } // FluentBitService defines the service of the FluentBit diff --git a/apis/fluentbit/v1alpha2/plugins/custom/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/custom/zz_generated.deepcopy.go index c2ecb123f..92f05b349 100644 --- a/apis/fluentbit/v1alpha2/plugins/custom/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/custom/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go index 2248f3a96..10a8e1c82 100644 --- a/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentbit/v1alpha2/plugins/input/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/input/zz_generated.deepcopy.go index 0f22b93ca..9be65078e 100644 --- a/apis/fluentbit/v1alpha2/plugins/input/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/input/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentbit/v1alpha2/plugins/multilineparser/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/multilineparser/zz_generated.deepcopy.go index 9590dd2bc..5d0bb0840 100644 --- a/apis/fluentbit/v1alpha2/plugins/multilineparser/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/multilineparser/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go index 463987678..bd36e928e 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentbit/v1alpha2/plugins/parser/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/parser/zz_generated.deepcopy.go index 34b14fa72..3ed98ba55 100644 --- a/apis/fluentbit/v1alpha2/plugins/parser/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/parser/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentbit/v1alpha2/plugins/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/zz_generated.deepcopy.go index b68555c24..2fe9b68ba 100644 --- a/apis/fluentbit/v1alpha2/plugins/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentbit/v1alpha2/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/zz_generated.deepcopy.go index ebbd1c3cc..f0b14564d 100644 --- a/apis/fluentbit/v1alpha2/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. @@ -1088,6 +1087,13 @@ func (in *FluentBitSpec) DeepCopyInto(out *FluentBitSpec) { *out = new(int64) **out = **in } + if in.HostAliases != nil { + in, out := &in.HostAliases, &out.HostAliases + *out = make([]v1.HostAlias, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FluentBitSpec. diff --git a/apis/fluentd/v1alpha1/fluentd_types.go b/apis/fluentd/v1alpha1/fluentd_types.go index a19d3e9be..664ec5861 100644 --- a/apis/fluentd/v1alpha1/fluentd_types.go +++ b/apis/fluentd/v1alpha1/fluentd_types.go @@ -117,6 +117,8 @@ type FluentdSpec struct { LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"` // ReadinessProbe represents the readiness probe for the fluentd container. ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"` + // HostAliases is an optional list of IPs and hostnames that will be injected into the pod's hosts file if specified. + HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"` } // FluentDService the service of the FluentD diff --git a/apis/fluentd/v1alpha1/plugins/common/zz_generated.deepcopy.go b/apis/fluentd/v1alpha1/plugins/common/zz_generated.deepcopy.go index 839ede891..49ff87b81 100644 --- a/apis/fluentd/v1alpha1/plugins/common/zz_generated.deepcopy.go +++ b/apis/fluentd/v1alpha1/plugins/common/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. diff --git a/apis/fluentd/v1alpha1/zz_generated.deepcopy.go b/apis/fluentd/v1alpha1/zz_generated.deepcopy.go index af4064acd..0e55f2cf3 100644 --- a/apis/fluentd/v1alpha1/zz_generated.deepcopy.go +++ b/apis/fluentd/v1alpha1/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2022. @@ -937,6 +936,13 @@ func (in *FluentdSpec) DeepCopyInto(out *FluentdSpec) { *out = new(corev1.Probe) (*in).DeepCopyInto(*out) } + if in.HostAliases != nil { + in, out := &in.HostAliases, &out.HostAliases + *out = make([]corev1.HostAlias, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FluentdSpec. diff --git a/charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_fluentbits.yaml b/charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_fluentbits.yaml index 8c8d7ccd0..acbc0b38b 100644 --- a/charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_fluentbits.yaml +++ b/charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_fluentbits.yaml @@ -1310,6 +1310,27 @@ spec: fluentBitConfigName: description: Fluentbitconfig object associated with this Fluentbit type: string + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array hostNetwork: description: Host networking is requested for this pod. Use the host's network namespace. If this option is set, the ports that will be diff --git a/charts/fluent-operator/charts/fluentd-crds/crds/fluentd.fluent.io_fluentds.yaml b/charts/fluent-operator/charts/fluentd-crds/crds/fluentd.fluent.io_fluentds.yaml index 06c93b14b..c188cedbc 100644 --- a/charts/fluent-operator/charts/fluentd-crds/crds/fluentd.fluent.io_fluentds.yaml +++ b/charts/fluent-operator/charts/fluentd-crds/crds/fluentd.fluent.io_fluentds.yaml @@ -2813,6 +2813,27 @@ spec: type: object type: object type: array + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array image: description: Fluentd image. type: string diff --git a/config/crd/bases/fluentbit.fluent.io_fluentbits.yaml b/config/crd/bases/fluentbit.fluent.io_fluentbits.yaml index 8c8d7ccd0..acbc0b38b 100644 --- a/config/crd/bases/fluentbit.fluent.io_fluentbits.yaml +++ b/config/crd/bases/fluentbit.fluent.io_fluentbits.yaml @@ -1310,6 +1310,27 @@ spec: fluentBitConfigName: description: Fluentbitconfig object associated with this Fluentbit type: string + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array hostNetwork: description: Host networking is requested for this pod. Use the host's network namespace. If this option is set, the ports that will be diff --git a/config/crd/bases/fluentd.fluent.io_fluentds.yaml b/config/crd/bases/fluentd.fluent.io_fluentds.yaml index 06c93b14b..c188cedbc 100644 --- a/config/crd/bases/fluentd.fluent.io_fluentds.yaml +++ b/config/crd/bases/fluentd.fluent.io_fluentds.yaml @@ -2813,6 +2813,27 @@ spec: type: object type: object type: array + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array image: description: Fluentd image. type: string diff --git a/docs/fluentbit.md b/docs/fluentbit.md index 11d6a4670..12380bdce 100644 --- a/docs/fluentbit.md +++ b/docs/fluentbit.md @@ -432,6 +432,7 @@ FluentBitSpec defines the desired state of FluentBit | service | Service represents configurations on the fluent-bit service. | [FluentBitService](#fluentbitservice) | | schedulerName | SchedulerName represents the desired scheduler for fluent-bit pods. | string | | terminationGracePeriodSeconds | Optional duration in seconds the pod needs to terminate gracefully. Value must be non-negative integer. | *int64 | +| hostAliases | HostAliases is an optional list of IPs and hostnames that will be injected into the pod's hosts file if specified. | [][corev1.HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#hostalias-v1-core) | [Back to TOC](#table-of-contents) # InputSpec diff --git a/docs/fluentd.md b/docs/fluentd.md index f424e703e..7272e23f8 100644 --- a/docs/fluentd.md +++ b/docs/fluentd.md @@ -362,6 +362,7 @@ FluentdSpec defines the desired state of Fluentd | positionDB | Storage for position db. You will use it if tail input is enabled. Applicable when the mode is \"agent\", and will be ignored when the mode is \"collector\" | [corev1.VolumeSource](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volumesource-v1-core) | | livenessProbe | LivenessProbe represents the liveness probe for the fluentd container. | *[corev1.Probe](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#probe-v1-core) | | readinessProbe | ReadinessProbe represents the readiness probe for the fluentd container. | *[corev1.Probe](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#probe-v1-core) | +| hostAliases | HostAliases is an optional list of IPs and hostnames that will be injected into the pod's hosts file if specified. | [][corev1.HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#hostalias-v1-core) | [Back to TOC](#table-of-contents) # FluentdStatus diff --git a/manifests/setup/fluent-operator-crd.yaml b/manifests/setup/fluent-operator-crd.yaml index 4774f086a..31ab9a705 100644 --- a/manifests/setup/fluent-operator-crd.yaml +++ b/manifests/setup/fluent-operator-crd.yaml @@ -17892,6 +17892,27 @@ spec: fluentBitConfigName: description: Fluentbitconfig object associated with this Fluentbit type: string + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array hostNetwork: description: Host networking is requested for this pod. Use the host's network namespace. If this option is set, the ports that will be @@ -26937,6 +26958,27 @@ spec: type: object type: object type: array + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array image: description: Fluentd image. type: string diff --git a/manifests/setup/setup.yaml b/manifests/setup/setup.yaml index 404333627..23f509b90 100644 --- a/manifests/setup/setup.yaml +++ b/manifests/setup/setup.yaml @@ -17892,6 +17892,27 @@ spec: fluentBitConfigName: description: Fluentbitconfig object associated with this Fluentbit type: string + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array hostNetwork: description: Host networking is requested for this pod. Use the host's network namespace. If this option is set, the ports that will be @@ -26937,6 +26958,27 @@ spec: type: object type: object type: array + hostAliases: + description: HostAliases is an optional list of IPs and hostnames + that will be injected into the pod's hosts file if specified. + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array image: description: Fluentd image. type: string diff --git a/pkg/operator/daemonset.go b/pkg/operator/daemonset.go index 6c7fa63f3..8bb7b5141 100644 --- a/pkg/operator/daemonset.go +++ b/pkg/operator/daemonset.go @@ -94,6 +94,7 @@ func MakeDaemonSet(fb fluentbitv1alpha2.FluentBit, logPath string) *appsv1.Daemo SecurityContext: fb.Spec.SecurityContext, HostNetwork: fb.Spec.HostNetwork, TerminationGracePeriodSeconds: fb.Spec.TerminationGracePeriodSeconds, + HostAliases: fb.Spec.HostAliases, }, }, }, diff --git a/pkg/operator/fluentd-daemonset.go b/pkg/operator/fluentd-daemonset.go index 50018459f..52511e13c 100644 --- a/pkg/operator/fluentd-daemonset.go +++ b/pkg/operator/fluentd-daemonset.go @@ -114,6 +114,7 @@ func MakeFluentdDaemonSet(fd fluentdv1alpha1.Fluentd) *appsv1.DaemonSet { NodeSelector: fd.Spec.NodeSelector, Tolerations: fd.Spec.Tolerations, Affinity: fd.Spec.Affinity, + HostAliases: fd.Spec.HostAliases, }, }, }, diff --git a/pkg/operator/sts.go b/pkg/operator/sts.go index 676b1f72e..6a3097c06 100644 --- a/pkg/operator/sts.go +++ b/pkg/operator/sts.go @@ -112,6 +112,7 @@ func MakeStatefulSet(fd fluentdv1alpha1.Fluentd) *appsv1.StatefulSet { LivenessProbe: fd.Spec.LivenessProbe, }, }, + HostAliases: fd.Spec.HostAliases, NodeSelector: fd.Spec.NodeSelector, Tolerations: fd.Spec.Tolerations, Affinity: fd.Spec.Affinity,