Skip to content

Commit

Permalink
Feature/multi fluentbit support (kube-logging#665)
Browse files Browse the repository at this point in the history
NodeAgent Support
  • Loading branch information
ahma authored Apr 2, 2021
1 parent 620eb41 commit b6aa5be
Show file tree
Hide file tree
Showing 31 changed files with 8,884 additions and 30 deletions.
2 changes: 1 addition & 1 deletion charts/logging-demo/requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dependencies:
repository: https://kubernetes-charts.banzaicloud.com/
version: 0.1.5
digest: sha256:8c6a3777c9e971fc03bad54b76fa62ef58b07f73436121522c7a6e97fce6ece5
generated: "2021-01-20T11:35:41.461008+01:00"
generated: "2021-01-08T16:16:09.458546+01:00"
1 change: 1 addition & 0 deletions charts/logging-operator-logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The following tables lists the configurable parameters of the logging-operator-l
| `fluentd.tolerations` | Tolerations for fluentd statefulset | none |
| `fluentd.nodeSelector` | Node selector for fluentd pods | none |
| `fluentd.podPriorityClassName` | Priority class name for fluentd pods | none |
| `nodeAgents` | Node agents definitions | {}} |
| `defaultFlow` | Default Flow | {} |
| `clusterFlows` | Array of ClusterFlows to be created | [] |
| `clusterOutputs` | Array of ClusterOutputs to be created | [] |
7 changes: 6 additions & 1 deletion charts/logging-operator-logging/templates/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ spec:
{{- else }}
fluentbit: {}
{{- end }}

{{- if .Values.nodeAgents }}
nodeAgents:
{{ toYaml .Values.nodeAgents | indent 4 }}
{{- else }}
nodeAgents: []
{{- end }}
25 changes: 25 additions & 0 deletions charts/logging-operator-logging/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ enableRecreateWorkloadOnImmutableFieldChange: false

# Fluent-bit configurations https://banzaicloud.com/docs/one-eye/logging-operator/configuration/crds/#fluent-bit-spec
fluentbit: {}

#Node agent Definition
nodeAgents: {}
# - name: win-agent
# profile: windows
# nodeAgentFluentbit:
# daemonSet:
# spec:
# template:
# spec:
# containers:
# - image: banzaicloud/fluentbit:1.6.10
# name: fluent-bit
# tls:
# enabled: false
# - name: linux-agent
# profile: linux
# nodeAgentFluentbit:
# metrics:
# prometheusAnnotations: true
# serviceMonitor: false
# tls:
# enabled: false


# Fluentd configurations https://banzaicloud.com/docs/one-eye/logging-operator/configuration/crds/#fluentd-spec
fluentd: {}
# 20Gi persistent storage is configured for fluentd by default.
Expand Down
3,559 changes: 3,559 additions & 0 deletions charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func plugins() {
For more information please click on the plugin name
<center>
| Name | Type | Description | Status |Version |
| Name | Profile | Description | Status |Version |
|:---|---|:---|:---:|---:|`,
)

Expand Down
3,559 changes: 3,559 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_loggings.yaml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions controllers/logging_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/banzaicloud/logging-operator/pkg/resources/fluentbit"
"github.com/banzaicloud/logging-operator/pkg/resources/fluentd"
"github.com/banzaicloud/logging-operator/pkg/resources/model"
"github.com/banzaicloud/logging-operator/pkg/resources/nodeagent"
"github.com/banzaicloud/logging-operator/pkg/sdk/model/render"
"github.com/banzaicloud/operator-tools/pkg/reconciler"
"github.com/banzaicloud/operator-tools/pkg/secret"
Expand Down Expand Up @@ -120,6 +121,10 @@ func (r *LoggingReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
reconcilers = append(reconcilers, fluentbit.New(r.Client, r.Log, &logging, reconcilerOpts).Reconcile)
}

if len(logging.Spec.NodeAgents) > 0 {
reconcilers = append(reconcilers, nodeagent.New(r.Client, r.Log, &logging, reconcilerOpts).Reconcile)
}

for _, rec := range reconcilers {
result, err := rec()
if err != nil {
Expand Down Expand Up @@ -224,6 +229,7 @@ func SetupLoggingWithManager(mgr ctrl.Manager, logger logr.Logger) *ctrl.Builder

fluentd.RegisterWatches(builder)
fluentbit.RegisterWatches(builder)
nodeagent.RegisterWatches(builder)

return builder
}
Expand Down
69 changes: 69 additions & 0 deletions fluent-bit-image/v1.6/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# escape=`

ARG WINDOWS_VERSION=ltsc2019

#
# Builder Image - Windows Server Core
#
FROM mcr.microsoft.com/windows/servercore:$WINDOWS_VERSION as builder

# The FLUENTBIT_VERSION ARG must be after the FROM instruction
ARG FLUENTBIT_VERSION=1.6.10
ARG IMAGE_CREATE_DATE
ARG IMAGE_SOURCE_REVISION

# Metadata as defined in OCI image spec annotations
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL org.opencontainers.image.title="Fluent Bit" `
org.opencontainers.image.description="Fluent Bit is an open source and multi-platform Log Processor and Forwarder which allows you to collect data/logs from different sources, unify and send them to multiple destinations. It's fully compatible with Docker and Kubernetes environments." `
org.opencontainers.image.created=$IMAGE_CREATE_DATE `
org.opencontainers.image.version=$FLUENTBIT_VERSION `
org.opencontainers.image.authors="Eduardo Silva <[email protected]>" `
org.opencontainers.image.url="https://hub.docker.com/r/fluent/fluent-bit" `
org.opencontainers.image.documentation="https://docs.fluentbit.io/manual/" `
org.opencontainers.image.vendor="Fluent Organization" `
org.opencontainers.image.licenses="Apache-2.0" `
org.opencontainers.image.source="https://github.com/fluent/fluent-bit" `
org.opencontainers.image.revision=$IMAGE_SOURCE_REVISION

#
# Basic setup
#
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN Write-Host ('Creating folders'); `
New-Item -Type Directory -Path /local; `
New-Item -Type Directory -Path /fluent-bit;

WORKDIR /local

#
# Install Fluent Bit
#
RUN Write-Host ('Installing Fluent Bit'); `
$majorminor = ([Version]::Parse("$env:FLUENTBIT_VERSION")).toString(2); `
Invoke-WebRequest -Uri "https://fluentbit.io/releases/$($majorminor)/td-agent-bit-$($env:FLUENTBIT_VERSION)-win64.zip" -OutFile td-agent-bit.zip; `
Expand-Archive -Path td-agent-bit.zip -Destination /local/fluent-bit; `
Move-Item -Path /local/fluent-bit/*/* -Destination /fluent-bit/;

#
# Technique from https://github.com/StefanScherer/dockerfiles-windows/blob/master/mongo/3.6/Dockerfile
#
ADD https://aka.ms/vs/15/release/vc_redist.x64.exe /local/vc_redist.x64.exe

RUN Write-Host ('Installing Visual C++ Redistributable Package'); `
Start-Process /local/vc_redist.x64.exe -ArgumentList '/install', '/quiet', '/norestart' -NoNewWindow -Wait; `
Copy-Item -Path /Windows/System32/msvcp140.dll -Destination /fluent-bit/bin/; `
Copy-Item -Path /Windows/System32/vccorlib140.dll -Destination /fluent-bit/bin/; `
Copy-Item -Path /Windows/System32/vcruntime140.dll -Destination /fluent-bit/bin/;

#
# Runtime Image - Windows Server Nano
#
FROM mcr.microsoft.com/windows/servercore:$WINDOWS_VERSION as runtime

COPY --from=builder /fluent-bit /fluent-bit

RUN setx /M PATH "%PATH%;C:\fluent-bit\bin"

ENTRYPOINT ["fluent-bit.exe", "-i", "dummy", "-o", "stdout"]
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/banzaicloud/logging-operator/pkg/sdk v0.0.0
github.com/banzaicloud/operator-tools v0.15.0
github.com/banzaicloud/operator-tools v0.20.1
github.com/go-logr/logr v0.2.1
github.com/onsi/gomega v1.10.1
github.com/pborman/uuid v1.2.0
Expand All @@ -24,5 +24,3 @@ require (
replace k8s.io/client-go => k8s.io/client-go v0.19.2

replace github.com/banzaicloud/logging-operator/pkg/sdk => ./pkg/sdk

//replace github.com/banzaicloud/operator-tools => ../operator-tools
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
Expand All @@ -83,8 +85,8 @@ github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/banzaicloud/k8s-objectmatcher v1.5.0 h1:mYrLzvRgxCHBlJZEcyIglDuoKpMhwHocgsAXl1nmm10=
github.com/banzaicloud/k8s-objectmatcher v1.5.0/go.mod h1:9MWY5HsM/OaTmoTirczhlO8UALbH722WgdpaaR7Y8OE=
github.com/banzaicloud/operator-tools v0.15.0 h1:BxtRBJlHntpAq4dtgCkhTImAUiT9sdKxwlcYKoKR+uM=
github.com/banzaicloud/operator-tools v0.15.0/go.mod h1:544x65QDUmKMTrnMs0lbJ/0jvBSGKkaP2Z4fcmUZeLg=
github.com/banzaicloud/operator-tools v0.20.1 h1:gn9xRNZGvGywi5AmtplEw469qmUyUUPoLlnKi6z3M3A=
github.com/banzaicloud/operator-tools v0.20.1/go.mod h1:A/Y7Sxu9oSswN+gQABqx0imR6AbaMnxq2Mxag/gN/eM=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down Expand Up @@ -277,6 +279,8 @@ github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85n
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M=
github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/logger v1.0.1/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs=
Expand Down Expand Up @@ -636,6 +640,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/fluentbit/configsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er
Enabled bool
SharedKey string
}{
Enabled: r.Logging.Spec.FluentbitSpec.TLS.Enabled,
Enabled: *r.Logging.Spec.FluentbitSpec.TLS.Enabled,
SharedKey: r.Logging.Spec.FluentbitSpec.TLS.SharedKey,
},
Monitor: monitor,
Expand Down
8 changes: 4 additions & 4 deletions pkg/resources/fluentbit/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *Reconciler) daemonSet() (runtime.Object, reconciler.DesiredState, error
for key, config := range r.configs {
h := sha256.New()
_, _ = h.Write(config)
templates.Annotate(podMeta, fmt.Sprintf("checksum/%s", key), fmt.Sprintf("%x", h.Sum(nil)))
podMeta = templates.Annotate(podMeta, fmt.Sprintf("checksum/%s", key), fmt.Sprintf("%x", h.Sum(nil)))
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func (r *Reconciler) generateVolumeMounts() (v []corev1.VolumeMount) {
for vCount, vMnt := range r.Logging.Spec.FluentbitSpec.ExtraVolumeMounts {
v = append(v, corev1.VolumeMount{
Name: "extravolumemount" + strconv.Itoa(vCount),
ReadOnly: vMnt.ReadOnly,
ReadOnly: *vMnt.ReadOnly,
MountPath: vMnt.Destination,
})
}
Expand All @@ -162,7 +162,7 @@ func (r *Reconciler) generateVolumeMounts() (v []corev1.VolumeMount) {
})
}

if r.Logging.Spec.FluentbitSpec.TLS.Enabled {
if *r.Logging.Spec.FluentbitSpec.TLS.Enabled {
tlsRelatedVolume := []corev1.VolumeMount{
{
Name: "fluent-bit-tls",
Expand Down Expand Up @@ -236,7 +236,7 @@ func (r *Reconciler) generateVolume() (v []corev1.Volume) {
},
})
}
if r.Logging.Spec.FluentbitSpec.TLS.Enabled {
if *r.Logging.Spec.FluentbitSpec.TLS.Enabled {
tlsRelatedVolume := corev1.Volume{
Name: "fluent-bit-tls",
VolumeSource: corev1.VolumeSource{
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/fluentbit/psp.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (r *Reconciler) clusterPodSecurityPolicy() (runtime.Object, reconciler.Desi
for _, vMnt := range r.Logging.Spec.FluentbitSpec.ExtraVolumeMounts {
allowedHostPaths = append(allowedHostPaths, policyv1beta1.AllowedHostPath{
PathPrefix: vMnt.Source,
ReadOnly: vMnt.ReadOnly,
ReadOnly: *vMnt.ReadOnly,
})
}

Expand Down
119 changes: 119 additions & 0 deletions pkg/resources/nodeagent/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright © 2021 Banzai Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package nodeagent

const BaseConfigName = "fluent-bit.conf"
const UpstreamConfigName = "upstream.conf"

var fluentBitConfigTemplate = `
[SERVICE]
Flush {{ .Flush }}
Grace {{ .Grace }}
Daemon Off
Log_Level {{ .LogLevel }}
Parsers_File /fluent-bit/conf/parsers.conf
Coro_Stack_Size {{ .CoroStackSize }}
{{- if .Monitor.Enabled }}
HTTP_Server On
HTTP_Listen 0.0.0.0
HTTP_Port {{ .Monitor.Port }}
{{- end }}
[INPUT]
Name tail
{{- range $key, $value := .Input.Values }}
{{- if $value }}
{{ $key }} {{$value}}
{{- end }}
{{- end }}
{{- range $id, $v := .Input.ParserN }}
{{- if $v }}
Parse_{{ $id}} {{$v}}
{{- end }}
{{- end }}
{{- if not .DisableKubernetesFilter }}
[FILTER]
Name kubernetes
{{- range $key, $value := .KubernetesFilter }}
{{- if $value }}
{{ $key }} {{$value}}
{{- end }}
{{- end }}
{{- end}}
{{- if .AwsFilter }}
[FILTER]
Name aws
{{- range $key, $value := .AwsFilter }}
{{- if $value }}
{{ $key }} {{$value}}
{{- end }}
{{- end }}
{{- end}}
[OUTPUT]
Name forward
Match *
{{- if .Upstream.Enabled }}
Upstream /fluent-bit/conf_upstream/upstream.conf
{{- else }}
Host {{ .TargetHost }}
Port {{ .TargetPort }}
{{- end }}
{{ if .TLS.Enabled }}
tls On
tls.verify Off
tls.ca_file /fluent-bit/tls/ca.crt
tls.crt_file /fluent-bit/tls/tls.crt
tls.key_file /fluent-bit/tls/tls.key
{{- if .TLS.SharedKey }}
Shared_Key {{ .TLS.SharedKey }}
{{- else }}
Empty_Shared_Key true
{{- end }}
{{- end }}
{{- if .Network.ConnectTimeoutSet }}
net.connect_timeout {{.Network.ConnectTimeout}}
{{- end }}
{{- if .Network.KeepaliveSet}}
net.keepalive {{if .Network.Keepalive }}on{{else}}off{{end}}
{{- end }}
{{- if .Network.KeepaliveIdleTimeoutSet }}
net.keepalive_idle_timeout {{.Network.KeepaliveIdleTimeout}}
{{- end }}
{{- if .Network.KeepaliveMaxRecycleSet }}
net.keepalive_max_recycle {{.Network.KeepaliveMaxRecycle}}
{{- end }}
{{- if .ForwardOptions }}
{{- range $key, $value := .ForwardOptions }}
{{- if $value }}
{{ $key }} {{$value}}
{{- end }}
{{- end }}
{{- end }}
`

var upstreamConfigTemplate = `
[UPSTREAM]
Name {{ .Config.Name }}
{{- range $idx, $element:= .Config.Nodes}}
[NODE]
Name {{.Name}}
Host {{.Host}}
Port {{.Port}}
{{- end}}
`
Loading

0 comments on commit b6aa5be

Please sign in to comment.