Skip to content

Commit e50d5c7

Browse files
committed
Replace ptr methods with single generic function
1 parent 07d6242 commit e50d5c7

11 files changed

+138
-163
lines changed

apis/fluentbit/v1alpha2/clusterfilter_types_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ func TestClusterFilterList_Load(t *testing.T) {
135135
KubeURL: "http://127.0.0.1:6443",
136136
KubeCAFile: "root.ca",
137137
KubeCAPath: "/root/.kube/crt",
138-
Labels: ptrBool(true),
139-
Annotations: ptrBool(true),
140-
DNSWaitTime: ptrInt32(30),
141-
UseKubelet: ptrBool(true),
142-
KubeletPort: ptrInt32(10000),
138+
Labels: ptr(true),
139+
Annotations: ptr(true),
140+
DNSWaitTime: ptr[int32](30),
141+
UseKubelet: ptr(true),
142+
KubeletPort: ptr[int32](10000),
143143
KubeMetaCacheTTL: "60s",
144144
},
145145
},
@@ -163,8 +163,8 @@ func TestClusterFilterList_Load(t *testing.T) {
163163
CommonParams: plugins.CommonParams{
164164
Alias: "throttle.application-xy",
165165
},
166-
Rate: ptrInt64(200),
167-
Window: ptrInt64(300),
166+
Rate: ptr[int64](200),
167+
Window: ptr[int64](300),
168168
Interval: "1s",
169169
},
170170
},
@@ -494,11 +494,11 @@ func TestClusterFilterList_Load_As_Yaml(t *testing.T) {
494494
KubeURL: "http://127.0.0.1:6443",
495495
KubeCAFile: "root.ca",
496496
KubeCAPath: "/root/.kube/crt",
497-
Labels: ptrBool(true),
498-
Annotations: ptrBool(true),
499-
DNSWaitTime: ptrInt32(30),
500-
UseKubelet: ptrBool(true),
501-
KubeletPort: ptrInt32(10000),
497+
Labels: ptr(true),
498+
Annotations: ptr(true),
499+
DNSWaitTime: ptr[int32](30),
500+
UseKubelet: ptr(true),
501+
KubeletPort: ptr[int32](10000),
502502
KubeMetaCacheTTL: "60s",
503503
},
504504
},
@@ -522,8 +522,8 @@ func TestClusterFilterList_Load_As_Yaml(t *testing.T) {
522522
CommonParams: plugins.CommonParams{
523523
Alias: "throttle.application-xy",
524524
},
525-
Rate: ptrInt64(200),
526-
Window: ptrInt64(300),
525+
Rate: ptr[int64](200),
526+
Window: ptr[int64](300),
527527
Interval: "1s",
528528
},
529529
},

apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go

Lines changed: 50 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ pipeline:
386386
cfg = ClusterFluentBitConfig{
387387
Spec: FluentBitConfigSpec{
388388
Service: &Service{
389-
Daemon: ptrBool(false),
390-
FlushSeconds: ptrFloat64(1),
391-
GraceSeconds: ptrInt64(30),
392-
HttpServer: ptrBool(true),
389+
Daemon: ptr(false),
390+
FlushSeconds: ptr[float64](1),
391+
GraceSeconds: ptr[int64](30),
392+
HttpServer: ptr(true),
393393
LogLevel: "info",
394394
ParsersFile: "parsers.conf",
395395
},
@@ -402,7 +402,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
402402

403403
sl := plugins.NewSecretLoader(nil, "testnamespace")
404404

405-
disableInotifyWatcher := ptrBool(true)
405+
disableInotifyWatcher := ptr(true)
406406

407407
inputObj := &ClusterInput{
408408
TypeMeta: metav1.TypeMeta{
@@ -420,10 +420,10 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
420420
Tag: "logs.foo.bar",
421421
Path: "/logs/containers/apps0",
422422
ExcludePath: "/logs/containers/exclude_path",
423-
SkipLongLines: ptrBool(true),
423+
SkipLongLines: ptr(true),
424424
IgnoreOlder: "5m",
425425
MemBufLimit: "5MB",
426-
RefreshIntervalSeconds: ptrInt64(10),
426+
RefreshIntervalSeconds: ptr[int64](10),
427427
DB: "/fluent-bit/tail/pos.db",
428428
},
429429
},
@@ -507,10 +507,10 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
507507
Match: "logs.foo.bar",
508508
Syslog: &output.Syslog{
509509
Host: "example.com",
510-
Port: ptrInt32(int32(3300)),
510+
Port: ptr[int32](3300),
511511
Mode: "tls",
512512
TLS: &plugins.TLS{
513-
Verify: ptrBool(true),
513+
Verify: ptr(true),
514514
},
515515
SyslogMessageKey: "log",
516516
SyslogHostnameKey: "do_app_name",
@@ -519,12 +519,12 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
519519
},
520520
}
521521

522-
headers := map[string]string{}
523-
524-
headers["Authorization"] = authorization
525-
headers["X-Log-Header-App-Name"] = xLogHeaderAppName
526-
headers["X-Log-Header-0"] = xLogHeader0
527-
headers["X-Log-Header-App-ID"] = xLogHeaderAppID
522+
headers := map[string]string{
523+
"Authorization": authorization,
524+
"X-Log-Header-App-Name": xLogHeaderAppName,
525+
"X-Log-Header-0": xLogHeader0,
526+
"X-Log-Header-App-ID": xLogHeaderAppID,
527+
}
528528

529529
httpOutput := ClusterOutput{
530530
TypeMeta: metav1.TypeMeta{
@@ -540,14 +540,14 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
540540
Match: "logs.foo.bar",
541541
HTTP: &output.HTTP{
542542
Host: "https://example2.com",
543-
Port: ptrInt32(int32(433)),
543+
Port: ptr[int32](433),
544544
Uri: "/logs",
545545
Headers: headers,
546546
Format: "json_lines",
547547
JsonDateKey: "timestamp",
548548
JsonDateFormat: "iso8601",
549549
TLS: &plugins.TLS{
550-
Verify: ptrBool(true),
550+
Verify: ptr(true),
551551
},
552552
},
553553
},
@@ -567,7 +567,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
567567
Match: "*",
568568
OpenSearch: &output.OpenSearch{
569569
Host: "https://example2.com",
570-
Port: ptrInt32(int32(9200)),
570+
Port: ptr[int32](9200),
571571
Index: "my_index",
572572
Type: "my_type",
573573
},
@@ -588,7 +588,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
588588
Match: "*",
589589
Elasticsearch: &output.Elasticsearch{
590590
Host: "https://example2.com",
591-
Port: ptrInt32(int32(9200)),
591+
Port: ptr[int32](9200),
592592
Index: "my_index",
593593
Type: "my_type",
594594
WriteOperation: "upsert",
@@ -634,7 +634,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
634634

635635
sl := plugins.NewSecretLoader(nil, "testnamespace")
636636

637-
disableInotifyWatcher := ptrBool(true)
637+
disableInotifyWatcher := ptr(true)
638638

639639
inputObj := &ClusterInput{
640640
TypeMeta: metav1.TypeMeta{
@@ -652,10 +652,10 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
652652
Tag: "logs.foo.bar",
653653
Path: "/logs/containers/apps0",
654654
ExcludePath: "/logs/containers/exclude_path",
655-
SkipLongLines: ptrBool(true),
655+
SkipLongLines: ptr(true),
656656
IgnoreOlder: "5m",
657657
MemBufLimit: "5MB",
658-
RefreshIntervalSeconds: ptrInt64(10),
658+
RefreshIntervalSeconds: ptr[int64](10),
659659
DB: "/fluent-bit/tail/pos.db",
660660
},
661661
},
@@ -739,10 +739,10 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
739739
Match: "logs.foo.bar",
740740
Syslog: &output.Syslog{
741741
Host: "example.com",
742-
Port: ptrInt32(int32(3300)),
742+
Port: ptr[int32](3300),
743743
Mode: "tls",
744744
TLS: &plugins.TLS{
745-
Verify: ptrBool(true),
745+
Verify: ptr(true),
746746
},
747747
SyslogMessageKey: "log",
748748
SyslogHostnameKey: "do_app_name",
@@ -751,12 +751,12 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
751751
},
752752
}
753753

754-
headers := map[string]string{}
755-
756-
headers["Authorization"] = authorization
757-
headers["X-Log-Header-App-Name"] = xLogHeaderAppName
758-
headers["X-Log-Header-0"] = xLogHeader0
759-
headers["X-Log-Header-App-ID"] = xLogHeaderAppID
754+
headers := map[string]string{
755+
"Authorization": authorization,
756+
"X-Log-Header-App-Name": xLogHeaderAppName,
757+
"X-Log-Header-0": xLogHeader0,
758+
"X-Log-Header-App-ID": xLogHeaderAppID,
759+
}
760760

761761
httpOutput := ClusterOutput{
762762
TypeMeta: metav1.TypeMeta{
@@ -772,14 +772,14 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
772772
Match: "logs.foo.bar",
773773
HTTP: &output.HTTP{
774774
Host: "https://example2.com",
775-
Port: ptrInt32(int32(433)),
775+
Port: ptr[int32](433),
776776
Uri: "/logs",
777777
Headers: headers,
778778
Format: "json_lines",
779779
JsonDateKey: "timestamp",
780780
JsonDateFormat: "iso8601",
781781
TLS: &plugins.TLS{
782-
Verify: ptrBool(true),
782+
Verify: ptr(true),
783783
},
784784
},
785785
},
@@ -799,7 +799,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
799799
Match: "*",
800800
OpenSearch: &output.OpenSearch{
801801
Host: "https://example2.com",
802-
Port: ptrInt32(int32(9200)),
802+
Port: ptr[int32](9200),
803803
Index: "my_index",
804804
Type: "my_type",
805805
},
@@ -820,7 +820,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
820820
Match: "*",
821821
Elasticsearch: &output.Elasticsearch{
822822
Host: "https://example2.com",
823-
Port: ptrInt32(int32(9200)),
823+
Port: ptr[int32](9200),
824824
Index: "my_index",
825825
Type: "my_type",
826826
WriteOperation: "upsert",
@@ -908,10 +908,10 @@ func TestRenderMainConfigK8s(t *testing.T) {
908908
Tail: &input.Tail{
909909
Tag: "kube.*",
910910
Path: "/var/log/containers/*.log",
911-
SkipLongLines: ptrBool(true),
911+
SkipLongLines: ptr(true),
912912
IgnoreOlder: "5m",
913913
MemBufLimit: "5MB",
914-
RefreshIntervalSeconds: ptrInt64(10),
914+
RefreshIntervalSeconds: ptr[int64](10),
915915
DB: "/fluent-bit/tail/pos.db",
916916
},
917917
},
@@ -942,7 +942,7 @@ func TestRenderMainConfigK8s(t *testing.T) {
942942
Parser: &filter.Parser{
943943
KeyName: "log",
944944
Parser: "bar",
945-
ReserveData: ptrBool(true),
945+
ReserveData: ptr(true),
946946
},
947947
},
948948
},
@@ -967,7 +967,7 @@ func TestRenderMainConfigK8s(t *testing.T) {
967967
Match: "kube.*",
968968
OpenSearch: &output.OpenSearch{
969969
Host: "foo.bar",
970-
Port: ptrInt32(9200),
970+
Port: ptr[int32](9200),
971971
Index: "foo-index",
972972
},
973973
},
@@ -987,7 +987,7 @@ func TestRenderMainConfigK8s(t *testing.T) {
987987
Match: "kube.*",
988988
Elasticsearch: &output.Elasticsearch{
989989
Host: "foo.bar",
990-
Port: ptrInt32(9200),
990+
Port: ptr[int32](9200),
991991
Index: "foo-index",
992992
WriteOperation: "update",
993993
},
@@ -1031,10 +1031,10 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
10311031
Tail: &input.Tail{
10321032
Tag: "kube.*",
10331033
Path: "/var/log/containers/*.log",
1034-
SkipLongLines: ptrBool(true),
1034+
SkipLongLines: ptr(true),
10351035
IgnoreOlder: "5m",
10361036
MemBufLimit: "5MB",
1037-
RefreshIntervalSeconds: ptrInt64(10),
1037+
RefreshIntervalSeconds: ptr[int64](10),
10381038
DB: "/fluent-bit/tail/pos.db",
10391039
},
10401040
},
@@ -1059,7 +1059,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
10591059
{Parser: &filter.Parser{
10601060
KeyName: "log",
10611061
Parser: "test",
1062-
ReserveData: ptrBool(true),
1062+
ReserveData: ptr(true),
10631063
}},
10641064
},
10651065
},
@@ -1081,7 +1081,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
10811081
Match: "kube.*",
10821082
Elasticsearch: &output.Elasticsearch{
10831083
Host: "foo.bar",
1084-
Port: ptrInt32(9200),
1084+
Port: ptr[int32](9200),
10851085
Index: "foo-index",
10861086
},
10871087
},
@@ -1105,7 +1105,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
11051105
Parser: &filter.Parser{
11061106
KeyName: "log",
11071107
Parser: "bar",
1108-
ReserveData: ptrBool(true),
1108+
ReserveData: ptr(true),
11091109
},
11101110
},
11111111
},
@@ -1130,7 +1130,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
11301130
Match: "kube.*",
11311131
OpenSearch: &output.OpenSearch{
11321132
Host: "foo.bar",
1133-
Port: ptrInt32(9200),
1133+
Port: ptr[int32](9200),
11341134
Index: "foo-index",
11351135
},
11361136
},
@@ -1150,7 +1150,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
11501150
Match: "kube.*",
11511151
Elasticsearch: &output.Elasticsearch{
11521152
Host: "foo.bar",
1153-
Port: ptrInt32(9200),
1153+
Port: ptr[int32](9200),
11541154
Index: "foo-index",
11551155
WriteOperation: "update",
11561156
},
@@ -1178,10 +1178,10 @@ func TestClusterFluentBitConfig_RenderMainConfig_WithParsersFiles(t *testing.T)
11781178
cfbc := ClusterFluentBitConfig{
11791179
Spec: FluentBitConfigSpec{
11801180
Service: &Service{
1181-
Daemon: ptrBool(false),
1182-
FlushSeconds: ptrFloat64(1),
1183-
GraceSeconds: ptrInt64(30),
1184-
HttpServer: ptrBool(true),
1181+
Daemon: ptr(false),
1182+
FlushSeconds: ptr[float64](1),
1183+
GraceSeconds: ptr[int64](30),
1184+
HttpServer: ptr(true),
11851185
LogLevel: "info",
11861186
ParsersFiles: []string{"parsers.conf", "parsers_multiline.conf"},
11871187
},
@@ -1371,19 +1371,3 @@ func TestClusterFluentBitConfig_RenderMultilineParserConfig(t *testing.T) {
13711371
g.Expect(err).NotTo(HaveOccurred())
13721372
g.Expect(config).To(Equal(expectedMultilineParsers))
13731373
}
1374-
1375-
func ptrBool(v bool) *bool {
1376-
return &v
1377-
}
1378-
1379-
func ptrInt64(v int64) *int64 {
1380-
return &v
1381-
}
1382-
1383-
func ptrInt32(v int32) *int32 {
1384-
return &v
1385-
}
1386-
1387-
func ptrFloat64(v float64) *float64 {
1388-
return &v
1389-
}

0 commit comments

Comments
 (0)