Skip to content

Commit 28c4240

Browse files
Merge pull request #1708 from marcofranssen/fix-cyclo-complexity
Fix cyclomatic complexity linter warnings
2 parents e50d5c7 + 30cd0c3 commit 28c4240

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1468
-1941
lines changed

apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
629629
i++
630630
}
631631
}
632+
632633
func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
633634
g := NewGomegaWithT(t)
634635

apis/fluentbit/v1alpha2/clusteroutput_types_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ func TestClusterOutputList_Load(t *testing.T) {
164164
}
165165

166166
headers := map[string]string{
167-
"Authorization": "foo:bar",
168-
"X-Log-Header-App-Name": "app_name",
169-
"X-Log-Header-0": "testing",
170-
"X-Log-Header-App-ID": "9780495d9db3",
167+
"Authorization": authorization,
168+
"X-Log-Header-App-Name": xLogHeaderAppName,
169+
"X-Log-Header-0": xLogHeader0,
170+
"X-Log-Header-App-ID": xLogHeaderAppID,
171171
}
172172

173173
httpOutput := ClusterOutput{
@@ -304,10 +304,10 @@ func TestClusterOutputList_Load_As_Yaml(t *testing.T) {
304304
}
305305

306306
headers := map[string]string{
307-
"Authorization": "foo:bar",
308-
"X-Log-Header-App-Name": "app_name",
309-
"X-Log-Header-0": "testing",
310-
"X-Log-Header-App-ID": "9780495d9db3",
307+
"Authorization": authorization,
308+
"X-Log-Header-App-Name": xLogHeaderAppName,
309+
"X-Log-Header-0": xLogHeader0,
310+
"X-Log-Header-App-ID": xLogHeaderAppID,
311311
}
312312

313313
httpOutput := ClusterOutput{

apis/fluentbit/v1alpha2/plugins/common_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type CommonParams struct {
1313
// Alias for the plugin
1414
Alias string `json:"alias,omitempty"`
1515
// 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.
16-
// nolint:misspell
1716
// +kubebuilder:validation:Pattern="^(((f|F)alse)|(no_limits)|(no_retries)|([1-9]+[0-9]*))$"
1817
RetryLimit string `json:"retryLimit,omitempty"`
1918
}

apis/fluentbit/v1alpha2/plugins/filter/kubernetes_types.go

Lines changed: 39 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -119,114 +119,45 @@ func (k *Kubernetes) Params(_ plugins.SecretLoader) (*params.KVs, error) {
119119
if err != nil {
120120
return kvs, err
121121
}
122-
if k.BufferSize != "" {
123-
kvs.Insert("Buffer_Size", k.BufferSize)
124-
}
125-
if k.KubeURL != "" {
126-
kvs.Insert("Kube_URL", k.KubeURL)
127-
}
128-
if k.KubeCAFile != "" {
129-
kvs.Insert("Kube_CA_File", k.KubeCAFile)
130-
}
131-
if k.KubeCAPath != "" {
132-
kvs.Insert("Kube_CA_Path", k.KubeCAPath)
133-
}
134-
if k.KubeTokenFile != "" {
135-
kvs.Insert("Kube_Token_File", k.KubeTokenFile)
136-
}
137-
if k.KubeTagPrefix != "" {
138-
kvs.Insert("Kube_Tag_Prefix", k.KubeTagPrefix)
139-
}
140-
if k.MergeLog != nil {
141-
kvs.Insert("Merge_Log", fmt.Sprint(*k.MergeLog))
142-
}
143-
if k.MergeLogKey != "" {
144-
kvs.Insert("Merge_Log_Key", k.MergeLogKey)
145-
}
146-
if k.MergeLogTrim != nil {
147-
kvs.Insert("Merge_Log_Trim", fmt.Sprint(*k.MergeLogTrim))
148-
}
149-
if k.MergeParser != "" {
150-
kvs.Insert("Merge_Parser", k.MergeParser)
151-
}
152-
if k.KeepLog != nil {
153-
kvs.Insert("Keep_Log", fmt.Sprint(*k.KeepLog))
154-
}
155-
if k.TLSDebug != nil {
156-
kvs.Insert("tls.debug", fmt.Sprint(*k.TLSDebug))
157-
}
158-
if k.TLSVerify != nil {
159-
kvs.Insert("tls.verify", fmt.Sprint(*k.TLSVerify))
160-
}
161-
if k.UseJournal != nil {
162-
kvs.Insert("Use_Journal", fmt.Sprint(*k.UseJournal))
163-
}
164-
if k.CacheUseDockerId != nil {
165-
kvs.Insert("Cache_Use_Docker_Id", fmt.Sprint(*k.CacheUseDockerId))
166-
}
167-
if k.RegexParser != "" {
168-
kvs.Insert("Regex_Parser", k.RegexParser)
169-
}
170-
if k.K8SLoggingParser != nil {
171-
kvs.Insert("K8S-Logging.Parser", fmt.Sprint(*k.K8SLoggingParser))
172-
}
173-
if k.K8SLoggingExclude != nil {
174-
kvs.Insert("K8S-Logging.Exclude", fmt.Sprint(*k.K8SLoggingExclude))
175-
}
176-
if k.Labels != nil {
177-
kvs.Insert("Labels", fmt.Sprint(*k.Labels))
178-
}
179-
if k.Annotations != nil {
180-
kvs.Insert("Annotations", fmt.Sprint(*k.Annotations))
181-
}
182-
if k.KubeMetaPreloadCacheDir != "" {
183-
kvs.Insert("Kube_meta_preload_cache_dir", k.KubeMetaPreloadCacheDir)
184-
}
185-
if k.DummyMeta != nil {
186-
kvs.Insert("Dummy_Meta", fmt.Sprint(*k.DummyMeta))
187-
}
188-
if k.DNSRetries != nil {
189-
kvs.Insert("DNS_Retries", fmt.Sprint(*k.DNSRetries))
190-
}
191-
if k.DNSWaitTime != nil {
192-
kvs.Insert("DNS_Wait_Time", fmt.Sprint(*k.DNSWaitTime))
193-
}
194-
if k.UseKubelet != nil {
195-
kvs.Insert("Use_Kubelet", fmt.Sprint(*k.UseKubelet))
196-
}
197-
if k.KubeletPort != nil {
198-
kvs.Insert("Kubelet_Port", fmt.Sprint(*k.KubeletPort))
199-
}
200-
if k.KubeletHost != "" {
201-
kvs.Insert("Kubelet_Host", k.KubeletHost)
202-
}
203-
if k.KubeMetaCacheTTL != "" {
204-
kvs.Insert("Kube_Meta_Cache_TTL", k.KubeMetaCacheTTL)
205-
}
206-
if k.KubeTokenTTL != "" {
207-
kvs.Insert("Kube_Token_TTL", k.KubeTokenTTL)
208-
}
209-
if k.KubeTokenCommand != "" {
210-
kvs.Insert("Kube_Token_Command", fmt.Sprint(k.KubeTokenCommand))
211-
}
212-
if k.KubeMetaNamespaceCacheTTL != nil {
213-
kvs.Insert("Kube_Meta_Namespace_Cache_TTL", fmt.Sprint(*k.KubeMetaNamespaceCacheTTL))
214-
}
215-
if k.NamespaceLabels != nil {
216-
kvs.Insert("Namespace_Labels", fmt.Sprint(*k.NamespaceLabels))
217-
}
218-
if k.NamespaceAnnotations != nil {
219-
kvs.Insert("Namespace_Annotations", fmt.Sprint(*k.NamespaceAnnotations))
220-
}
221-
if k.NamespaceMetadataOnly != nil {
222-
kvs.Insert("Namespace_Metadata_Only", fmt.Sprint(*k.NamespaceMetadataOnly))
223-
}
224-
if k.OwnerReferences != nil {
225-
kvs.Insert("Owner_References", fmt.Sprint(*k.OwnerReferences))
226-
}
227-
if k.UseTagForMeta != nil {
228-
kvs.Insert("Use_Tag_For_Meta", fmt.Sprint(*k.UseTagForMeta))
229-
}
122+
123+
plugins.InsertKVString(kvs, "Buffer_Size", k.BufferSize)
124+
plugins.InsertKVString(kvs, "Kube_URL", k.KubeURL)
125+
plugins.InsertKVString(kvs, "Kube_CA_File", k.KubeCAFile)
126+
plugins.InsertKVString(kvs, "Kube_CA_Path", k.KubeCAPath)
127+
plugins.InsertKVString(kvs, "Kube_Token_File", k.KubeTokenFile)
128+
plugins.InsertKVString(kvs, "Kube_Tag_Prefix", k.KubeTagPrefix)
129+
plugins.InsertKVString(kvs, "Merge_Log_Key", k.MergeLogKey)
130+
plugins.InsertKVString(kvs, "Merge_Parser", k.MergeParser)
131+
plugins.InsertKVString(kvs, "Regex_Parser", k.RegexParser)
132+
plugins.InsertKVString(kvs, "Kube_meta_preload_cache_dir", k.KubeMetaPreloadCacheDir)
133+
plugins.InsertKVString(kvs, "Kubelet_Host", k.KubeletHost)
134+
plugins.InsertKVString(kvs, "Kube_Token_TTL", k.KubeTokenTTL)
135+
plugins.InsertKVString(kvs, "Kube_Token_Command", k.KubeTokenCommand)
136+
137+
plugins.InsertKVField(kvs, "Merge_Log", k.MergeLog)
138+
plugins.InsertKVField(kvs, "Merge_Log_Trim", k.MergeLogTrim)
139+
plugins.InsertKVField(kvs, "Keep_Log", k.KeepLog)
140+
plugins.InsertKVField(kvs, "tls.debug", k.TLSDebug)
141+
plugins.InsertKVField(kvs, "tls.verify", k.TLSVerify)
142+
plugins.InsertKVField(kvs, "Use_Journal", k.UseJournal)
143+
plugins.InsertKVField(kvs, "Cache_Use_Docker_Id", k.CacheUseDockerId)
144+
plugins.InsertKVField(kvs, "K8S-Logging.Parser", k.K8SLoggingParser)
145+
plugins.InsertKVField(kvs, "K8S-Logging.Exclude", k.K8SLoggingExclude)
146+
plugins.InsertKVField(kvs, "Labels", k.Labels)
147+
plugins.InsertKVField(kvs, "Annotations", k.Annotations)
148+
plugins.InsertKVField(kvs, "Dummy_Meta", k.DummyMeta)
149+
plugins.InsertKVField(kvs, "DNS_Retries", k.DNSRetries)
150+
plugins.InsertKVField(kvs, "DNS_Wait_Time", k.DNSWaitTime)
151+
plugins.InsertKVField(kvs, "Use_Kubelet", k.UseKubelet)
152+
plugins.InsertKVField(kvs, "Kubelet_Port", k.KubeletPort)
153+
plugins.InsertKVString(kvs, "Kube_Meta_Cache_TTL", k.KubeMetaCacheTTL)
154+
plugins.InsertKVField(kvs, "Kube_Meta_Namespace_Cache_TTL", k.KubeMetaNamespaceCacheTTL)
155+
plugins.InsertKVField(kvs, "Namespace_Labels", k.NamespaceLabels)
156+
plugins.InsertKVField(kvs, "Namespace_Annotations", k.NamespaceAnnotations)
157+
plugins.InsertKVField(kvs, "Namespace_Metadata_Only", k.NamespaceMetadataOnly)
158+
plugins.InsertKVField(kvs, "Owner_References", k.OwnerReferences)
159+
plugins.InsertKVField(kvs, "Use_Tag_For_Meta", k.UseTagForMeta)
160+
230161
return kvs, nil
231162
}
232163

apis/fluentbit/v1alpha2/plugins/input/collectd.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package input
22

33
import (
4-
"fmt"
5-
64
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
75
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
86
)
@@ -29,14 +27,11 @@ func (*Collectd) Name() string {
2927
// implement Section() method
3028
func (c *Collectd) Params(_ plugins.SecretLoader) (*params.KVs, error) {
3129
kvs := params.NewKVs()
32-
if c.Listen != "" {
33-
kvs.Insert("Listen", c.Listen)
34-
}
35-
if c.Port != nil {
36-
kvs.Insert("Port", fmt.Sprint(*c.Port))
37-
}
38-
if c.TypesDB != "" {
39-
kvs.Insert("TypesDB", c.TypesDB)
40-
}
30+
31+
plugins.InsertKVString(kvs, "Listen", c.Listen)
32+
plugins.InsertKVString(kvs, "TypesDB", c.TypesDB)
33+
34+
plugins.InsertKVField(kvs, "Port", c.Port)
35+
4136
return kvs, nil
4237
}

apis/fluentbit/v1alpha2/plugins/input/dummy_types.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package input
22

33
import (
4-
"fmt"
5-
64
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
75
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
86
)
@@ -30,17 +28,12 @@ func (*Dummy) Name() string {
3028
// implement Section() method
3129
func (d *Dummy) Params(_ plugins.SecretLoader) (*params.KVs, error) {
3230
kvs := params.NewKVs()
33-
if d.Tag != "" {
34-
kvs.Insert("Tag", d.Tag)
35-
}
36-
if d.Dummy != "" {
37-
kvs.Insert("Dummy", d.Dummy)
38-
}
39-
if d.Rate != nil {
40-
kvs.Insert("Rate", fmt.Sprint(*d.Rate))
41-
}
42-
if d.Samples != nil {
43-
kvs.Insert("Samples", fmt.Sprint(*d.Samples))
44-
}
31+
32+
plugins.InsertKVString(kvs, "Tag", d.Tag)
33+
plugins.InsertKVString(kvs, "Dummy", d.Dummy)
34+
35+
plugins.InsertKVField(kvs, "Rate", d.Rate)
36+
plugins.InsertKVField(kvs, "Samples", d.Samples)
37+
4538
return kvs, nil
4639
}

apis/fluentbit/v1alpha2/plugins/input/exec_wasi_types.go

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package input
22

33
import (
4-
"fmt"
5-
64
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
75
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
86
)
@@ -42,32 +40,19 @@ func (*ExecWasi) Name() string {
4240
func (w *ExecWasi) Params(_ plugins.SecretLoader) (*params.KVs, error) {
4341
kvs := params.NewKVs()
4442

45-
if w.WASIPath != "" {
46-
kvs.Insert("WASI_Path", w.WASIPath)
47-
}
48-
if w.Parser != "" {
49-
kvs.Insert("Parser", w.Parser)
50-
}
43+
plugins.InsertKVString(kvs, "WASI_Path", w.WASIPath)
44+
plugins.InsertKVString(kvs, "Parser", w.Parser)
45+
plugins.InsertKVString(kvs, "Wasm_Heap_Size", w.WasmHeapSize)
46+
plugins.InsertKVString(kvs, "Wasm_Stack_Size", w.WasmStackSize)
47+
plugins.InsertKVString(kvs, "Buf_Size", w.BufSize)
48+
49+
plugins.InsertKVField(kvs, "Interval_Sec", w.IntervalSec)
50+
plugins.InsertKVField(kvs, "Interval_NSec", w.IntervalNSec)
51+
plugins.InsertKVField(kvs, "Threaded", w.Threaded)
52+
5153
for _, p := range w.AccessiblePaths {
5254
kvs.Insert("Accessible_Paths", p)
5355
}
54-
if w.IntervalSec != nil {
55-
kvs.Insert("Interval_Sec", fmt.Sprint(*w.IntervalSec))
56-
}
57-
if w.IntervalNSec != nil {
58-
kvs.Insert("Interval_NSec", fmt.Sprint(*w.IntervalNSec))
59-
}
60-
if w.WasmHeapSize != "" {
61-
kvs.Insert("Wasm_Heap_Size", w.WasmHeapSize)
62-
}
63-
if w.WasmStackSize != "" {
64-
kvs.Insert("Wasm_Stack_Size", w.WasmStackSize)
65-
}
66-
if w.BufSize != "" {
67-
kvs.Insert("Buf_Size", w.BufSize)
68-
}
69-
if w.Threaded != nil {
70-
kvs.Insert("Threaded", fmt.Sprint(*w.Threaded))
71-
}
56+
7257
return kvs, nil
7358
}

apis/fluentbit/v1alpha2/plugins/input/fluentbit_metrics_types.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package input
22

33
import (
4-
"fmt"
5-
64
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
75
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
86
)
@@ -30,14 +28,11 @@ func (*FluentbitMetrics) Name() string {
3028

3129
func (f *FluentbitMetrics) Params(_ plugins.SecretLoader) (*params.KVs, error) {
3230
kvs := params.NewKVs()
33-
if f.Tag != "" {
34-
kvs.Insert("Tag", f.Tag)
35-
}
36-
if f.ScrapeInterval != "" {
37-
kvs.Insert("scrape_interval", f.ScrapeInterval)
38-
}
39-
if f.ScrapeOnStart != nil {
40-
kvs.Insert("scrape_on_start", fmt.Sprint(*f.ScrapeOnStart))
41-
}
31+
32+
plugins.InsertKVString(kvs, "Tag", f.Tag)
33+
plugins.InsertKVString(kvs, "scrape_interval", f.ScrapeInterval)
34+
35+
plugins.InsertKVField(kvs, "scrape_on_start", f.ScrapeOnStart)
36+
4237
return kvs, nil
4338
}

apis/fluentbit/v1alpha2/plugins/input/forward.go

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package input
22

33
import (
4-
"fmt"
5-
64
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
75
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
86
)
@@ -46,32 +44,16 @@ func (*Forward) Name() string {
4644
// Params implement Section() method
4745
func (f *Forward) Params(_ plugins.SecretLoader) (*params.KVs, error) {
4846
kvs := params.NewKVs()
49-
if f.Port != nil {
50-
kvs.Insert("Port", fmt.Sprint(*f.Port))
51-
}
52-
if f.Listen != "" {
53-
kvs.Insert("Listen", f.Listen)
54-
}
55-
if f.Tag != "" {
56-
kvs.Insert("Tag", f.Tag)
57-
}
58-
if f.TagPrefix != "" {
59-
kvs.Insert("Tag_Prefix", f.TagPrefix)
60-
}
61-
if f.UnixPath != "" {
62-
kvs.Insert("Unix_Path", f.UnixPath)
63-
}
64-
if f.UnixPerm != "" {
65-
kvs.Insert("Unix_Perm", f.UnixPerm)
66-
}
67-
if f.BufferChunkSize != "" {
68-
kvs.Insert("Buffer_Chunk_Size", f.BufferChunkSize)
69-
}
70-
if f.BufferMaxSize != "" {
71-
kvs.Insert("Buffer_Max_Size", f.BufferMaxSize)
72-
}
73-
if f.Threaded != "" {
74-
kvs.Insert("threaded", f.Threaded)
75-
}
47+
48+
plugins.InsertKVField(kvs, "Port", f.Port)
49+
plugins.InsertKVString(kvs, "Listen", f.Listen)
50+
plugins.InsertKVString(kvs, "Tag", f.Tag)
51+
plugins.InsertKVString(kvs, "Tag_Prefix", f.TagPrefix)
52+
plugins.InsertKVString(kvs, "Unix_Path", f.UnixPath)
53+
plugins.InsertKVString(kvs, "Unix_Perm", f.UnixPerm)
54+
plugins.InsertKVString(kvs, "Buffer_Chunk_Size", f.BufferChunkSize)
55+
plugins.InsertKVString(kvs, "Buffer_Max_Size", f.BufferMaxSize)
56+
plugins.InsertKVString(kvs, "threaded", f.Threaded)
57+
7658
return kvs, nil
7759
}

0 commit comments

Comments
 (0)