Skip to content

Commit 1bae3d9

Browse files
authored
refactor: switch to reusable pointer conversion method in utils package (#1749) (#1750)
Signed-off-by: Leon Low <[email protected]>
1 parent fe81b42 commit 1bae3d9

11 files changed

+126
-121
lines changed

apis/fluentbit/v1alpha2/clusterfilter_types_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
77
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/filter"
8+
"github.com/fluent/fluent-operator/v3/pkg/utils"
89
. "github.com/onsi/gomega"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
)
@@ -135,11 +136,11 @@ func TestClusterFilterList_Load(t *testing.T) {
135136
KubeURL: "http://127.0.0.1:6443",
136137
KubeCAFile: "root.ca",
137138
KubeCAPath: "/root/.kube/crt",
138-
Labels: ptr(true),
139-
Annotations: ptr(true),
140-
DNSWaitTime: ptr[int32](30),
141-
UseKubelet: ptr(true),
142-
KubeletPort: ptr[int32](10000),
139+
Labels: utils.ToPtr(true),
140+
Annotations: utils.ToPtr(true),
141+
DNSWaitTime: utils.ToPtr[int32](30),
142+
UseKubelet: utils.ToPtr(true),
143+
KubeletPort: utils.ToPtr[int32](10000),
143144
KubeMetaCacheTTL: "60s",
144145
},
145146
},
@@ -163,8 +164,8 @@ func TestClusterFilterList_Load(t *testing.T) {
163164
CommonParams: plugins.CommonParams{
164165
Alias: "throttle.application-xy",
165166
},
166-
Rate: ptr[int64](200),
167-
Window: ptr[int64](300),
167+
Rate: utils.ToPtr[int64](200),
168+
Window: utils.ToPtr[int64](300),
168169
Interval: "1s",
169170
},
170171
},
@@ -494,11 +495,11 @@ func TestClusterFilterList_Load_As_Yaml(t *testing.T) {
494495
KubeURL: "http://127.0.0.1:6443",
495496
KubeCAFile: "root.ca",
496497
KubeCAPath: "/root/.kube/crt",
497-
Labels: ptr(true),
498-
Annotations: ptr(true),
499-
DNSWaitTime: ptr[int32](30),
500-
UseKubelet: ptr(true),
501-
KubeletPort: ptr[int32](10000),
498+
Labels: utils.ToPtr(true),
499+
Annotations: utils.ToPtr(true),
500+
DNSWaitTime: utils.ToPtr[int32](30),
501+
UseKubelet: utils.ToPtr(true),
502+
KubeletPort: utils.ToPtr[int32](10000),
502503
KubeMetaCacheTTL: "60s",
503504
},
504505
},
@@ -522,8 +523,8 @@ func TestClusterFilterList_Load_As_Yaml(t *testing.T) {
522523
CommonParams: plugins.CommonParams{
523524
Alias: "throttle.application-xy",
524525
},
525-
Rate: ptr[int64](200),
526-
Window: ptr[int64](300),
526+
Rate: utils.ToPtr[int64](200),
527+
Window: utils.ToPtr[int64](300),
527528
Interval: "1s",
528529
},
529530
},

apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/multilineparser"
1515
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/output"
1616
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/parser"
17+
"github.com/fluent/fluent-operator/v3/pkg/utils"
1718
)
1819

1920
const (
@@ -385,10 +386,10 @@ pipeline:
385386
cfg = ClusterFluentBitConfig{
386387
Spec: FluentBitConfigSpec{
387388
Service: &Service{
388-
Daemon: ptr(false),
389-
FlushSeconds: ptr[float64](1),
390-
GraceSeconds: ptr[int64](30),
391-
HttpServer: ptr(true),
389+
Daemon: utils.ToPtr(false),
390+
FlushSeconds: utils.ToPtr[float64](1),
391+
GraceSeconds: utils.ToPtr[int64](30),
392+
HttpServer: utils.ToPtr(true),
392393
LogLevel: "info",
393394
ParsersFile: "parsers.conf",
394395
},
@@ -401,7 +402,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
401402

402403
sl := plugins.NewSecretLoader(nil, "testnamespace")
403404

404-
disableInotifyWatcher := ptr(true)
405+
disableInotifyWatcher := utils.ToPtr(true)
405406

406407
inputObj := &ClusterInput{
407408
TypeMeta: metav1.TypeMeta{
@@ -419,10 +420,10 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
419420
Tag: "logs.foo.bar",
420421
Path: "/logs/containers/apps0",
421422
ExcludePath: "/logs/containers/exclude_path",
422-
SkipLongLines: ptr(true),
423+
SkipLongLines: utils.ToPtr(true),
423424
IgnoreOlder: "5m",
424425
MemBufLimit: "5MB",
425-
RefreshIntervalSeconds: ptr[int64](10),
426+
RefreshIntervalSeconds: utils.ToPtr[int64](10),
426427
DB: "/fluent-bit/tail/pos.db",
427428
},
428429
},
@@ -506,10 +507,10 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
506507
Match: "logs.foo.bar",
507508
Syslog: &output.Syslog{
508509
Host: "example.com",
509-
Port: ptr[int32](3300),
510+
Port: utils.ToPtr[int32](3300),
510511
Mode: "tls",
511512
TLS: &plugins.TLS{
512-
Verify: ptr(true),
513+
Verify: utils.ToPtr(true),
513514
},
514515
SyslogMessageKey: "log",
515516
SyslogHostnameKey: "do_app_name",
@@ -539,14 +540,14 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
539540
Match: "logs.foo.bar",
540541
HTTP: &output.HTTP{
541542
Host: "https://example2.com",
542-
Port: ptr[int32](433),
543+
Port: utils.ToPtr[int32](433),
543544
Uri: "/logs",
544545
Headers: headers,
545546
Format: "json_lines",
546547
JsonDateKey: "timestamp",
547548
JsonDateFormat: "iso8601",
548549
TLS: &plugins.TLS{
549-
Verify: ptr(true),
550+
Verify: utils.ToPtr(true),
550551
},
551552
},
552553
},
@@ -566,7 +567,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
566567
Match: "*",
567568
OpenSearch: &output.OpenSearch{
568569
Host: "https://example2.com",
569-
Port: ptr[int32](9200),
570+
Port: utils.ToPtr[int32](9200),
570571
Index: "my_index",
571572
Type: "my_type",
572573
},
@@ -587,7 +588,7 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {
587588
Match: "*",
588589
Elasticsearch: &output.Elasticsearch{
589590
Host: "https://example2.com",
590-
Port: ptr[int32](9200),
591+
Port: utils.ToPtr[int32](9200),
591592
Index: "my_index",
592593
Type: "my_type",
593594
WriteOperation: "upsert",
@@ -634,7 +635,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
634635

635636
sl := plugins.NewSecretLoader(nil, "testnamespace")
636637

637-
disableInotifyWatcher := ptr(true)
638+
disableInotifyWatcher := utils.ToPtr(true)
638639

639640
inputObj := &ClusterInput{
640641
TypeMeta: metav1.TypeMeta{
@@ -652,10 +653,10 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
652653
Tag: "logs.foo.bar",
653654
Path: "/logs/containers/apps0",
654655
ExcludePath: "/logs/containers/exclude_path",
655-
SkipLongLines: ptr(true),
656+
SkipLongLines: utils.ToPtr(true),
656657
IgnoreOlder: "5m",
657658
MemBufLimit: "5MB",
658-
RefreshIntervalSeconds: ptr[int64](10),
659+
RefreshIntervalSeconds: utils.ToPtr[int64](10),
659660
DB: "/fluent-bit/tail/pos.db",
660661
},
661662
},
@@ -739,10 +740,10 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
739740
Match: "logs.foo.bar",
740741
Syslog: &output.Syslog{
741742
Host: "example.com",
742-
Port: ptr[int32](3300),
743+
Port: utils.ToPtr[int32](3300),
743744
Mode: "tls",
744745
TLS: &plugins.TLS{
745-
Verify: ptr(true),
746+
Verify: utils.ToPtr(true),
746747
},
747748
SyslogMessageKey: "log",
748749
SyslogHostnameKey: "do_app_name",
@@ -772,14 +773,14 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
772773
Match: "logs.foo.bar",
773774
HTTP: &output.HTTP{
774775
Host: "https://example2.com",
775-
Port: ptr[int32](433),
776+
Port: utils.ToPtr[int32](433),
776777
Uri: "/logs",
777778
Headers: headers,
778779
Format: "json_lines",
779780
JsonDateKey: "timestamp",
780781
JsonDateFormat: "iso8601",
781782
TLS: &plugins.TLS{
782-
Verify: ptr(true),
783+
Verify: utils.ToPtr(true),
783784
},
784785
},
785786
},
@@ -799,7 +800,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
799800
Match: "*",
800801
OpenSearch: &output.OpenSearch{
801802
Host: "https://example2.com",
802-
Port: ptr[int32](9200),
803+
Port: utils.ToPtr[int32](9200),
803804
Index: "my_index",
804805
Type: "my_type",
805806
},
@@ -820,7 +821,7 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {
820821
Match: "*",
821822
Elasticsearch: &output.Elasticsearch{
822823
Host: "https://example2.com",
823-
Port: ptr[int32](9200),
824+
Port: utils.ToPtr[int32](9200),
824825
Index: "my_index",
825826
Type: "my_type",
826827
WriteOperation: "upsert",
@@ -908,10 +909,10 @@ func TestRenderMainConfigK8s(t *testing.T) {
908909
Tail: &input.Tail{
909910
Tag: "kube.*",
910911
Path: "/var/log/containers/*.log",
911-
SkipLongLines: ptr(true),
912+
SkipLongLines: utils.ToPtr(true),
912913
IgnoreOlder: "5m",
913914
MemBufLimit: "5MB",
914-
RefreshIntervalSeconds: ptr[int64](10),
915+
RefreshIntervalSeconds: utils.ToPtr[int64](10),
915916
DB: "/fluent-bit/tail/pos.db",
916917
},
917918
},
@@ -942,7 +943,7 @@ func TestRenderMainConfigK8s(t *testing.T) {
942943
Parser: &filter.Parser{
943944
KeyName: "log",
944945
Parser: "bar",
945-
ReserveData: ptr(true),
946+
ReserveData: utils.ToPtr(true),
946947
},
947948
},
948949
},
@@ -967,7 +968,7 @@ func TestRenderMainConfigK8s(t *testing.T) {
967968
Match: "kube.*",
968969
OpenSearch: &output.OpenSearch{
969970
Host: "foo.bar",
970-
Port: ptr[int32](9200),
971+
Port: utils.ToPtr[int32](9200),
971972
Index: "foo-index",
972973
},
973974
},
@@ -987,7 +988,7 @@ func TestRenderMainConfigK8s(t *testing.T) {
987988
Match: "kube.*",
988989
Elasticsearch: &output.Elasticsearch{
989990
Host: "foo.bar",
990-
Port: ptr[int32](9200),
991+
Port: utils.ToPtr[int32](9200),
991992
Index: "foo-index",
992993
WriteOperation: "update",
993994
},
@@ -1031,10 +1032,10 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
10311032
Tail: &input.Tail{
10321033
Tag: "kube.*",
10331034
Path: "/var/log/containers/*.log",
1034-
SkipLongLines: ptr(true),
1035+
SkipLongLines: utils.ToPtr(true),
10351036
IgnoreOlder: "5m",
10361037
MemBufLimit: "5MB",
1037-
RefreshIntervalSeconds: ptr[int64](10),
1038+
RefreshIntervalSeconds: utils.ToPtr[int64](10),
10381039
DB: "/fluent-bit/tail/pos.db",
10391040
},
10401041
},
@@ -1059,7 +1060,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
10591060
{Parser: &filter.Parser{
10601061
KeyName: "log",
10611062
Parser: "test",
1062-
ReserveData: ptr(true),
1063+
ReserveData: utils.ToPtr(true),
10631064
}},
10641065
},
10651066
},
@@ -1081,7 +1082,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
10811082
Match: "kube.*",
10821083
Elasticsearch: &output.Elasticsearch{
10831084
Host: "foo.bar",
1084-
Port: ptr[int32](9200),
1085+
Port: utils.ToPtr[int32](9200),
10851086
Index: "foo-index",
10861087
},
10871088
},
@@ -1105,7 +1106,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
11051106
Parser: &filter.Parser{
11061107
KeyName: "log",
11071108
Parser: "bar",
1108-
ReserveData: ptr(true),
1109+
ReserveData: utils.ToPtr(true),
11091110
},
11101111
},
11111112
},
@@ -1130,7 +1131,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
11301131
Match: "kube.*",
11311132
OpenSearch: &output.OpenSearch{
11321133
Host: "foo.bar",
1133-
Port: ptr[int32](9200),
1134+
Port: utils.ToPtr[int32](9200),
11341135
Index: "foo-index",
11351136
},
11361137
},
@@ -1150,7 +1151,7 @@ func TestRenderMainConfigK8sInYaml(t *testing.T) {
11501151
Match: "kube.*",
11511152
Elasticsearch: &output.Elasticsearch{
11521153
Host: "foo.bar",
1153-
Port: ptr[int32](9200),
1154+
Port: utils.ToPtr[int32](9200),
11541155
Index: "foo-index",
11551156
WriteOperation: "update",
11561157
},
@@ -1178,10 +1179,10 @@ func TestClusterFluentBitConfig_RenderMainConfig_WithParsersFiles(t *testing.T)
11781179
cfbc := ClusterFluentBitConfig{
11791180
Spec: FluentBitConfigSpec{
11801181
Service: &Service{
1181-
Daemon: ptr(false),
1182-
FlushSeconds: ptr[float64](1),
1183-
GraceSeconds: ptr[int64](30),
1184-
HttpServer: ptr(true),
1182+
Daemon: utils.ToPtr(false),
1183+
FlushSeconds: utils.ToPtr[float64](1),
1184+
GraceSeconds: utils.ToPtr[int64](30),
1185+
HttpServer: utils.ToPtr(true),
11851186
LogLevel: "info",
11861187
ParsersFiles: []string{"parsers.conf", "parsers_multiline.conf"},
11871188
},

0 commit comments

Comments
 (0)