|
| 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 | +} |
0 commit comments