bug: fluent-operator crashes when applying FluentBitConfig
Describe the issue
I am testing out the latest development branch that includes additional CRs for e.g. namespaced FluentBitConfig and Output. It looks to me that it solves my issues related to multi tenant fluentbit setup.
What I am trying to achieve is to have a a cluster-wide, generic ClusterInput that picks up all logs but then have a namespaced FluentBitConfig and Output for my tenants to configure their own endpoints to send logs. I could of course have misunderstood the namespaced CR setup, if so I apologize.
I have added to my FluentBit config the new namespaced config selector. When I do that, the operator pod errors out with the following logs output:
I0406 09:15:16.140700 1 request.go:690] Waited for 1.010012652s due to client-side throttling, not priority and fairness, request: GET:https://10.26.0.1:443/apis/cilium.io/v2?timeout=32s
2023-04-06T09:15:16Z INFO controller-runtime.metrics Metrics server is starting to listen {"addr": ":8080"}
2023-04-06T09:15:16Z INFO setup starting manager
2023-04-06T09:15:16Z INFO Starting server {"path": "/metrics", "kind": "metrics", "addr": "[::]:8080"}
2023-04-06T09:15:16Z INFO Starting server {"kind": "health probe", "addr": "[::]:8081"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.FluentBit"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1.Secret"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.ClusterFluentBitConfig"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.FluentBitConfig"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.ClusterInput"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.ClusterFilter"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.ClusterOutput"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.ClusterParser"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.Filter"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.Output"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.Parser"}
2023-04-06T09:15:17Z INFO Starting Controller {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1alpha2.FluentBit"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1.ServiceAccount"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "source": "kind source: *v1.DaemonSet"}
2023-04-06T09:15:17Z INFO Starting Controller {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "collector", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "Collector", "source": "kind source: *v1alpha2.Collector"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "collector", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "Collector", "source": "kind source: *v1.ServiceAccount"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "collector", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "Collector", "source": "kind source: *v1.StatefulSet"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "collector", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "Collector", "source": "kind source: *v1.Service"}
2023-04-06T09:15:17Z INFO Starting Controller {"controller": "collector", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "Collector"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.Fluentd"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1.ServiceAccount"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1.StatefulSet"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1.Service"}
2023-04-06T09:15:17Z INFO Starting Controller {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.Fluentd"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1.Secret"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.ClusterFluentdConfig"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.FluentdConfig"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.Filter"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.ClusterFilter"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.Output"}
2023-04-06T09:15:17Z INFO Starting EventSource {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "source": "kind source: *v1alpha1.ClusterOutput"}
2023-04-06T09:15:17Z INFO Starting Controller {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd"}
2023-04-06T09:15:17Z INFO Starting workers {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "worker count": 1}
2023-04-06T09:15:17Z INFO Starting workers {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "worker count": 1}
2023-04-06T09:15:17Z INFO Starting workers {"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "worker count": 1}
2023-04-06T09:15:17Z INFO Observed a panic in reconciler: runtime error: index out of range [0] with length 0 {"controller": "fluentbit", "controllerGroup": "fluentbit.fluent.io", "controllerKind": "FluentBit", "FluentBit": {"name":"stdout"}, "namespace": "", "name": "stdout", "reconcileID": "7b53b347-2fe1-47fa-863c-9a2d7265c5b5"}
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
goroutine 673 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:119 +0x1fa
panic({0x17ce660, 0xc0017b5fc8})
/usr/local/go/src/runtime/panic.go:884 +0x213
github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2.ClusterFluentBitConfig.RenderMainConfig({{{0x15d7e4b, 0x16}, {0xc000d3d0a0, 0x1c}}, {{0xc000d3c6a0, 0x19}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...}, ...)
/workspace/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go:178 +0x7c5
github.com/fluent/fluent-operator/v2/controllers.(*FluentBitConfigReconciler).Reconcile(0xc00027a4b0, {0x1b21fb0, 0xc001cb1d40}, {{{0x0, 0x0}, {0xc001d838c6, 0x6}}})
/workspace/controllers/fluentbitconfig_controller.go:145 +0xa3f
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x1b21fb0?, {0x1b21fb0?, 0xc001cb1d40?}, {{{0x0?, 0x1668cc0?}, {0xc001d838c6?, 0x40f91d?}}})
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:122 +0xc8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc000199360, {0x1b21f08, 0xc0002793b0}, {0x1738fc0?, 0xc0003237e0?})
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:323 +0x377
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc000199360, {0x1b21f08, 0xc0002793b0})
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:274 +0x1d9
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:235 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:231 +0x587
To Reproduce
Apply a "basic" setup of fluentbit with fluent operator:
# FluentBit config with added namespaceFluentBitCfgSelector
apiVersion: fluentbit.fluent.io/v1alpha2
kind: FluentBit
metadata:
name: fluent-bit
namespace: fluent
labels:
app.kubernetes.io/name: fluent-bit
spec:
image: kubesphere/fluent-bit:v2.0.10
resources:
limits:
cpu: 500m
memory: 200Mi
requests:
cpu: 10m
memory: 25Mi
fluentBitConfigName: cluster-fluent-bit-config
namespaceFluentBitCfgSelector:
matchLabels:
onboardedFluentbit: "true"
tolerations:
- key: McsComponentsOnly
operator: Exists
effect: NoSchedule
- key: CriticalAddonsOnly
operator: Exists
effect: NoSchedule
annotations:
fluentbit.io/exclude: "true"
apiVersion: fluentbit.fluent.io/v1alpha2
kind: ClusterInput
metadata:
name: tail
labels:
fluentbit.fluent.io/enabled: "true"
spec:
tail:
tag: kube.*
path: "/var/log/containers/*.log"
parser: cri
refreshIntervalSeconds: 10
memBufLimit: 5MB
skipLongLines: true
apiVersion: fluentbit.fluent.io/v1alpha2
kind: ClusterFluentBitConfig
metadata:
name: cluster-fluent-bit-config
labels:
app.kubernetes.io/name: fluent-bit
spec:
service:
parsersFile: parsers.conf
inputSelector:
matchLabels:
fluentbit.fluent.io/enabled: "true"
outputSelector:
matchLabels:
fluentbit.fluent.io/enabled: "true"
Then, apply the new namespaced CRs:
apiVersion: fluentbit.fluent.io/v1alpha2
kind: FluentBitConfig
metadata:
name: ns-fluent-bit-config
namespace: test-sbx
labels:
onboardedFluentbit: "true"
spec:
outputSelector:
matchLabels:
fluentbit.fluent.io/enabled: "true"
apiVersion: fluentbit.fluent.io/v1alpha2
kind: ClusterOutput
metadata:
name: azure-output
labels:
fluentbit.fluent.io/enabled: "true"
spec:
customPlugin:
config: |
Name azure
Match kube.*
Customer_ID ************
Shared_Key ***********
Expected behavior
Logs from my pods in the namespace where the new FluentBitConfig and Output resource resides ends up in the log analytics workspace described in Output.
Your Environment
- Fluent Operator version: latest
- Container Runtime: containerd
- Operating system: Ubuntu 18.04.6 LTS
- Kernel version: 5.4.0-1105-azure
How did you install fluent operator?
kubectl apply -f https://raw.githubusercontent.com/fluent/fluentbit-operator/master/manifests/setup/setup.yaml
Additional context
No response
You can try reinstall it with helm : https://github.com/fluent/fluent-operator#deploy-fluent-operator-with-helm
You can try reinstall it with helm : https://github.com/fluent/fluent-operator#deploy-fluent-operator-with-helm
Thanks, that makes it a bit easier to work with. I cloned the repo and ran helm install fluent-operator --create-namespace -n fluent charts/fluent-operator/ --set containerRuntime=containerd with the following modifications done to template files:
Added this to fluentbit-fluentBit.yaml:
namespaceFluentBitCfgSelector:
matchLabels:
onboardedFluentbit: "true"
Added a new file:
#ns-config.yaml
apiVersion: fluentbit.fluent.io/v1alpha2
kind: FluentBitConfig
metadata:
name: ns-fluent-bit-config
namespace: test-ns
labels:
onboardedFluentbit: "true"
spec:
outputSelector:
matchLabels:
fluentbit.fluent.io/enabled: "true"
Still, I am seeing pod operator crashing with the same error log.
Still, I am seeing pod operator crashing with the same error log.
Use the released one: https://github.com/fluent/fluent-operator/releases/tag/v2.1.0
But v2.1.0 doesn't include the latest updated CRDs coming in from #630 which I am testing out?
We're going to release a new version soon and @wenchajun will test the new version before release it
We're going to release a new version soon and @wenchajun will test the new version before release it
All right nice! Will try with that release when it is available.