Skip to content

Commit 25994fd

Browse files
authored
Add kubernetes events input plugin (fluent#1209)
* Add Kubernetes Events Input Plugin Signed-off-by: Anson Liu <[email protected]> * Update role permission and fix typo Signed-off-by: Anson Liu <[email protected]> * update docs/fluentbit.md Signed-off-by: Anson Liu <[email protected]> * Update manifests in setup folder Signed-off-by: Anson Liu <[email protected]> --------- Signed-off-by: Anson Liu <[email protected]>
1 parent 59a2316 commit 25994fd

File tree

12 files changed

+453
-0
lines changed

12 files changed

+453
-0
lines changed

apis/fluentbit/v1alpha2/clusterinput_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type InputSpec struct {
7171
Syslog *input.Syslog `json:"syslog,omitempty"`
7272
// TCP defines the TCP input plugin configuration
7373
TCP *input.TCP `json:"tcp,omitempty"`
74+
// KubernetesEvents defines the KubernetesEvents input plugin configuration
75+
KubernetesEvents *input.KubernetesEvents `json:"kubernetesEvents,omitempty"`
7476
}
7577

7678
// +kubebuilder:object:root=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package input
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins"
7+
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/params"
8+
)
9+
10+
// +kubebuilder:object:generate:=true
11+
12+
// The KubernetesEvents input plugin allows you to collect kubernetes cluster events from kube-api server
13+
// **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/inputs/kubernetes-events*
14+
type KubernetesEvents struct {
15+
// Tag name associated to all records comming from this plugin.
16+
Tag string `json:"tag,omitempty"`
17+
// Set a database file to keep track of recorded Kubernetes events
18+
DB string `json:"db,omitempty"`
19+
// Set a database sync method. values: extra, full, normal and off
20+
DBSync string `json:"dbSync,omitempty"`
21+
// Set the polling interval for each channel.
22+
IntervalSec *int32 `json:"intervalSec,omitempty"`
23+
// Set the polling interval for each channel (sub seconds: nanoseconds).
24+
IntervalNsec *int64 `json:"intervalNsec,omitempty"`
25+
// API Server end-point
26+
KubeURL string `json:"kubeURL,omitempty"`
27+
// CA certificate file
28+
KubeCAFile string `json:"kubeCAFile,omitempty"`
29+
// Absolute path to scan for certificate files
30+
KubeCAPath string `json:"kubeCAPath,omitempty"`
31+
// Token file
32+
KubeTokenFile string `json:"kubeTokenFile,omitempty"`
33+
// configurable 'time to live' for the K8s token. By default, it is set to 600 seconds.
34+
// After this time, the token is reloaded from Kube_Token_File or the Kube_Token_Command.
35+
KubeTokenTTL string `json:"kubeTokenTTL,omitempty"`
36+
// kubernetes limit parameter for events query, no limit applied when set to 0.
37+
KubeRequestLimit *int32 `json:"kubeRequestLimit,omitempty"`
38+
// Kubernetes retention time for events.
39+
KubeRetentionTime string `json:"kubeRetentionTime,omitempty"`
40+
// Kubernetes namespace to query events from. Gets events from all namespaces by default
41+
KubeNamespace string `json:"kubeNamespace,omitempty"`
42+
// Debug level between 0 (nothing) and 4 (every detail).
43+
TLSDebug *int32 `json:"tlsDebug,omitempty"`
44+
// When enabled, turns on certificate validation when connecting to the Kubernetes API server.
45+
TLSVerify *bool `json:"tlsVerify,omitempty"`
46+
// Set optional TLS virtual host.
47+
TLSVhost string `json:"tlsVhost,omitempty"`
48+
}
49+
50+
func (_ *KubernetesEvents) Name() string {
51+
return "kubernetes_events"
52+
}
53+
54+
// implement Section() method
55+
func (k *KubernetesEvents) Params(_ plugins.SecretLoader) (*params.KVs, error) {
56+
kvs := params.NewKVs()
57+
if k.Tag != "" {
58+
kvs.Insert("Tag", k.Tag)
59+
}
60+
if k.DB != "" {
61+
kvs.Insert("DB", k.DB)
62+
}
63+
if k.DBSync != "" {
64+
kvs.Insert("DB_Sync", k.DBSync)
65+
}
66+
if k.IntervalSec != nil {
67+
kvs.Insert("Interval_Sec", fmt.Sprint(*k.IntervalSec))
68+
}
69+
if k.IntervalNsec != nil {
70+
kvs.Insert("Interval_Nsec", fmt.Sprint(*k.IntervalNsec))
71+
}
72+
if k.KubeURL != "" {
73+
kvs.Insert("Kube_URL", k.KubeURL)
74+
}
75+
if k.KubeCAFile != "" {
76+
kvs.Insert("Kube_CA_File", k.KubeCAFile)
77+
}
78+
if k.KubeCAPath != "" {
79+
kvs.Insert("Kube_CA_Path", k.KubeCAPath)
80+
}
81+
if k.KubeTokenFile != "" {
82+
kvs.Insert("Kube_Token_File", k.KubeTokenFile)
83+
}
84+
if k.KubeTokenTTL != "" {
85+
kvs.Insert("Kube_Token_TTL", k.KubeTokenTTL)
86+
}
87+
if k.KubeRequestLimit != nil {
88+
kvs.Insert("Kube_Request_Limit", fmt.Sprint(*k.KubeRequestLimit))
89+
}
90+
if k.KubeRetentionTime != "" {
91+
kvs.Insert("Kube_Retention_Time", k.KubeRetentionTime)
92+
}
93+
if k.KubeNamespace != "" {
94+
kvs.Insert("Kube_Namespace", k.KubeNamespace)
95+
}
96+
if k.TLSDebug != nil {
97+
kvs.Insert("tls.Debug", fmt.Sprint(*k.TLSDebug))
98+
}
99+
if k.TLSVerify != nil {
100+
kvs.Insert("tls.Verify", fmt.Sprint(*k.TLSVerify))
101+
}
102+
if k.TLSVhost != "" {
103+
kvs.Insert("tls.Vhost", k.TLSVhost)
104+
}
105+
return kvs, nil
106+
}

apis/fluentbit/v1alpha2/plugins/input/zz_generated.deepcopy.go

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/fluentbit/v1alpha2/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_clusterinputs.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,72 @@ spec:
243243
type: string
244244
type: object
245245
type: object
246+
kubernetesEvents:
247+
description: KubernetesEvents defines the KubernetesEvents input plugin
248+
configuration
249+
properties:
250+
db:
251+
description: Set a database file to keep track of recorded Kubernetes
252+
events
253+
type: string
254+
dbSync:
255+
description: 'Set a database sync method. values: extra, full,
256+
normal and off'
257+
type: string
258+
intervalNsec:
259+
description: 'Set the polling interval for each channel (sub seconds:
260+
nanoseconds).'
261+
format: int64
262+
type: integer
263+
intervalSec:
264+
description: Set the polling interval for each channel.
265+
format: int32
266+
type: integer
267+
kubeCAFile:
268+
description: CA certificate file
269+
type: string
270+
kubeCAPath:
271+
description: Absolute path to scan for certificate files
272+
type: string
273+
kubeNamespace:
274+
description: Kubernetes namespace to query events from. Gets events
275+
from all namespaces by default
276+
type: string
277+
kubeRequestLimit:
278+
description: kubernetes limit parameter for events query, no limit
279+
applied when set to 0.
280+
format: int32
281+
type: integer
282+
kubeRetentionTime:
283+
description: Kubernetes retention time for events.
284+
type: string
285+
kubeTokenFile:
286+
description: Token file
287+
type: string
288+
kubeTokenTTL:
289+
description: configurable 'time to live' for the K8s token. By
290+
default, it is set to 600 seconds. After this time, the token
291+
is reloaded from Kube_Token_File or the Kube_Token_Command.
292+
type: string
293+
kubeURL:
294+
description: API Server end-point
295+
type: string
296+
tag:
297+
description: Tag name associated to all records comming from this
298+
plugin.
299+
type: string
300+
tlsDebug:
301+
description: Debug level between 0 (nothing) and 4 (every detail).
302+
format: int32
303+
type: integer
304+
tlsVerify:
305+
description: When enabled, turns on certificate validation when
306+
connecting to the Kubernetes API server.
307+
type: boolean
308+
tlsVhost:
309+
description: Set optional TLS virtual host.
310+
type: string
311+
type: object
246312
logLevel:
247313
enum:
248314
- "off"

charts/fluent-operator/templates/fluent-operator-clusterRole.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ rules:
2525
- pods
2626
verbs:
2727
- get
28+
- apiGroups:
29+
- ""
30+
resources:
31+
- events
32+
verbs:
33+
- list
2834
- apiGroups:
2935
- ""
3036
resources:

config/crd/bases/fluentbit.fluent.io_clusterinputs.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,72 @@ spec:
243243
type: string
244244
type: object
245245
type: object
246+
kubernetesEvents:
247+
description: KubernetesEvents defines the KubernetesEvents input plugin
248+
configuration
249+
properties:
250+
db:
251+
description: Set a database file to keep track of recorded Kubernetes
252+
events
253+
type: string
254+
dbSync:
255+
description: 'Set a database sync method. values: extra, full,
256+
normal and off'
257+
type: string
258+
intervalNsec:
259+
description: 'Set the polling interval for each channel (sub seconds:
260+
nanoseconds).'
261+
format: int64
262+
type: integer
263+
intervalSec:
264+
description: Set the polling interval for each channel.
265+
format: int32
266+
type: integer
267+
kubeCAFile:
268+
description: CA certificate file
269+
type: string
270+
kubeCAPath:
271+
description: Absolute path to scan for certificate files
272+
type: string
273+
kubeNamespace:
274+
description: Kubernetes namespace to query events from. Gets events
275+
from all namespaces by default
276+
type: string
277+
kubeRequestLimit:
278+
description: kubernetes limit parameter for events query, no limit
279+
applied when set to 0.
280+
format: int32
281+
type: integer
282+
kubeRetentionTime:
283+
description: Kubernetes retention time for events.
284+
type: string
285+
kubeTokenFile:
286+
description: Token file
287+
type: string
288+
kubeTokenTTL:
289+
description: configurable 'time to live' for the K8s token. By
290+
default, it is set to 600 seconds. After this time, the token
291+
is reloaded from Kube_Token_File or the Kube_Token_Command.
292+
type: string
293+
kubeURL:
294+
description: API Server end-point
295+
type: string
296+
tag:
297+
description: Tag name associated to all records comming from this
298+
plugin.
299+
type: string
300+
tlsDebug:
301+
description: Debug level between 0 (nothing) and 4 (every detail).
302+
format: int32
303+
type: integer
304+
tlsVerify:
305+
description: When enabled, turns on certificate validation when
306+
connecting to the Kubernetes API server.
307+
type: boolean
308+
tlsVhost:
309+
description: Set optional TLS virtual host.
310+
type: string
311+
type: object
246312
logLevel:
247313
enum:
248314
- "off"

docs/fluentbit.md

+1
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ InputSpec defines the desired state of ClusterInput
456456
| nginx | Nginx defines the Nginx input plugin configuration | *[input.Nginx](plugins/input/nginx.md) |
457457
| syslog | Syslog defines the Syslog input plugin configuration | *[input.Syslog](plugins/input/syslog.md) |
458458
| tcp | TCP defines the TCP input plugin configuration | *[input.TCP](plugins/input/tcp.md) |
459+
| kubernetesEvents | KubernetesEvents defines the KubernetesEvents input plugin configuration | *[input.KubernetesEvents](plugins/input/kubernetesevents.md) |
459460

460461
[Back to TOC](#table-of-contents)
461462
# MultilineParser
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# KubernetesEvents
2+
3+
The KubernetesEvents input plugin allows you to collect kubernetes cluster events from kube-api server **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/inputs/kubernetes-events*
4+
5+
6+
| Field | Description | Scheme |
7+
| ----- | ----------- | ------ |
8+
| tag | Tag name associated to all records comming from this plugin. | string |
9+
| db | Set a database file to keep track of recorded Kubernetes events | string |
10+
| dbSync | Set a database sync method. values: extra, full, normal and off | string |
11+
| intervalSec | Set the polling interval for each channel. | *int32 |
12+
| intervalNsec | Set the polling interval for each channel (sub seconds: nanoseconds). | *int64 |
13+
| kubeURL | API Server end-point | string |
14+
| kubeCAFile | CA certificate file | string |
15+
| kubeCAPath | Absolute path to scan for certificate files | string |
16+
| kubeTokenFile | Token file | string |
17+
| kubeTokenTTL | configurable 'time to live' for the K8s token. By default, it is set to 600 seconds. After this time, the token is reloaded from Kube_Token_File or the Kube_Token_Command. | string |
18+
| kubeRequestLimit | kubernetes limit parameter for events query, no limit applied when set to 0. | *int32 |
19+
| kubeRetentionTime | Kubernetes retention time for events. | string |
20+
| kubeNamespace | Kubernetes namespace to query events from. Gets events from all namespaces by default | string |
21+
| tlsDebug | Debug level between 0 (nothing) and 4 (every detail). | *int32 |
22+
| tlsVerify | When enabled, turns on certificate validation when connecting to the Kubernetes API server. | *bool |
23+
| tlsVhost | Set optional TLS virtual host. | string |

manifests/setup/fluent-operator-clusterRole.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ rules:
2525
- pods
2626
verbs:
2727
- get
28+
- apiGroups:
29+
- ""
30+
resources:
31+
- events
32+
verbs:
33+
- list
2834
- apiGroups:
2935
- ""
3036
resources:

0 commit comments

Comments
 (0)