fluent-operator icon indicating copy to clipboard operation
fluent-operator copied to clipboard

help request: fluent-operator: runtime error: invalid memory address or nil pointer dereference

Open wgh9626 opened this issue 3 years ago • 3 comments

Describe the issue

cat fluentd.yaml
apiVersion: fluentd.fluent.io/v1alpha1
kind: Fluentd
metadata:
  name: fluentd
  namespace: fluent
  labels:
    app.kubernetes.io/name: fluentd
spec:
  globalInputs:
  - forward:
      bind: 0.0.0.0
      port: 24224
  replicas: 1
  image: kubesphere/fluentd:v1.14.4
  fluentdCfgSelector:
    matchLabels:
      config.fluentd.fluent.io/enabled: "true"
  buffer:
    hostPath:
      path: "/var/log/fluentd-buffer"
---
apiVersion: fluentd.fluent.io/v1alpha1
kind: ClusterFluentdConfig
metadata:
  name: cluster-fluentd-config
  labels:
    config.fluentd.fluent.io/enabled: "true"
spec:
  watchedNamespaces:
  - kube-system
  - default
  - fluent
  - elastic
  - cattle-prometheus
  - icu
  - ingress-nginx
  - local-path-storage
  - longhorn-system
  - prod
  clusterFilterSelector:
    matchLabels:
      filter.fluentd.fluent.io/type: "buffer"
      filter.fluentd.fluent.io/enabled: "true"
  clusterOutputSelector:
    matchLabels:
      output.fluentd.fluent.io/scope: "cluster"
      output.fluentd.fluent.io/enabled: "true"
---
apiVersion: fluentd.fluent.io/v1alpha1
kind: ClusterFilter
metadata:
  name: cluster-fluentd-filter-buffer
  labels:
    filter.fluentd.fluent.io/type: "buffer"
    filter.fluentd.fluent.io/enabled: "true"
spec:
  filters:
  - recordTransformer:
      enableRuby: true
      records:
      - key: kubernetes_ns
        value: ${record["kubernetes"]["namespace_name"]}
---
apiVersion: fluentd.fluent.io/v1alpha1
kind: ClusterOutput
metadata:
  name: cluster-fluentd-output-es
  labels:
    output.fluentd.fluent.io/scope: "cluster"
    output.fluentd.fluent.io/enabled: "true"
spec:
  outputs:
  - elasticsearch:
      host: elasticsearch-master.elastic.svc
      port: 9200
      password:
        valueFrom:
          secretKeyRef:
            name: elasticsearch-password
            key: ES_PASSWORD
      user:
        valueFrom:
          secretKeyRef:
            name: elasticsearch-password
            key: ES_USER
      logstashFormat: true
      logstashPrefix: fluent-log
    buffer:
      type: file
      path: /buffers/es_buffer
---
apiVersion: v1
kind: Secret
metadata:
  name: elasticsearch-password
  namespace: fluent
data:
  ES_PASSWORD: S2dRemR5N1JkRlJKUHRWQg==
  ES_USER: ZWxhc3RpYw==
type: Opaque

When I apply -f fluentd.yaml, the fluent-operaor log reports an error:

Observed a panic in reconciler: runtime error: invalid memory address or nil pointer dereference	{"controller": "fluentd", "controllerGroup": "fluentd.fluent.io", "controllerKind": "Fluentd", "Fluentd": {"name":"cluster-fluentd-output-es"}, "namespace": "", "name": "cluster-fluentd-output-es", "reconcileID": "49e31186-0c68-46a7-8793-974dcad179fb"}
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x14108cb]
goroutine 555 [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:118 +0x1f4
panic({0x1562d20, 0x245b570})
	/usr/local/go/src/runtime/panic.go:884 +0x212
github.com/fluent/fluent-operator/controllers.(*FluentdConfigReconciler).ClusterCfgsForFluentd(0xc000533c20, {0x1981178, 0xc000a57440}, {{{0x0, 0x0}, {0x0, 0x0}}, {{0x0, 0x0}, {0x0, ...}, ...}, ...}, ...)
	/workspace/controllers/fluentdconfig_controller.go:267 +0x9cb
github.com/fluent/fluent-operator/controllers.(*FluentdConfigReconciler).Reconcile(0xc000533c20, {0x1981178, 0xc000a57440}, {{{0x0, 0x0}, {0xc000131540, 0x19}}})
	/workspace/controllers/fluentdconfig_controller.go:149 +0x7a5
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x19810d0?, {0x1981178?, 0xc000a57440?}, {{{0x0?, 0x16704e0?}, {0xc000131540?, 0x4045d4?}}})
	/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:121 +0xc8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc0004848c0, {0x19810d0, 0xc000782580}, {0x15b7460?, 0xc00069bae0?})
	/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:320 +0x33c
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc0004848c0, {0x19810d0, 0xc000782580})
	/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:273 +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:234 +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:230 +0x333

How can I solve this problem?

How did you install fluent operator?

helm fluent-operator-1.7.0

Additional context

No response

wgh9626 avatar Dec 05 '22 07:12 wgh9626

I used your yaml file, but it did not reproduce your problem. Are there any other notes?

Gentleelephant avatar Dec 07 '22 07:12 Gentleelephant

I used your yaml file, but it did not reproduce your problem. Are there any other notes?

env:

fluent-operator:kubesphere/fluent-operator:latest
fluentd:kubesphere/fluentd:v1.14.4
k8s version:v1.20.15
docker version:19.03.15

fluent-operator yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "2"
    meta.helm.sh/release-name: fluent-operator
    meta.helm.sh/release-namespace: fluent
  creationTimestamp: "2022-12-05T08:38:29Z"
  generation: 2
  labels:
    app.kubernetes.io/component: operator
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: fluent-operator
  name: fluent-operator
  namespace: fluent
  resourceVersion: "31377378"
  uid: 277bed75-02ee-4097-91c6-ff4a1a4a252c
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/component: operator
      app.kubernetes.io/name: fluent-operator
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app.kubernetes.io/component: operator
        app.kubernetes.io/name: fluent-operator
    spec:
      containers:
      - env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        image: kubesphere/fluent-operator:latest
        imagePullPolicy: Always
        name: fluent-operator
        resources:
          limits:
            cpu: 500m
            memory: 50Mi
          requests:
            cpu: 100m
            memory: 20Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /fluent-operator
          name: env
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - /bin/sh
        - -c
        - set -ex; echo CONTAINER_ROOT_DIR=$(docker info -f '{{.DockerRootDir}}' 2>
          /dev/null) > /fluent-operator/fluent-bit.env
        image: docker:20.10
        imagePullPolicy: IfNotPresent
        name: setenv
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /fluent-operator
          name: env
        - mountPath: /var/run/docker.sock
          name: dockersock
          readOnly: true
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: fluent-operator
      serviceAccountName: fluent-operator
      terminationGracePeriodSeconds: 30
      volumes:
      - emptyDir: {}
        name: env
      - hostPath:
          path: /var/run/docker.sock
          type: ""
        name: dockersock

I suspect it is caused by the configuration of the es password.It will work when I remove the user and password of es.

wgh9626 avatar Dec 07 '22 08:12 wgh9626

Same issue. Adding es user secret is creating the same error for me. Without username and password fields it works fine but cannot auth to ES.

maxkokocom avatar Sep 01 '23 17:09 maxkokocom