Skip to content

Commit a0cc44a

Browse files
authored
tici: fix lost common prefix when apply config (#6746)
1 parent 339e333 commit a0cc44a

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

pkg/manager/member/tici_member_manager.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,11 @@ access-key = "%s"
715715
secret-key = "%s"
716716
use-path-style = %t
717717
bucket = "%s"
718+
prefix = "%s"
718719
719720
[shard]
720721
max-size = "128MB"
721-
`, tidbHost, tidbPort, pdAddr, s3.Endpoint, s3.Region, s3.AccessKey, s3.SecretKey, s3.UsePathStyle, s3.Bucket)
722+
`, tidbHost, tidbPort, pdAddr, s3.Endpoint, s3.Region, s3.AccessKey, s3.SecretKey, s3.UsePathStyle, s3.Bucket, s3.Prefix)
722723
if tc.Spec.TiCI != nil && tc.Spec.TiCI.Meta != nil {
723724
return appendTiCICustomConfig(baseConfig, tc.Spec.TiCI.Meta.Config)
724725
}
@@ -742,7 +743,8 @@ access-key = "%s"
742743
secret-key = "%s"
743744
use-path-style = %t
744745
bucket = "%s"
745-
`, pdAddr, s3.Endpoint, s3.Region, s3.AccessKey, s3.SecretKey, s3.UsePathStyle, s3.Bucket)
746+
prefix = "%s"
747+
`, pdAddr, s3.Endpoint, s3.Region, s3.AccessKey, s3.SecretKey, s3.UsePathStyle, s3.Bucket, s3.Prefix)
746748
if tc.Spec.TiCI != nil && tc.Spec.TiCI.Worker != nil {
747749
return appendTiCICustomConfig(baseConfig, tc.Spec.TiCI.Worker.Config)
748750
}

pkg/manager/member/tici_member_manager_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ data-dir = "/data/tici-meta"`
8181
}
8282
}
8383

84+
func TestBuildTiCIConfigIncludesS3Prefix(t *testing.T) {
85+
tc := newTidbClusterForTiCIConfig()
86+
tc.Spec.TiCI.S3.Prefix = "custom_prefix"
87+
88+
workerCfg, err := buildTiCIWorkerConfig(tc)
89+
if err != nil {
90+
t.Fatalf("build worker config failed: %v", err)
91+
}
92+
assertS3Prefix(t, workerCfg, "worker", "custom_prefix")
93+
94+
metaCfg, err := buildTiCIMetaConfig(tc)
95+
if err != nil {
96+
t.Fatalf("build meta config failed: %v", err)
97+
}
98+
assertS3Prefix(t, metaCfg, "meta", "custom_prefix")
99+
}
100+
101+
func assertS3Prefix(t *testing.T, cfg, component, expected string) {
102+
t.Helper()
103+
wrapper := tcconfig.New(map[string]interface{}{})
104+
if err := wrapper.UnmarshalTOML([]byte(cfg)); err != nil {
105+
t.Fatalf("%s config should be valid TOML, got err: %v, config: %s", component, err, cfg)
106+
}
107+
prefix := wrapper.Get("s3.prefix")
108+
if prefix == nil || prefix.MustString() != expected {
109+
t.Fatalf("%s config should include s3.prefix=%q, got: %s", component, expected, cfg)
110+
}
111+
}
112+
84113
func TestAppendTiCICustomConfig(t *testing.T) {
85114
base := "[server]\npd-addr = \"x\"\n"
86115

0 commit comments

Comments
 (0)