diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index eac0bbadd..81caaca91 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,7 +24,7 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: - version: v2.11.4 + version: v2.13.2 actionlint: name: Lint GitHub Actions workflows diff --git a/.golangci.yml b/.golangci.yml index c1908eae3..b032f2355 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,6 +24,8 @@ linters: - unused settings: + goconst: + min-occurrences: 10 revive: rules: - name: comment-spacings @@ -42,6 +44,9 @@ linters: - dupl - lll path: internal/* + - linters: + - goconst + path: _test\.go - linters: - misspell path: apis/fluentbit/v1alpha2/plugins/common_types.go diff --git a/Makefile b/Makefile index e9efc33ff..55b22f40c 100644 --- a/Makefile +++ b/Makefile @@ -240,7 +240,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.18.0 ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') -GOLANGCI_LINT_VERSION ?= v2.6.2 +GOLANGCI_LINT_VERSION ?= v2.13.2 GINKGO_VERSION ?= v2.27.2 CODE_GENERATOR_VERSION ?= v0.32.3 KIND_VERSION ?= v0.30.0 diff --git a/apis/fluentbit/v1alpha2/clusterfilter_types.go b/apis/fluentbit/v1alpha2/clusterfilter_types.go index 423819cd0..583bb24da 100644 --- a/apis/fluentbit/v1alpha2/clusterfilter_types.go +++ b/apis/fluentbit/v1alpha2/clusterfilter_types.go @@ -163,8 +163,8 @@ func (list ClusterFilterList) Load(sl plugins.SecretLoader) (string, error) { } for _, elem := range item.Spec.FilterItems { - for i := 0; i < reflect.ValueOf(elem).NumField(); i++ { - p, _ := reflect.ValueOf(elem).Field(i).Interface().(plugins.Plugin) + for _, field := range reflect.ValueOf(elem).Fields() { + p, _ := field.Interface().(plugins.Plugin) if err := merge(p); err != nil { return "", err } @@ -224,8 +224,8 @@ func (list ClusterFilterList) LoadAsYaml(sl plugins.SecretLoader, depth int) (st } for _, elem := range item.Spec.FilterItems { - for i := 0; i < reflect.ValueOf(elem).NumField(); i++ { - p, _ := reflect.ValueOf(elem).Field(i).Interface().(plugins.Plugin) + for _, field := range reflect.ValueOf(elem).Fields() { + p, _ := field.Interface().(plugins.Plugin) if err := merge(p); err != nil { return "", err } diff --git a/apis/fluentbit/v1alpha2/clusterfilter_types_test.go b/apis/fluentbit/v1alpha2/clusterfilter_types_test.go index ac084d74d..bb22e89be 100644 --- a/apis/fluentbit/v1alpha2/clusterfilter_types_test.go +++ b/apis/fluentbit/v1alpha2/clusterfilter_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/filter" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -136,11 +135,11 @@ func TestClusterFilterList_Load(t *testing.T) { KubeURL: "http://127.0.0.1:6443", KubeCAFile: "root.ca", KubeCAPath: "/root/.kube/crt", - Labels: utils.ToPtr(true), - Annotations: utils.ToPtr(true), - DNSWaitTime: utils.ToPtr[int32](30), - UseKubelet: utils.ToPtr(true), - KubeletPort: utils.ToPtr[int32](10000), + Labels: new(true), + Annotations: new(true), + DNSWaitTime: new(int32(30)), + UseKubelet: new(true), + KubeletPort: new(int32(10000)), KubeMetaCacheTTL: "60s", }, }, @@ -164,8 +163,8 @@ func TestClusterFilterList_Load(t *testing.T) { CommonParams: plugins.CommonParams{ Alias: "throttle.application-xy", }, - Rate: utils.ToPtr[int64](200), - Window: utils.ToPtr[int64](300), + Rate: new(int64(200)), + Window: new(int64(300)), Interval: "1s", }, }, @@ -622,11 +621,11 @@ func TestClusterFilterList_Load_As_Yaml(t *testing.T) { KubeURL: "http://127.0.0.1:6443", KubeCAFile: "root.ca", KubeCAPath: "/root/.kube/crt", - Labels: utils.ToPtr(true), - Annotations: utils.ToPtr(true), - DNSWaitTime: utils.ToPtr[int32](30), - UseKubelet: utils.ToPtr(true), - KubeletPort: utils.ToPtr[int32](10000), + Labels: new(true), + Annotations: new(true), + DNSWaitTime: new(int32(30)), + UseKubelet: new(true), + KubeletPort: new(int32(10000)), KubeMetaCacheTTL: "60s", }, }, @@ -650,8 +649,8 @@ func TestClusterFilterList_Load_As_Yaml(t *testing.T) { CommonParams: plugins.CommonParams{ Alias: "throttle.application-xy", }, - Rate: utils.ToPtr[int64](200), - Window: utils.ToPtr[int64](300), + Rate: new(int64(200)), + Window: new(int64(300)), Interval: "1s", }, }, diff --git a/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go b/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go index 1e95b271a..f470acdbf 100644 --- a/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go +++ b/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go @@ -408,16 +408,16 @@ pipeline: cfg = ClusterFluentBitConfig{ Spec: FluentBitConfigSpec{ Service: &Service{ - Daemon: utils.ToPtr(false), - FlushSeconds: utils.ToPtr[float64](1), - GraceSeconds: utils.ToPtr[int64](30), - HttpServer: utils.ToPtr(true), + Daemon: new(false), + FlushSeconds: new(float64(1)), + GraceSeconds: new(int64(30)), + HttpServer: new(true), LogLevel: "info", ParsersFile: "parsers.conf", - HotReloadEnsureThreadSafety: utils.ToPtr(false), - HotReloadTimeout: utils.ToPtr[int32](60), - SchedulerBase: utils.ToPtr[int32](5), - SchedulerCap: utils.ToPtr[int32](2000), + HotReloadEnsureThreadSafety: new(false), + HotReloadTimeout: new(int32(60)), + SchedulerBase: new(int32(5)), + SchedulerCap: new(int32(2000)), }, }, } @@ -428,7 +428,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) { sl := plugins.NewSecretLoader(nil, "testnamespace") - disableInotifyWatcher := utils.ToPtr(true) + disableInotifyWatcher := new(true) inputObj := &ClusterInput{ TypeMeta: metav1.TypeMeta{ @@ -446,10 +446,10 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) { Tag: "logs.foo.bar", Path: "/logs/containers/apps0", ExcludePath: "/logs/containers/exclude_path", - SkipLongLines: utils.ToPtr(true), + SkipLongLines: new(true), IgnoreOlder: "5m", MemBufLimit: "5MB", - RefreshIntervalSeconds: utils.ToPtr[int64](10), + RefreshIntervalSeconds: new(int64(10)), DB: "/fluent-bit/tail/pos.db", }, }, @@ -533,10 +533,10 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) { Match: "logs.foo.bar", Syslog: &output.Syslog{ Host: "example.com", - Port: utils.ToPtr[int32](3300), + Port: new(int32(3300)), Mode: "tls", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, SyslogMessageKey: "log", SyslogHostnameKey: "do_app_name", @@ -566,14 +566,14 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) { Match: "logs.foo.bar", HTTP: &output.HTTP{ Host: "https://example2.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), Uri: "/logs", Headers: headers, Format: "json_lines", JsonDateKey: "timestamp", JsonDateFormat: "iso8601", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, }, }, @@ -593,7 +593,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) { Match: "*", OpenSearch: &output.OpenSearch{ Host: "https://example2.com", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "my_index", Type: "my_type", }, @@ -614,7 +614,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) { Match: "*", Elasticsearch: &output.Elasticsearch{ Host: "https://example2.com", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "my_index", Type: "my_type", WriteOperation: "upsert", @@ -661,7 +661,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { sl := plugins.NewSecretLoader(nil, "testnamespace") - disableInotifyWatcher := utils.ToPtr(true) + disableInotifyWatcher := new(true) inputObj := &ClusterInput{ TypeMeta: metav1.TypeMeta{ @@ -679,10 +679,10 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { Tag: "logs.foo.bar", Path: "/logs/containers/apps0", ExcludePath: "/logs/containers/exclude_path", - SkipLongLines: utils.ToPtr(true), + SkipLongLines: new(true), IgnoreOlder: "5m", MemBufLimit: "5MB", - RefreshIntervalSeconds: utils.ToPtr[int64](10), + RefreshIntervalSeconds: new(int64(10)), DB: "/fluent-bit/tail/pos.db", }, }, @@ -766,10 +766,10 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { Match: "logs.foo.bar", Syslog: &output.Syslog{ Host: "example.com", - Port: utils.ToPtr[int32](3300), + Port: new(int32(3300)), Mode: "tls", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, SyslogMessageKey: "log", SyslogHostnameKey: "do_app_name", @@ -799,14 +799,14 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { Match: "logs.foo.bar", HTTP: &output.HTTP{ Host: "https://example2.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), Uri: "/logs", Headers: headers, Format: "json_lines", JsonDateKey: "timestamp", JsonDateFormat: "iso8601", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, }, }, @@ -826,7 +826,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { Match: "*", OpenSearch: &output.OpenSearch{ Host: "https://example2.com", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "my_index", Type: "my_type", }, @@ -847,7 +847,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { Match: "*", Elasticsearch: &output.Elasticsearch{ Host: "https://example2.com", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "my_index", Type: "my_type", WriteOperation: "upsert", @@ -866,7 +866,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { }, Spec: OutputSpec{ CustomPlugin: &custom.CustomPlugin{ - YamlConfig: &plugins.Config{Data: map[string]interface{}{ + YamlConfig: &plugins.Config{Data: map[string]any{ "name": "kafka", "topics": "fluentbit", "match": "kube.*", @@ -896,7 +896,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) { }, Spec: OutputSpec{ CustomPlugin: &custom.CustomPlugin{ - YamlConfig: &plugins.Config{Data: map[string]interface{}{ + YamlConfig: &plugins.Config{Data: map[string]any{ "name": "kafka-namespace", "topics": "fluentbit-namespace", "match": "kube.namespace.*", @@ -935,10 +935,10 @@ func TestRenderMainConfigK8s(t *testing.T) { Tail: &input.Tail{ Tag: "kube.*", Path: "/var/log/containers/*.log", - SkipLongLines: utils.ToPtr(true), + SkipLongLines: new(true), IgnoreOlder: "5m", MemBufLimit: "5MB", - RefreshIntervalSeconds: utils.ToPtr[int64](10), + RefreshIntervalSeconds: new(int64(10)), DB: "/fluent-bit/tail/pos.db", }, }, @@ -969,7 +969,7 @@ func TestRenderMainConfigK8s(t *testing.T) { Parser: &filter.Parser{ KeyName: "log", Parser: "bar", - ReserveData: utils.ToPtr(true), + ReserveData: new(true), }, }, }, @@ -994,7 +994,7 @@ func TestRenderMainConfigK8s(t *testing.T) { Match: "kube.*", OpenSearch: &output.OpenSearch{ Host: "foo.bar", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "foo-index", }, }, @@ -1014,7 +1014,7 @@ func TestRenderMainConfigK8s(t *testing.T) { Match: "kube.*", Elasticsearch: &output.Elasticsearch{ Host: "foo.bar", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "foo-index", WriteOperation: "update", }, @@ -1058,10 +1058,10 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) { Tail: &input.Tail{ Tag: "kube.*", Path: "/var/log/containers/*.log", - SkipLongLines: utils.ToPtr(true), + SkipLongLines: new(true), IgnoreOlder: "5m", MemBufLimit: "5MB", - RefreshIntervalSeconds: utils.ToPtr[int64](10), + RefreshIntervalSeconds: new(int64(10)), DB: "/fluent-bit/tail/pos.db", }, }, @@ -1086,7 +1086,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) { {Parser: &filter.Parser{ KeyName: "log", Parser: "test", - ReserveData: utils.ToPtr(true), + ReserveData: new(true), }}, }, }, @@ -1108,7 +1108,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) { Match: "kube.*", Elasticsearch: &output.Elasticsearch{ Host: "foo.bar", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "foo-index", }, }, @@ -1132,7 +1132,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) { Parser: &filter.Parser{ KeyName: "log", Parser: "bar", - ReserveData: utils.ToPtr(true), + ReserveData: new(true), }, }, }, @@ -1157,7 +1157,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) { Match: "kube.*", OpenSearch: &output.OpenSearch{ Host: "foo.bar", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "foo-index", }, }, @@ -1177,7 +1177,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) { Match: "kube.*", Elasticsearch: &output.Elasticsearch{ Host: "foo.bar", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "foo-index", WriteOperation: "update", }, @@ -1205,8 +1205,8 @@ func TestClusterFluentBitConfig_Service_MultilineBufferLimit(t *testing.T) { cfbc := ClusterFluentBitConfig{ Spec: FluentBitConfigSpec{ Service: &Service{ - Daemon: utils.ToPtr(false), - FlushSeconds: utils.ToPtr[float64](1), + Daemon: new(false), + FlushSeconds: new(float64(1)), MultilineBufferLimit: "5MB", }, }, @@ -1246,10 +1246,10 @@ func TestClusterFluentBitConfig_RenderMainConfig_WithParsersFiles(t *testing.T) cfbc := ClusterFluentBitConfig{ Spec: FluentBitConfigSpec{ Service: &Service{ - Daemon: utils.ToPtr(false), - FlushSeconds: utils.ToPtr[float64](1), - GraceSeconds: utils.ToPtr[int64](30), - HttpServer: utils.ToPtr(true), + Daemon: new(false), + FlushSeconds: new(float64(1)), + GraceSeconds: new(int64(30)), + HttpServer: new(true), LogLevel: "info", ParsersFiles: []string{"parsers.conf", "parsers_multiline.conf"}, }, @@ -1512,12 +1512,12 @@ func TestRenderMainConfigInYaml_RewriteTagConfigMergesIntoSingleFiltersSection(t g.Expect(strings.Count(config, "filters:\n")).To(Equal(1)) - var parsed map[string]interface{} + var parsed map[string]any g.Expect(yaml.Unmarshal([]byte(config), &parsed)).To(Succeed()) - pipeline, ok := parsed["pipeline"].(map[string]interface{}) + pipeline, ok := parsed["pipeline"].(map[string]any) g.Expect(ok).To(BeTrue()) - filterEntries, ok := pipeline["filters"].([]interface{}) + filterEntries, ok := pipeline["filters"].([]any) g.Expect(ok).To(BeTrue()) g.Expect(filterEntries).To(HaveLen(2)) } diff --git a/apis/fluentbit/v1alpha2/clusterinput_types.go b/apis/fluentbit/v1alpha2/clusterinput_types.go index f82daf8c1..3de2180c6 100644 --- a/apis/fluentbit/v1alpha2/clusterinput_types.go +++ b/apis/fluentbit/v1alpha2/clusterinput_types.go @@ -153,8 +153,8 @@ func (list ClusterInputList) Load(sl plugins.SecretLoader) (string, error) { return nil } - for i := 0; i < reflect.ValueOf(item.Spec).NumField(); i++ { - p, _ := reflect.ValueOf(item.Spec).Field(i).Interface().(plugins.Plugin) + for _, field := range reflect.ValueOf(item.Spec).Fields() { + p, _ := field.Interface().(plugins.Plugin) if err := merge(p); err != nil { return "", err } @@ -213,8 +213,8 @@ func (list ClusterInputList) LoadAsYaml(sl plugins.SecretLoader, depth int) (str return nil } - for i := 0; i < reflect.ValueOf(item.Spec).NumField(); i++ { - p, _ := reflect.ValueOf(item.Spec).Field(i).Interface().(plugins.Plugin) + for _, field := range reflect.ValueOf(item.Spec).Fields() { + p, _ := field.Interface().(plugins.Plugin) if err := merge(p); err != nil { return "", err } diff --git a/apis/fluentbit/v1alpha2/clusterinput_types_test.go b/apis/fluentbit/v1alpha2/clusterinput_types_test.go index bc869c9e9..0a400302f 100644 --- a/apis/fluentbit/v1alpha2/clusterinput_types_test.go +++ b/apis/fluentbit/v1alpha2/clusterinput_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/input" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -87,18 +86,18 @@ func TestClusterInputList_Load(t *testing.T) { Spec: InputSpec{ Alias: "input0_alias", Tail: &input.Tail{ - DisableInotifyWatcher: utils.ToPtr(true), + DisableInotifyWatcher: new(true), Tag: "logs.foo.bar", Path: "/logs/containers/apps0", ExcludePath: "/logs/containers/exclude_path", - SkipLongLines: utils.ToPtr(true), + SkipLongLines: new(true), IgnoreOlder: "5m", MemBufLimit: "5MB", - RefreshIntervalSeconds: utils.ToPtr[int64](10), + RefreshIntervalSeconds: new(int64(10)), DB: "/fluent-bit/tail/pos.db", Parser: "docker", - DockerMode: utils.ToPtr(true), - DockerModeFlushSeconds: utils.ToPtr[int64](4), + DockerMode: new(true), + DockerModeFlushSeconds: new(int64(4)), DockerModeParser: "docker-mode-parser", }, }, @@ -116,8 +115,8 @@ func TestClusterInputList_Load(t *testing.T) { Alias: "input2_alias", Dummy: &input.Dummy{ Tag: "logs.foo.bar", - Rate: utils.ToPtr[int32](3), - Samples: utils.ToPtr[int32](5), + Rate: new(int32(3)), + Samples: new(int32(5)), }, }, } @@ -135,7 +134,7 @@ func TestClusterInputList_Load(t *testing.T) { PrometheusScrapeMetrics: &input.PrometheusScrapeMetrics{ Tag: "logs.foo.bar", Host: "https://example3.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), ScrapeInterval: "10s", MetricsPath: "/metrics", }, @@ -200,7 +199,7 @@ func TestFluentbitMetricClusterInputList_Load(t *testing.T) { FluentBitMetrics: &input.FluentbitMetrics{ Tag: "logs.foo.bar", ScrapeInterval: "2", - ScrapeOnStart: utils.ToPtr(true), + ScrapeOnStart: new(true), }, }, } @@ -216,7 +215,7 @@ func TestFluentbitMetricClusterInputList_Load(t *testing.T) { Spec: InputSpec{ Alias: "input1_alias", Forward: &input.Forward{ - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), Listen: "0.0.0.0", BufferChunkSize: "1M", BufferMaxSize: "6M", @@ -263,18 +262,18 @@ func TestClusterInputList_Load_As_Yaml(t *testing.T) { Spec: InputSpec{ Alias: "input0_alias", Tail: &input.Tail{ - DisableInotifyWatcher: utils.ToPtr(true), + DisableInotifyWatcher: new(true), Tag: "logs.foo.bar", Path: "/logs/containers/apps0", ExcludePath: "/logs/containers/exclude_path", - SkipLongLines: utils.ToPtr(true), + SkipLongLines: new(true), IgnoreOlder: "5m", MemBufLimit: "5MB", - RefreshIntervalSeconds: utils.ToPtr[int64](10), + RefreshIntervalSeconds: new(int64(10)), DB: "/fluent-bit/tail/pos.db", Parser: "docker", - DockerMode: utils.ToPtr(true), - DockerModeFlushSeconds: utils.ToPtr[int64](4), + DockerMode: new(true), + DockerModeFlushSeconds: new(int64(4)), DockerModeParser: "docker-mode-parser", }, }, @@ -292,8 +291,8 @@ func TestClusterInputList_Load_As_Yaml(t *testing.T) { Alias: "input2_alias", Dummy: &input.Dummy{ Tag: "logs.foo.bar", - Rate: utils.ToPtr[int32](3), - Samples: utils.ToPtr[int32](5), + Rate: new(int32(3)), + Samples: new(int32(5)), }, }, } @@ -311,7 +310,7 @@ func TestClusterInputList_Load_As_Yaml(t *testing.T) { PrometheusScrapeMetrics: &input.PrometheusScrapeMetrics{ Tag: "logs.foo.bar", Host: "https://example3.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), ScrapeInterval: "10s", MetricsPath: "/metrics", }, @@ -380,10 +379,10 @@ func TestClusterInputListProcessors_Load_As_Yaml(t *testing.T) { Tag: "logs.foo.bar", Dummy: "{\"key\":\"value\"}", }, - Processors: &plugins.Config{Data: map[string]interface{}{ - "logs": []interface{}{ - map[string]interface{}{"add": "hostname test", "name": "modify"}, - map[string]interface{}{"name": "lua", "call": "append_tag", "code": `function append_tag(tag, timestamp, record) + Processors: &plugins.Config{Data: map[string]any{ + "logs": []any{ + map[string]any{"add": "hostname test", "name": "modify"}, + map[string]any{"name": "lua", "call": "append_tag", "code": `function append_tag(tag, timestamp, record) new_record = record new_record["tag"] = tag return 1, timestamp, new_record diff --git a/apis/fluentbit/v1alpha2/clusteroutput_types_test.go b/apis/fluentbit/v1alpha2/clusteroutput_types_test.go index 65e8071b9..cd61d836d 100644 --- a/apis/fluentbit/v1alpha2/clusteroutput_types_test.go +++ b/apis/fluentbit/v1alpha2/clusteroutput_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/output" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -152,10 +151,10 @@ func TestClusterOutputList_Load(t *testing.T) { Match: "logs.foo.bar", Syslog: &output.Syslog{ Host: "example.com", - Port: utils.ToPtr[int32](3300), + Port: new(int32(3300)), Mode: "tls", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, SyslogMessageKey: "log", SyslogHostnameKey: "do_app_name", @@ -185,14 +184,14 @@ func TestClusterOutputList_Load(t *testing.T) { Match: "logs.foo.bar", HTTP: &output.HTTP{ Host: "https://example2.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), Uri: "/logs", Headers: headers, Format: "json_lines", JsonDateKey: "timestamp", JsonDateFormat: "iso8601", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, }, }, @@ -212,7 +211,7 @@ func TestClusterOutputList_Load(t *testing.T) { Match: "*", OpenSearch: &output.OpenSearch{ Host: "https://example2.com", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "my_index", Type: "my_type", }, @@ -237,15 +236,15 @@ func TestClusterOutputList_Load(t *testing.T) { Match: "logs.foo.bar", PrometheusRemoteWrite: &output.PrometheusRemoteWrite{ Host: "https://example3.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), URI: "/prometheus/v1/write?prometheus_server=YOUR_DATA_SOURCE_NAME", Proxy: "https://proxy:533", Headers: headers, - LogResponsePayload: utils.ToPtr(true), + LogResponsePayload: new(true), AddLabels: addLabels, - Workers: utils.ToPtr[int32](3), + Workers: new(int32(3)), TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, }, }, @@ -292,10 +291,10 @@ func TestClusterOutputList_Load_As_Yaml(t *testing.T) { Match: "logs.foo.bar", Syslog: &output.Syslog{ Host: "example.com", - Port: utils.ToPtr[int32](3300), + Port: new(int32(3300)), Mode: "tls", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, SyslogMessageKey: "log", SyslogHostnameKey: "do_app_name", @@ -325,14 +324,14 @@ func TestClusterOutputList_Load_As_Yaml(t *testing.T) { Match: "logs.foo.bar", HTTP: &output.HTTP{ Host: "https://example2.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), Uri: "/logs", Headers: headers, Format: "json_lines", JsonDateKey: "timestamp", JsonDateFormat: "iso8601", TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, }, }, @@ -352,7 +351,7 @@ func TestClusterOutputList_Load_As_Yaml(t *testing.T) { Match: "*", OpenSearch: &output.OpenSearch{ Host: "https://example2.com", - Port: utils.ToPtr[int32](9200), + Port: new(int32(9200)), Index: "my_index", Type: "my_type", }, @@ -377,15 +376,15 @@ func TestClusterOutputList_Load_As_Yaml(t *testing.T) { Match: "logs.foo.bar", PrometheusRemoteWrite: &output.PrometheusRemoteWrite{ Host: "https://example3.com", - Port: utils.ToPtr[int32](433), + Port: new(int32(433)), URI: "/prometheus/v1/write?prometheus_server=YOUR_DATA_SOURCE_NAME", Proxy: "https://proxy:533", Headers: headers, - LogResponsePayload: utils.ToPtr(true), + LogResponsePayload: new(true), AddLabels: addLabels, - Workers: utils.ToPtr[int32](3), + Workers: new(int32(3)), TLS: &plugins.TLS{ - Verify: utils.ToPtr(true), + Verify: new(true), }, }, }, @@ -434,7 +433,7 @@ func TestLokiOutputWithStructuredMetadata_Load(t *testing.T) { Match: "kube.*", Loki: &output.Loki{ Host: "loki-gateway", - Port: utils.ToPtr[int32](3100), + Port: new(int32(3100)), Labels: []string{ "job=fluentbit", "environment=production", @@ -487,7 +486,7 @@ func TestLokiOutputWithStructuredMetadata_LoadAsYaml(t *testing.T) { Match: "kube.*", Loki: &output.Loki{ Host: "loki-gateway", - Port: utils.ToPtr[int32](3100), + Port: new(int32(3100)), Labels: []string{ "job=fluentbit", "environment=production", @@ -533,7 +532,7 @@ func TestForwardOutput_RetainMetadataInForwardMode(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "fwd-nil"}, Spec: OutputSpec{ Match: "kube.*", - Forward: &output.Forward{Host: "fluentd.svc", Port: utils.ToPtr[int32](24224)}, + Forward: &output.Forward{Host: "fluentd.svc", Port: new(int32(24224))}, }, }}} resultNil, err := nilOut.Load(sl) @@ -547,8 +546,8 @@ func TestForwardOutput_RetainMetadataInForwardMode(t *testing.T) { Match: "kube.*", Forward: &output.Forward{ Host: "fluentd.svc", - Port: utils.ToPtr[int32](24224), - RetainMetadataInForwardMode: utils.ToPtr(false), + Port: new(int32(24224)), + RetainMetadataInForwardMode: new(false), }, }, }}} @@ -563,8 +562,8 @@ func TestForwardOutput_RetainMetadataInForwardMode(t *testing.T) { Match: "kube.*", Forward: &output.Forward{ Host: "fluentd.svc", - Port: utils.ToPtr[int32](24224), - RetainMetadataInForwardMode: utils.ToPtr(true), + Port: new(int32(24224)), + RetainMetadataInForwardMode: new(true), }, }, }}} diff --git a/apis/fluentbit/v1alpha2/filter_types.go b/apis/fluentbit/v1alpha2/filter_types.go index e0e5b8f77..4bfda624e 100644 --- a/apis/fluentbit/v1alpha2/filter_types.go +++ b/apis/fluentbit/v1alpha2/filter_types.go @@ -94,7 +94,7 @@ func (list FilterList) Load(sl plugins.SecretLoader) (string, error) { fmt.Fprintf(&buf, " Match_Regex %s\n", utils.GenerateNamespacedMatchRegExpr(item.Namespace, item.Spec.MatchRegex)) } - var iface interface{} = p + var iface any = p if f, ok := iface.(plugins.Namespaceable); ok { f.MakeNamespaced(item.Namespace) } @@ -112,8 +112,8 @@ func (list FilterList) Load(sl plugins.SecretLoader) (string, error) { } for _, elem := range item.Spec.FilterItems { - for i := 0; i < reflect.ValueOf(elem).NumField(); i++ { - p, _ := reflect.ValueOf(elem).Field(i).Interface().(plugins.Plugin) + for _, field := range reflect.ValueOf(elem).Fields() { + p, _ := field.Interface().(plugins.Plugin) if err := merge(p); err != nil { return "", err } @@ -152,7 +152,7 @@ func (list FilterList) LoadAsYaml(sl plugins.SecretLoader, depth int) (string, e fmt.Fprintf(&buf, "%smatch_regex: %s\n", padding, utils.GenerateNamespacedMatchRegExpr(item.Namespace, item.Spec.MatchRegex)) } - var iface interface{} = p + var iface any = p if f, ok := iface.(plugins.Namespaceable); ok { f.MakeNamespaced(item.Namespace) } @@ -170,8 +170,8 @@ func (list FilterList) LoadAsYaml(sl plugins.SecretLoader, depth int) (string, e } for _, elem := range item.Spec.FilterItems { - for i := 0; i < reflect.ValueOf(elem).NumField(); i++ { - p, _ := reflect.ValueOf(elem).Field(i).Interface().(plugins.Plugin) + for _, field := range reflect.ValueOf(elem).Fields() { + p, _ := field.Interface().(plugins.Plugin) if err := merge(p); err != nil { return "", err } diff --git a/apis/fluentbit/v1alpha2/filter_types_test.go b/apis/fluentbit/v1alpha2/filter_types_test.go index a6a3fd0ee..21c98912e 100644 --- a/apis/fluentbit/v1alpha2/filter_types_test.go +++ b/apis/fluentbit/v1alpha2/filter_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/filter" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" ) @@ -84,14 +83,14 @@ func TestFilterList_Load(t *testing.T) { Parser: &filter.Parser{ KeyName: "msg", Parser: "second-parser", - ReserveData: utils.ToPtr(true), + ReserveData: new(true), }, }, { Parser: &filter.Parser{ KeyName: "msg", Parser: "third-parser", - ReserveData: utils.ToPtr(true), + ReserveData: new(true), }, }, }, @@ -256,14 +255,14 @@ func TestFilterList_LoadAsYaml(t *testing.T) { Parser: &filter.Parser{ KeyName: "msg", Parser: "second-parser", - ReserveData: utils.ToPtr(true), + ReserveData: new(true), }, }, { Parser: &filter.Parser{ KeyName: "msg", Parser: "third-parser", - ReserveData: utils.ToPtr(true), + ReserveData: new(true), }, }, }, diff --git a/apis/fluentbit/v1alpha2/injection_test.go b/apis/fluentbit/v1alpha2/injection_test.go index e51a6cd8e..b5f38416f 100644 --- a/apis/fluentbit/v1alpha2/injection_test.go +++ b/apis/fluentbit/v1alpha2/injection_test.go @@ -7,7 +7,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/custom" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/output" - "github.com/fluent/fluent-operator/v3/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -62,7 +61,7 @@ func TestClusterOutput_Load_AllowsBenignConfig(t *testing.T) { Spec: OutputSpec{ Match: "logs.foo.bar", Alias: "my_alias", - HTTP: &output.HTTP{Host: "https://example.com", Port: utils.ToPtr[int32](443)}, + HTTP: &output.HTTP{Host: "https://example.com", Port: new(int32(443))}, }, }}} diff --git a/apis/fluentbit/v1alpha2/multilineparser_types.go b/apis/fluentbit/v1alpha2/multilineparser_types.go index bef7fdee1..3babae1e1 100644 --- a/apis/fluentbit/v1alpha2/multilineparser_types.go +++ b/apis/fluentbit/v1alpha2/multilineparser_types.go @@ -102,8 +102,8 @@ func load[T multilineParserInterface](items []T, sl plugins.SecretLoader) (strin return nil } - for i := 0; i < reflect.ValueOf(item.spec()).NumField(); i++ { - p, _ := reflect.ValueOf(item.spec()).Field(i).Interface().(plugins.Plugin) + for _, field := range reflect.ValueOf(item.spec()).Fields() { + p, _ := field.Interface().(plugins.Plugin) if err := merge(p); err != nil { return "", err } diff --git a/apis/fluentbit/v1alpha2/plugins/common_types.go b/apis/fluentbit/v1alpha2/plugins/common_types.go index 6c26da876..4e829e6b4 100644 --- a/apis/fluentbit/v1alpha2/plugins/common_types.go +++ b/apis/fluentbit/v1alpha2/plugins/common_types.go @@ -32,7 +32,7 @@ func (c *CommonParams) AddCommonParams(kvs *params.KVs) error { // +kubebuilder:validation:Type=object type Config struct { // Data holds the configuration keys and values. - Data map[string]interface{} `json:"-"` + Data map[string]any `json:"-"` } // MarshalJSON implements the Marshaler interface. @@ -42,7 +42,7 @@ func (c *Config) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the Unmarshaler interface. func (c *Config) UnmarshalJSON(data []byte) error { - var out map[string]interface{} + var out map[string]any err := json.Unmarshal(data, &out) if err != nil { return err @@ -52,7 +52,7 @@ func (c *Config) UnmarshalJSON(data []byte) error { } // MarshalYAML implements the yaml.Marshaler interface. -func (c *Config) MarshalYAML() (interface{}, error) { +func (c *Config) MarshalYAML() (any, error) { return c.Data, nil } @@ -65,7 +65,7 @@ func (c *Config) DeepCopyInto(out *Config) { // created in the API server panic(err) } - var clone map[string]interface{} + var clone map[string]any err = json.Unmarshal(bytes, &clone) if err != nil { // we assume again optimistically because we just marshalled that the round trip works as well diff --git a/apis/fluentbit/v1alpha2/plugins/input/syslog_test.go b/apis/fluentbit/v1alpha2/plugins/input/syslog_test.go index 887b3a1ec..4e31363ab 100644 --- a/apis/fluentbit/v1alpha2/plugins/input/syslog_test.go +++ b/apis/fluentbit/v1alpha2/plugins/input/syslog_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" ) @@ -22,9 +21,9 @@ func TestSyslog_Params(t *testing.T) { syslog := Syslog{ Mode: "tcp", Listen: "0.0.0.0", - Port: utils.ToPtr[int32](514), + Port: new(int32(514)), Path: "/tmp/syslog.sock", - UnixPerm: utils.ToPtr[int32](644), + UnixPerm: new(int32(644)), Parser: "syslog-rfc5424", BufferChunkSize: "32KB", BufferMaxSize: "256KB", diff --git a/apis/fluentbit/v1alpha2/plugins/output/datadog_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/datadog_types_test.go index ff1ac2e9f..c985b4813 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/datadog_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/datadog_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" ) @@ -16,14 +15,14 @@ func TestOutput_DataDog_Params(t *testing.T) { dd := DataDog{ Host: "http-intake.logs.datadoghq.com", - TLS: utils.ToPtr(true), + TLS: new(true), Compress: "gzip", Service: "service_name", Source: "app_name", Tags: "foo:bar", MessageKey: "message", JSONDateKey: "timestamp", - IncludeTagKey: utils.ToPtr(true), + IncludeTagKey: new(true), TagKey: "tagkey", } diff --git a/apis/fluentbit/v1alpha2/plugins/output/firehose_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/firehose_types_test.go index 9229d6c22..48c40bdd1 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/firehose_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/firehose_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" "github.com/onsi/gomega" ) @@ -17,19 +16,19 @@ func TestOutput_Firehose_Params(t *testing.T) { fh := Firehose{ Region: "us-east-1", DeliveryStream: "test_stream", - TimeKey: utils.ToPtr("test_time_key"), - TimeKeyFormat: utils.ToPtr("%Y-%m-%dT%H:%M:%S.%3N"), - DataKeys: utils.ToPtr("test_data_keys"), - LogKey: utils.ToPtr("test_time_key"), - RoleARN: utils.ToPtr("arn:aws:iam:test"), - Endpoint: utils.ToPtr("test_endpoint"), - STSEndpoint: utils.ToPtr("test_sts_endpoint"), - AutoRetryRequests: utils.ToPtr(true), - ExternalID: utils.ToPtr("test_external_id"), - Compression: utils.ToPtr("gzip"), - SimpleAggregation: utils.ToPtr(true), - Profile: utils.ToPtr("my-profile"), - Workers: utils.ToPtr[int32](1), + TimeKey: new("test_time_key"), + TimeKeyFormat: new("%Y-%m-%dT%H:%M:%S.%3N"), + DataKeys: new("test_data_keys"), + LogKey: new("test_time_key"), + RoleARN: new("arn:aws:iam:test"), + Endpoint: new("test_endpoint"), + STSEndpoint: new("test_sts_endpoint"), + AutoRetryRequests: new(true), + ExternalID: new("test_external_id"), + Compression: new("gzip"), + SimpleAggregation: new(true), + Profile: new("my-profile"), + Workers: new(int32(1)), } expected := params.NewKVs() diff --git a/apis/fluentbit/v1alpha2/plugins/output/gelf_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/gelf_types_test.go index bbdfdcdeb..ca5b7a44c 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/gelf_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/gelf_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" ) @@ -16,15 +15,15 @@ func TestOutput_Gelf_Params(t *testing.T) { dd := Gelf{ Host: "127.0.0.1", - Port: utils.ToPtr[int32](1234), + Port: new(int32(1234)), Mode: "udp", ShortMessageKey: "short_message", TimestampKey: "timestamp", HostKey: "host", FullMessageKey: "full_message", LevelKey: "level", - PacketSize: utils.ToPtr[int32](1000), - Compress: utils.ToPtr(true), + PacketSize: new(int32(1000)), + Compress: new(true), } expected := params.NewKVs() diff --git a/apis/fluentbit/v1alpha2/plugins/output/http_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/http_types_test.go index 2b62d5e50..54f581e61 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/http_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/http_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,15 +25,15 @@ func TestHTTP_Params(t *testing.T) { sl := plugins.NewSecretLoader(fc, "test_namespace") h := HTTP{ Host: "example.com", - Port: utils.ToPtr[int32](443), + Port: new(int32(443)), HTTPUser: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_user"}}}, HTTPPasswd: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_passwd"}}}, Uri: "/logs", Format: "json", - LogResponsePayload: utils.ToPtr(false), + LogResponsePayload: new(false), Headers: map[string]string{"X-Custom": "value"}, - TLS: &plugins.TLS{Verify: utils.ToPtr(false)}, - Networking: &plugins.Networking{SourceAddress: utils.ToPtr("expected_source_address")}, + TLS: &plugins.TLS{Verify: new(false)}, + Networking: &plugins.Networking{SourceAddress: new("expected_source_address")}, TotalLimitSize: "512M", } diff --git a/apis/fluentbit/v1alpha2/plugins/output/influxdb_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/influxdb_types_test.go index e7d12750e..5772d005e 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/influxdb_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/influxdb_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" ) @@ -16,14 +15,14 @@ func TestOutput_InfluxDB_Params(t *testing.T) { dd := InfluxDB{ Host: "127.0.0.1", - Port: utils.ToPtr[int32](8086), + Port: new(int32(8086)), Database: "fluentbit", Bucket: "buck", Org: "orgnis", SequenceTag: "_inc", TagKeys: []string{"foo", "bar", "foo:bar"}, - AutoTags: utils.ToPtr(false), - TagsListEnabled: utils.ToPtr(true), + AutoTags: new(false), + TagsListEnabled: new(true), TagsListKey: "taglist_key", } diff --git a/apis/fluentbit/v1alpha2/plugins/output/kinesis_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/kinesis_types_test.go index 248fd986d..933e31011 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/kinesis_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/kinesis_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" "github.com/onsi/gomega" ) @@ -23,7 +22,7 @@ func TestOutput_Kinesis_Params(t *testing.T) { RoleARN: "arn:aws:iam:test", Endpoint: "test_endpoint", STSEndpoint: "test_sts_endpoint", - AutoRetryRequests: utils.ToPtr(true), + AutoRetryRequests: new(true), ExternalID: "test_external_id", } diff --git a/apis/fluentbit/v1alpha2/plugins/output/open_telemetry_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/open_telemetry_types_test.go index 518753ff1..06429db9b 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/open_telemetry_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/open_telemetry_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,7 +25,7 @@ func TestOpenTelemetry_Params(t *testing.T) { sl := plugins.NewSecretLoader(fc, "test_namespace") ot := OpenTelemetry{ Host: "otlp-collector.example.com", - Port: utils.ToPtr[int32](443), + Port: new(int32(443)), HTTPUser: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_user"}}}, HTTPPasswd: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_passwd"}}}, Proxy: "expected_proxy", @@ -34,13 +33,13 @@ func TestOpenTelemetry_Params(t *testing.T) { LogsUri: "expected_logs_uri", TracesUri: "expected_traces_uri", Header: map[string]string{"custom_header_key": "custom_header_val"}, - LogResponsePayload: utils.ToPtr(true), + LogResponsePayload: new(true), AddLabel: map[string]string{"add_label_key": "add_label_val"}, - LogsBodyKeyAttributes: utils.ToPtr(true), + LogsBodyKeyAttributes: new(true), LogsBodyKey: "expected_logs_body_key", - TLS: &plugins.TLS{Verify: utils.ToPtr(false)}, - Networking: &plugins.Networking{SourceAddress: utils.ToPtr("expected_source_address")}, - BatchSize: utils.ToPtr[int32](512), + TLS: &plugins.TLS{Verify: new(false)}, + Networking: &plugins.Networking{SourceAddress: new("expected_source_address")}, + BatchSize: new(int32(512)), } expected := params.NewKVs() diff --git a/apis/fluentbit/v1alpha2/plugins/output/s3_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/s3_types_test.go index 63eb0b9a7..4921494ed 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/s3_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/s3_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" ) @@ -26,37 +25,37 @@ func TestOutput_S3_Params(t *testing.T) { StoreDirLimitSize: "0", S3KeyFormat: "/fluent-bit-logs/$TAG/%Y/%m/%d/%H/%M/%S", S3KeyFormatTagDelimiters: ".", - StaticFilePath: utils.ToPtr(false), - UsePutObject: utils.ToPtr(false), + StaticFilePath: new(false), + UsePutObject: new(false), RoleArn: "role", Endpoint: "endpoint", StsEndpoint: "sts_endpoint", CannedAcl: "canned_acl", Compression: "gzip", ContentType: "text/plain", - SendContentMd5: utils.ToPtr(false), - AutoRetryRequests: utils.ToPtr(true), + SendContentMd5: new(false), + AutoRetryRequests: new(true), LogKey: "log_key", - PreserveDataOrdering: utils.ToPtr(true), + PreserveDataOrdering: new(true), StorageClass: "storage_class", - RetryLimit: utils.ToPtr[int32](1), + RetryLimit: new(int32(1)), ExternalId: "external_id", Profile: "my-profile", - Workers: utils.ToPtr[int32](1), + Workers: new(int32(1)), Networking: &plugins.Networking{ - ConnectTimeout: utils.ToPtr[int32](10), - ConnectTimeoutLogError: utils.ToPtr(true), - DNSMode: utils.ToPtr("TCP"), - DNSPreferIPv4: utils.ToPtr(false), - DNSPreferIPv6: utils.ToPtr(false), - IOTimeout: utils.ToPtr[int32](0), - KeepaliveMaxRecycle: utils.ToPtr[int32](2000), - MaxWorkerConnections: utils.ToPtr[int32](0), - ProxyEnvIgnore: utils.ToPtr(false), - SourceAddress: utils.ToPtr("127.0.0.1"), - TCPKeepaliveInterval: utils.ToPtr[int32](-1), - TCPKeepaliveProbes: utils.ToPtr[int32](-1), - TCPKeepaliveTime: utils.ToPtr[int32](-1), + ConnectTimeout: new(int32(10)), + ConnectTimeoutLogError: new(true), + DNSMode: new("TCP"), + DNSPreferIPv4: new(false), + DNSPreferIPv6: new(false), + IOTimeout: new(int32(0)), + KeepaliveMaxRecycle: new(int32(2000)), + MaxWorkerConnections: new(int32(0)), + ProxyEnvIgnore: new(false), + SourceAddress: new("127.0.0.1"), + TCPKeepaliveInterval: new(int32(-1)), + TCPKeepaliveProbes: new(int32(-1)), + TCPKeepaliveTime: new(int32(-1)), }, } diff --git a/apis/fluentbit/v1alpha2/plugins/output/splunk_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/splunk_types_test.go index b4fb90396..26182514c 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/splunk_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/splunk_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -25,7 +24,7 @@ func TestSplunk_Params(t *testing.T) { sl := plugins.NewSecretLoader(fc, "test_namespace") s := Splunk{ Host: "splunk.example.com", - Port: utils.ToPtr[int32](8088), + Port: new(int32(8088)), SplunkToken: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "splunk_secret"}, Key: "splunk_token"}}}, TotalLimitSize: "512M", } diff --git a/apis/fluentbit/v1alpha2/plugins/output/syslog_types_test.go b/apis/fluentbit/v1alpha2/plugins/output/syslog_types_test.go index 32590d1ab..8c28fd6ba 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/syslog_types_test.go +++ b/apis/fluentbit/v1alpha2/plugins/output/syslog_types_test.go @@ -5,7 +5,6 @@ import ( "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" - "github.com/fluent/fluent-operator/v3/pkg/utils" . "github.com/onsi/gomega" ) @@ -16,10 +15,10 @@ func TestOutput_Syslog_Params(t *testing.T) { syslog := Syslog{ Host: "127.0.0.1", - Port: utils.ToPtr[int32](514), + Port: new(int32(514)), Mode: "tcp", SyslogFormat: "rfc5424", - SyslogMaxSize: utils.ToPtr[int32](2048), + SyslogMaxSize: new(int32(2048)), SyslogSeverityKey: "severity", SyslogFacilityKey: "facility", SyslogHostnameKey: "hostname", @@ -29,7 +28,7 @@ func TestOutput_Syslog_Params(t *testing.T) { SyslogSDKey: "structured_data", SyslogMessageKey: "message", TotalLimitSize: "1G", - Workers: utils.ToPtr[int32](2), + Workers: new(int32(2)), } expected := params.NewKVs() diff --git a/apis/fluentd/v1alpha1/plugins/params/model.go b/apis/fluentd/v1alpha1/plugins/params/model.go index 2e818ccef..3884c098b 100644 --- a/apis/fluentd/v1alpha1/plugins/params/model.go +++ b/apis/fluentd/v1alpha1/plugins/params/model.go @@ -208,7 +208,7 @@ func (ps *PluginStore) processHead(buf *bytes.Buffer) { // processes the key-value pair body func (ps *PluginStore) processBody(buf *bytes.Buffer) { - var body string + var body strings.Builder keys := make([]string, 0, len(ps.Store)) for k := range ps.Store { @@ -224,10 +224,10 @@ func (ps *PluginStore) processBody(buf *bytes.Buffer) { sort.Strings(keys) for _, k := range keys { - body += fmt.Sprintf("%s%s %s\n", ps.PrefixWhitespaces, k, escapeValue(ps.Store[k])) + fmt.Fprintf(&body, "%s%s %s\n", ps.PrefixWhitespaces, k, escapeValue(ps.Store[k])) } - buf.WriteString(body) + buf.WriteString(body.String()) } // write the tail directive to the buffer, i.e.: diff --git a/apis/fluentd/v1alpha1/plugins/params/model_test.go b/apis/fluentd/v1alpha1/plugins/params/model_test.go index 3593af42a..3230fcf28 100644 --- a/apis/fluentd/v1alpha1/plugins/params/model_test.go +++ b/apis/fluentd/v1alpha1/plugins/params/model_test.go @@ -85,7 +85,7 @@ func TestPluginStoreString_NoInjectionViaBody(t *testing.T) { // injected would appear on its own line; escaped, it stays inside the // quoted value on the parameter line. closingLines := 0 - for _, line := range strings.Split(got, "\n") { + for line := range strings.SplitSeq(got, "\n") { trimmed := strings.TrimSpace(line) if strings.HasPrefix(trimmed, "") { closingLines++ @@ -112,7 +112,7 @@ func TestPluginStoreString_NoInjectionViaHead(t *testing.T) { // Only line-leading directives change block nesting; the escaped value keeps // everything on one physical line, so at most one line may open a 0 { @@ -77,7 +77,7 @@ func MakeFluentdDaemonSet(fd fluentdv1alpha1.Fluentd) *appsv1.DaemonSet { }, Containers: []corev1.Container{ { - Name: "fluentd", + Name: fluentdLabelValue, Image: fd.Spec.Image, Args: fd.Spec.Args, ImagePullPolicy: fd.Spec.ImagePullPolicy, diff --git a/pkg/operator/fluentd-service.go b/pkg/operator/fluentd-service.go index 75aff2a8e..a888443d4 100644 --- a/pkg/operator/fluentd-service.go +++ b/pkg/operator/fluentd-service.go @@ -11,6 +11,7 @@ import ( const ( FluentdForwardPortName = "forward" FluentdHttpPortName = "http" + fluentdLabelValue = "fluentd" ) func MakeFluentdService(fd fluentdv1alpha1.Fluentd) *corev1.Service { @@ -28,8 +29,8 @@ func MakeFluentdService(fd fluentdv1alpha1.Fluentd) *corev1.Service { } else { labels = map[string]string{ "app.kubernetes.io/name": name, - "app.kubernetes.io/instance": "fluentd", - "app.kubernetes.io/component": "fluentd", + "app.kubernetes.io/instance": fluentdLabelValue, + "app.kubernetes.io/component": fluentdLabelValue, } } diff --git a/pkg/operator/pvc.go b/pkg/operator/pvc.go index d55601dd2..a2c066545 100644 --- a/pkg/operator/pvc.go +++ b/pkg/operator/pvc.go @@ -19,8 +19,8 @@ func MakeFluentdPVC(fd fluentdv1alpha1.Fluentd) *corev1.PersistentVolumeClaim { labels := map[string]string{ "app.kubernetes.io/name": fd.Name, - "app.kubernetes.io/instance": "fluentd", - "app.kubernetes.io/component": "fluentd", + "app.kubernetes.io/instance": fluentdLabelValue, + "app.kubernetes.io/component": fluentdLabelValue, } pvc := corev1.PersistentVolumeClaim{ @@ -42,8 +42,8 @@ func MakeFluentdPVC(fd fluentdv1alpha1.Fluentd) *corev1.PersistentVolumeClaim { func makeDefaultFluentdPVC(fd fluentdv1alpha1.Fluentd) *corev1.PersistentVolumeClaim { labels := map[string]string{ "app.kubernetes.io/name": fd.Name, - "app.kubernetes.io/instance": "fluentd", - "app.kubernetes.io/component": "fluentd", + "app.kubernetes.io/instance": fluentdLabelValue, + "app.kubernetes.io/component": fluentdLabelValue, } r := corev1.VolumeResourceRequirements{ diff --git a/pkg/operator/sts.go b/pkg/operator/sts.go index dd7c50345..72970539f 100644 --- a/pkg/operator/sts.go +++ b/pkg/operator/sts.go @@ -41,8 +41,8 @@ func MakeStatefulSet(fd fluentdv1alpha1.Fluentd) *appsv1.StatefulSet { labels := map[string]string{ "app.kubernetes.io/name": fd.Name, - "app.kubernetes.io/instance": "fluentd", - "app.kubernetes.io/component": "fluentd", + "app.kubernetes.io/instance": fluentdLabelValue, + "app.kubernetes.io/component": fluentdLabelValue, } if len(fd.Labels) > 0 { @@ -89,7 +89,7 @@ func MakeStatefulSet(fd fluentdv1alpha1.Fluentd) *appsv1.StatefulSet { }, Containers: []corev1.Container{ { - Name: "fluentd", + Name: fluentdLabelValue, Image: fd.Spec.Image, Args: fd.Spec.Args, ImagePullPolicy: fd.Spec.ImagePullPolicy, diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index c6d568255..f36d794f7 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -6,10 +6,6 @@ import ( "strings" ) -func ToPtr[T any](v T) *T { - return &v -} - func HashCode(msg string) string { var h = md5.New() h.Write([]byte(msg)) diff --git a/tests/e2e/fluentd/deployment_test.go b/tests/e2e/fluentd/deployment_test.go index e45a8c3a9..95bcb3b2e 100644 --- a/tests/e2e/fluentd/deployment_test.go +++ b/tests/e2e/fluentd/deployment_test.go @@ -14,7 +14,6 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" fluentdv1alpha1 "github.com/fluent/fluent-operator/v3/apis/fluentd/v1alpha1" @@ -77,12 +76,12 @@ var _ = Describe("Fluentd E2E Deployment Test", func() { }, }, Spec: fluentdv1alpha1.FluentdSpec{ - Replicas: ptr.To(int32(1)), + Replicas: new(int32(1)), GlobalInputs: []input.Input{ { Forward: &input.Forward{ - Bind: ptr.To("0.0.0.0"), - Port: ptr.To(int32(24224)), + Bind: new("0.0.0.0"), + Port: new(int32(24224)), }, }, },