Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint

on:
push:
pull_request:

jobs:
lint:
name: Run on Ubuntu
runs-on: ubuntu-latest
steps:
- name: Clone the code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Setup Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
with:
go-version-file: go.mod

- name: Run linter
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
version: v2.1.0
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ lint: golangci-lint ## Run golangci-lint linter
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix

.PHONY: lint-config
lint-config: golangci-lint ## Verify golangci-lint linter configuration
$(GOLANGCI_LINT) config verify

##@ Build

binary:
Expand Down Expand Up @@ -197,7 +201,7 @@ KIND = $(LOCALBIN)/kind
KUSTOMIZE_VERSION ?= v5.6.0
CONTROLLER_TOOLS_VERSION ?= v0.15.0
ENVTEST_VERSION ?= release-0.19
GOLANGCI_LINT_VERSION ?= v1.59.1
GOLANGCI_LINT_VERSION ?= v2.0.1
GINKGO_VERSION ?= v2.23.4
CODE_GENERATOR_VERSION ?= v0.32.3
KIND_VERSION ?= v0.17.0
Expand All @@ -220,7 +224,7 @@ $(ENVTEST): $(LOCALBIN)
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
Expand Down
4 changes: 2 additions & 2 deletions apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ func (cfg ClusterFluentBitConfig) RenderNamespacedLuaScript(
for _, f := range nsfilters.Items {
for _, p := range f.Spec.FilterItems {
if p.Lua != nil && p.Lua.Script.Key != "" {
script, err := cl.LoadConfigMap(p.Lua.Script, f.ObjectMeta.Namespace)
script, err := cl.LoadConfigMap(p.Lua.Script, f.Namespace)
if err != nil {
return nil, err
}
namespacedScriptName := fmt.Sprintf("%x-%s", md5.Sum([]byte(f.ObjectMeta.Namespace)), p.Lua.Script.Key)
namespacedScriptName := fmt.Sprintf("%x-%s", md5.Sum([]byte(f.Namespace)), p.Lua.Script.Key)
scripts = append(scripts, Script{Name: namespacedScriptName, Content: script})
}
}
Expand Down
8 changes: 4 additions & 4 deletions apis/fluentbit/v1alpha2/collector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,25 @@ type Collector struct {

// IsBeingDeleted returns true if a deletion timestamp is set
func (co *Collector) IsBeingDeleted() bool {
return !co.ObjectMeta.DeletionTimestamp.IsZero()
return !co.DeletionTimestamp.IsZero()
}

// CollectorFinalizerName is the name of the fluentbit finalizer
const CollectorFinalizerName = "collector.fluent.io"

// HasFinalizer returns true if the item has the specified finalizer
func (co *Collector) HasFinalizer(finalizerName string) bool {
return slices.Contains(co.ObjectMeta.Finalizers, finalizerName)
return slices.Contains(co.Finalizers, finalizerName)
}

// AddFinalizer adds the specified finalizer
func (co *Collector) AddFinalizer(finalizerName string) {
co.ObjectMeta.Finalizers = append(co.ObjectMeta.Finalizers, finalizerName)
co.Finalizers = append(co.Finalizers, finalizerName)
}

// RemoveFinalizer removes the specified finalizer
func (co *Collector) RemoveFinalizer(finalizerName string) {
co.ObjectMeta.Finalizers = slices.DeleteFunc(co.ObjectMeta.Finalizers, func(s string) bool { return s == finalizerName })
co.Finalizers = slices.DeleteFunc(co.Finalizers, func(s string) bool { return s == finalizerName })
}

// +kubebuilder:object:root=true
Expand Down
8 changes: 4 additions & 4 deletions apis/fluentbit/v1alpha2/fluentbit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,25 @@ type FluentBit struct {

// IsBeingDeleted returns true if a deletion timestamp is set
func (fb *FluentBit) IsBeingDeleted() bool {
return !fb.ObjectMeta.DeletionTimestamp.IsZero()
return !fb.DeletionTimestamp.IsZero()
}

// FluentBitFinalizerName is the name of the fluentbit finalizer
const FluentBitFinalizerName = "fluentbit.fluent.io"

// HasFinalizer returns true if the item has the specified finalizer
func (fb *FluentBit) HasFinalizer(finalizerName string) bool {
return slices.Contains(fb.ObjectMeta.Finalizers, finalizerName)
return slices.Contains(fb.Finalizers, finalizerName)
}

// AddFinalizer adds the specified finalizer
func (fb *FluentBit) AddFinalizer(finalizerName string) {
fb.ObjectMeta.Finalizers = append(fb.ObjectMeta.Finalizers, finalizerName)
fb.Finalizers = append(fb.Finalizers, finalizerName)
}

// RemoveFinalizer removes the specified finalizer
func (fb *FluentBit) RemoveFinalizer(finalizerName string) {
fb.ObjectMeta.Finalizers = slices.DeleteFunc(fb.ObjectMeta.Finalizers, func(s string) bool { return s == finalizerName })
fb.Finalizers = slices.DeleteFunc(fb.Finalizers, func(s string) bool { return s == finalizerName })
}

// +kubebuilder:object:root=true
Expand Down
3 changes: 2 additions & 1 deletion apis/fluentbit/v1alpha2/plugins/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type CommonParams struct {

// Alias for the plugin
Alias string `json:"alias,omitempty"`
// RetryLimit describes how many times fluent-bit should retry to send data to a specific output. If set to false fluent-bit will try indefinetly. If set to any integer N>0 it will try at most N+1 times. Leading zeros are not allowed (values such as 007, 0150, 01 do not work). If this property is not defined fluent-bit will use the default value: 1.
// RetryLimit describes how many times fluent-bit should retry to send data to a specific output. If set to false fluent-bit will try indefinitely. If set to any integer N>0 it will try at most N+1 times. Leading zeros are not allowed (values such as 007, 0150, 01 do not work). If this property is not defined fluent-bit will use the default value: 1.
// nolint:misspell
// +kubebuilder:validation:Pattern="^(((f|F)alse)|(no_limits)|(no_retries)|([1-9]+[0-9]*))$"
RetryLimit string `json:"retryLimit,omitempty"`
}
Expand Down
7 changes: 4 additions & 3 deletions apis/fluentbit/v1alpha2/plugins/configmap_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package plugins
import (
"context"
"fmt"
"strings"

"github.com/go-openapi/errors"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
)

type ConfigMapLoader struct {
Expand All @@ -30,6 +31,6 @@ func (cl ConfigMapLoader) LoadConfigMap(selector v1.ConfigMapKeySelector, namesp
if v, ok := configMap.Data[selector.Key]; !ok {
return "", errors.NotFound(fmt.Sprintf("The key %s is not found.", selector.Key))
} else {
return strings.TrimSuffix(fmt.Sprintf("%s", v), "\n"), nil
return strings.TrimSuffix(v, "\n"), nil
}
}
10 changes: 4 additions & 6 deletions apis/fluentbit/v1alpha2/plugins/custom/custom_plugin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,18 @@ func (c *CustomPlugin) MakeNamespaced(ns string) {
}

func indentation(str string) string {
splits := strings.Split(str, "\n")
var buf bytes.Buffer
for _, i := range splits {
if i != "" {
buf.WriteString(fmt.Sprintf(" %s\n", strings.TrimSpace(i)))
for s := range strings.SplitSeq(str, "\n") {
if s != "" {
buf.WriteString(fmt.Sprintf(" %s\n", strings.TrimSpace(s)))
}
}
return buf.String()
}

func MakeCustomConfigNamespaced(customConfig string, namespace string) string {
var buf bytes.Buffer
sections := strings.Split(customConfig, "\n")
for _, section := range sections {
for section := range strings.SplitSeq(customConfig, "\n") {
section = strings.TrimSpace(section)
idx := strings.LastIndex(section, " ")
if strings.HasPrefix(section, "Match_Regex") {
Expand Down
16 changes: 8 additions & 8 deletions apis/fluentbit/v1alpha2/plugins/filter/aws_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ type AWS struct {
ImdsVersion string `json:"imdsVersion,omitempty"`
// The availability zone; for example, "us-east-1a". Default is true.
AZ *bool `json:"az,omitempty"`
//The EC2 instance ID.Default is true.
// The EC2 instance ID.Default is true.
EC2InstanceID *bool `json:"ec2InstanceID,omitempty"`
//The EC2 instance type.Default is false.
// The EC2 instance type.Default is false.
EC2InstanceType *bool `json:"ec2InstanceType,omitempty"`
//The EC2 instance private ip.Default is false.
// The EC2 instance private ip.Default is false.
PrivateIP *bool `json:"privateIP,omitempty"`
//The EC2 instance image id.Default is false.
// The EC2 instance image id.Default is false.
AmiID *bool `json:"amiID,omitempty"`
//The account ID for current EC2 instance.Default is false.
// The account ID for current EC2 instance.Default is false.
AccountID *bool `json:"accountID,omitempty"`
//The hostname for current EC2 instance.Default is false.
// The hostname for current EC2 instance.Default is false.
HostName *bool `json:"hostName,omitempty"`
//The VPC ID for current EC2 instance.Default is false.
// The VPC ID for current EC2 instance.Default is false.
VpcID *bool `json:"vpcID,omitempty"`
}

func (_ *AWS) Name() string {
func (*AWS) Name() string {
return "aws"
}

Expand Down
2 changes: 1 addition & 1 deletion apis/fluentbit/v1alpha2/plugins/filter/grep_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Grep struct {
Exclude string `json:"exclude,omitempty"`
}

func (_ *Grep) Name() string {
func (*Grep) Name() string {
return "grep"
}

Expand Down
2 changes: 1 addition & 1 deletion apis/fluentbit/v1alpha2/plugins/filter/kubernetes_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type Kubernetes struct {
UseTagForMeta *bool `json:"useTagForMeta,omitempty"`
}

func (_ *Kubernetes) Name() string {
func (*Kubernetes) Name() string {
return "kubernetes"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type LogToMetrics struct {
DiscardLogs *bool `json:"discardLogs,omitempty"`
}

func (_ *LogToMetrics) Name() string {
func (*LogToMetrics) Name() string {
return "log_to_metrics"
}

Expand Down
11 changes: 6 additions & 5 deletions apis/fluentbit/v1alpha2/plugins/filter/lua_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ func (l *Lua) Params(_ plugins.SecretLoader) (*params.KVs, error) {
}

if l.Code != "" {
var singleLineLua string = ""
var singleLineLua = ""
lineTrim := ""
for _, line := range strings.Split(strings.TrimSuffix(l.Code, "\n"), "\n") {
re := regexp.MustCompile(`^function |^if |^for |^else|^elseif |^end|--[[]+`)
for line := range strings.SplitSeq(strings.TrimSuffix(l.Code, "\n"), "\n") {
lineTrim = strings.TrimSpace(line)
if lineTrim != "" {
operator, _ := regexp.MatchString("^function |^if |^for |^else|^elseif |^end|--[[]+", lineTrim)
operator := re.MatchString(lineTrim)
if operator {
singleLineLua = singleLineLua + lineTrim + " "
} else {
Expand All @@ -77,11 +78,11 @@ func (l *Lua) Params(_ plugins.SecretLoader) (*params.KVs, error) {

kvs.Insert("call", l.Call)

if l.TypeIntKey != nil && len(l.TypeIntKey) > 0 {
if len(l.TypeIntKey) > 0 {
kvs.Insert("type_int_key", strings.Join(l.TypeIntKey, " "))
}

if l.TypeArrayKey != nil && len(l.TypeArrayKey) > 0 {
if len(l.TypeArrayKey) > 0 {
kvs.Insert("type_array_key", strings.Join(l.TypeArrayKey, " "))
}

Expand Down
21 changes: 11 additions & 10 deletions apis/fluentbit/v1alpha2/plugins/filter/modify_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,37 @@ func (mo *Modify) Params(_ plugins.SecretLoader) (*params.KVs, error) {
if err != nil {
return kvs, err
}
const condition = "Condition"
for _, c := range mo.Conditions {
if c.KeyExists != "" {
kvs.Insert("Condition", fmt.Sprintf("Key_exists %s", c.KeyExists))
kvs.Insert(condition, fmt.Sprintf("Key_exists %s", c.KeyExists))
}
kvs.InsertStringMap(c.KeyDoesNotExist, func(k, v string) (string, string) {
return "Condition", fmt.Sprintf("Key_does_not_exist %s %s", k, v)
return condition, fmt.Sprintf("Key_does_not_exist %s %s", k, v)
})
if c.AKeyMatches != "" {
kvs.Insert("Condition", fmt.Sprintf("A_key_matches %s", c.AKeyMatches))
kvs.Insert(condition, fmt.Sprintf("A_key_matches %s", c.AKeyMatches))
}
if c.NoKeyMatches != "" {
kvs.Insert("Condition", fmt.Sprintf("No_key_matches %s", c.NoKeyMatches))
kvs.Insert(condition, fmt.Sprintf("No_key_matches %s", c.NoKeyMatches))
}
kvs.InsertStringMap(c.KeyValueEquals, func(k, v string) (string, string) {
return "Condition", fmt.Sprintf("Key_value_equals %s %s", k, v)
return condition, fmt.Sprintf("Key_value_equals %s %s", k, v)
})
kvs.InsertStringMap(c.KeyValueDoesNotEqual, func(k, v string) (string, string) {
return "Condition", fmt.Sprintf("Key_value_does_not_equal %s %s", k, v)
return condition, fmt.Sprintf("Key_value_does_not_equal %s %s", k, v)
})
kvs.InsertStringMap(c.KeyValueMatches, func(k, v string) (string, string) {
return "Condition", fmt.Sprintf("Key_value_matches %s %s", k, v)
return condition, fmt.Sprintf("Key_value_matches %s %s", k, v)
})
kvs.InsertStringMap(c.KeyValueDoesNotMatch, func(k, v string) (string, string) {
return "Condition", fmt.Sprintf("Key_value_does_not_match %s %s", k, v)
return condition, fmt.Sprintf("Key_value_does_not_match %s %s", k, v)
})
kvs.InsertStringMap(c.MatchingKeysHaveMatchingValues, func(k, v string) (string, string) {
return "Condition", fmt.Sprintf("Matching_keys_have_matching_values %s %s", k, v)
return condition, fmt.Sprintf("Matching_keys_have_matching_values %s %s", k, v)
})
kvs.InsertStringMap(c.MatchingKeysDoNotHaveMatchingValues, func(k, v string) (string, string) {
return "Condition", fmt.Sprintf("Matching_keys_do_not_have_matching_values %s %s", k, v)
return condition, fmt.Sprintf("Matching_keys_do_not_have_matching_values %s %s", k, v)
})
}
for _, r := range mo.Rules {
Expand Down
40 changes: 20 additions & 20 deletions apis/fluentbit/v1alpha2/plugins/filter/multiline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ type Multiline struct {

type Multi struct {
// Specify one or multiple Multiline Parsing definitions to apply to the content.
//You can specify multiple multiline parsers to detect different formats by separating them with a comma.
// You can specify multiple multiline parsers to detect different formats by separating them with a comma.
Parser string `json:"parser"`
//Key name that holds the content to process.
//Note that a Multiline Parser definition can already specify the key_content to use, but this option allows to overwrite that value for the purpose of the filter.
// Key name that holds the content to process.
// Note that a Multiline Parser definition can already specify the key_content to use, but this option allows to overwrite that value for the purpose of the filter.
KeyContent string `json:"keyContent,omitempty"`
// +kubebuilder:validation:Enum:=parser;partial_message
Mode string `json:"mode,omitempty"`
Expand All @@ -41,7 +41,7 @@ type Multi struct {
EmitterMemBufLimit int `json:"emitterMemBufLimit,omitempty"`
}

func (_ *Multiline) Name() string {
func (*Multiline) Name() string {
return "multiline"
}

Expand All @@ -52,29 +52,29 @@ func (m *Multiline) Params(_ plugins.SecretLoader) (*params.KVs, error) {
return kvs, err
}
if m.Multi != nil {
if m.Multi.Parser != "" {
kvs.Insert("multiline.parser", m.Multi.Parser)
if m.Parser != "" {
kvs.Insert("multiline.parser", m.Parser)
}
if m.Multi.KeyContent != "" {
kvs.Insert("multiline.key_content", m.Multi.KeyContent)
if m.KeyContent != "" {
kvs.Insert("multiline.key_content", m.KeyContent)
}
if m.Multi.Mode != "" {
kvs.Insert("mode", m.Multi.Mode)
if m.Mode != "" {
kvs.Insert("mode", m.Mode)
}
if m.Multi.Buffer != false {
kvs.Insert("buffer", fmt.Sprint(m.Multi.Buffer))
if m.Buffer {
kvs.Insert("buffer", fmt.Sprint(m.Buffer))
}
if m.Multi.FlushMS != 0 {
kvs.Insert("flush_ms", fmt.Sprint(m.Multi.FlushMS))
if m.FlushMS != 0 {
kvs.Insert("flush_ms", fmt.Sprint(m.FlushMS))
}
if m.Multi.EmitterName != "" {
kvs.Insert("emitter_name", m.Multi.EmitterName)
if m.EmitterName != "" {
kvs.Insert("emitter_name", m.EmitterName)
}
if m.Multi.EmitterType != "" {
kvs.Insert("emitter_storage.type", m.Multi.EmitterType)
if m.EmitterType != "" {
kvs.Insert("emitter_storage.type", m.EmitterType)
}
if m.Multi.EmitterMemBufLimit != 0 {
kvs.Insert("emitter_mem_buf_limit", fmt.Sprintf("%dMB", m.Multi.EmitterMemBufLimit))
if m.EmitterMemBufLimit != 0 {
kvs.Insert("emitter_mem_buf_limit", fmt.Sprintf("%dMB", m.EmitterMemBufLimit))
}
}
return kvs, nil
Expand Down
2 changes: 1 addition & 1 deletion apis/fluentbit/v1alpha2/plugins/filter/nest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Nest struct {
RemovePrefix string `json:"removePrefix,omitempty"`
}

func (_ *Nest) Name() string {
func (*Nest) Name() string {
return "nest"
}

Expand Down
Loading
Loading