Skip to content

Commit 0e9909d

Browse files
RidRisRcsuzhangxc
andauthored
br: fix overlay empty config file (#6435)
Co-authored-by: Cody (Xuecheng) Zhang <[email protected]>
1 parent 1b2fab0 commit 0e9909d

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

pkg/manager/member/tikv_member_manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,9 +1215,10 @@ func applyOverlay(cm *corev1.ConfigMap, key string, value any) error {
12151215
if err := configFileWrapper.UnmarshalTOML([]byte(configContent)); err != nil {
12161216
return fmt.Errorf("failed to unmarshal existing TiKV config: %v", err)
12171217
}
1218-
if err := configFileWrapper.Merge(overlayWrapper.GenericConfig); err != nil {
1219-
return fmt.Errorf("failed to merge overlay into existing TiKV config: %v", err)
1220-
}
1218+
}
1219+
// Always merge overlay config, regardless of whether config-file is empty
1220+
if err := configFileWrapper.Merge(overlayWrapper.GenericConfig); err != nil {
1221+
return fmt.Errorf("failed to merge overlay into existing TiKV config: %v", err)
12211222
}
12221223
overlayAppliedConfigContent, err := configFileWrapper.MarshalTOML()
12231224
if err != nil {

pkg/manager/member/tikv_member_manager_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,3 +3026,64 @@ batch-keys = 512`,
30263026
testFn(&tests[i], t)
30273027
}
30283028
}
3029+
3030+
func TestApplyOverlay(t *testing.T) {
3031+
g := NewGomegaWithT(t)
3032+
3033+
tests := []struct {
3034+
name string
3035+
configFile string
3036+
configFileOverlay string
3037+
key string
3038+
value interface{}
3039+
}{
3040+
{
3041+
name: "empty config-file with empty overlay",
3042+
configFile: "",
3043+
configFileOverlay: "",
3044+
key: "gc.ratio-threshold",
3045+
value: -1.0,
3046+
},
3047+
{
3048+
name: "existing config-file with overlay",
3049+
configFile: "[log]\n level = \"info\"\n",
3050+
configFileOverlay: "",
3051+
key: "gc.ratio-threshold",
3052+
value: -1.0,
3053+
},
3054+
{
3055+
name: "empty config-file with existing overlay",
3056+
configFile: "",
3057+
configFileOverlay: "[storage.block-cache]\ncapacity = \"1GB\"\n",
3058+
key: "gc.ratio-threshold",
3059+
value: -1.0,
3060+
},
3061+
}
3062+
3063+
for _, tt := range tests {
3064+
t.Run(tt.name, func(t *testing.T) {
3065+
cm := &corev1.ConfigMap{
3066+
Data: map[string]string{
3067+
"config-file": tt.configFile,
3068+
"config-file-overlay": tt.configFileOverlay,
3069+
},
3070+
}
3071+
3072+
err := applyOverlay(cm, tt.key, tt.value)
3073+
g.Expect(err).NotTo(HaveOccurred())
3074+
3075+
// Check that config-file now contains the merged configuration
3076+
g.Expect(cm.Data["config-file"]).NotTo(BeEmpty(), "config-file should not be empty after applying overlay")
3077+
3078+
// Parse the result to verify it contains our key
3079+
wrapper := v1alpha1.NewTiKVConfig()
3080+
err = wrapper.UnmarshalTOML([]byte(cm.Data["config-file"]))
3081+
g.Expect(err).NotTo(HaveOccurred())
3082+
3083+
// Verify the key was set correctly
3084+
val := wrapper.Get(tt.key)
3085+
g.Expect(val).NotTo(BeNil(), "expected key %s should be present in config", tt.key)
3086+
g.Expect(val.Interface()).To(Equal(tt.value), "expected value for key %s", tt.key)
3087+
})
3088+
}
3089+
}

0 commit comments

Comments
 (0)