@@ -66,11 +66,14 @@ type (
66
66
67
67
Mutate func (string , string , string ) (string , error )
68
68
69
+ DynamicAppend func (string , string ) (string , error )
70
+
69
71
Filter struct {
70
- KVFieldSplit string
71
- Mutate Mutate
72
- Input * string
73
- Output * string
72
+ KVFieldSplit string
73
+ Mutate Mutate
74
+ SerivceConfig map [string ]string
75
+ Input * string
76
+ Output * string
74
77
}
75
78
76
79
SyncFile struct {
80
83
ContainerDestPath string
81
84
KVFieldSplit string
82
85
Mutate func (string , string , string ) (string , error )
86
+ SerivceConfig map [string ]string
83
87
module.ExecOptions
84
88
}
85
89
@@ -232,6 +236,14 @@ func (s *Filter) kvSplit(line string, key, value *string) error {
232
236
func (s * Filter ) Execute (ctx * context.Context ) error {
233
237
var key , value string
234
238
output := []string {}
239
+
240
+ topologySerivceConfigKeys := []string {}
241
+ for k := range s .SerivceConfig {
242
+ topologySerivceConfigKeys = append (topologySerivceConfigKeys , k )
243
+ }
244
+
245
+ originServiceConfigKeys := []string {}
246
+
235
247
scanner := bufio .NewScanner (strings .NewReader (string (* s .Input )))
236
248
for scanner .Scan () {
237
249
in := scanner .Text ()
@@ -242,13 +254,36 @@ func (s *Filter) Execute(ctx *context.Context) error {
242
254
}
243
255
}
244
256
257
+ originServiceConfigKeys = append (originServiceConfigKeys , key )
258
+
245
259
out , err := s .Mutate (in , key , value )
246
260
if err != nil {
247
261
return err
248
262
}
249
263
output = append (output , out )
250
264
}
251
265
266
+ // extract the key from topologySerivceConfigKeys that are not in originServiceConfigKeys
267
+ extraServiceConfigKeys := utils .Filter (topologySerivceConfigKeys , func (k string ) bool {
268
+ if ! strings .HasPrefix (k , "mds_" ) {
269
+ return false
270
+ }
271
+ mdsv2_key := fmt .Sprintf ("%s%s" , comm .MDSV2_CONFIG_PREFIX , k )
272
+ return ! utils .Contains (originServiceConfigKeys , mdsv2_key )
273
+ })
274
+
275
+ if len (extraServiceConfigKeys ) > 0 {
276
+ output = append (output , "# dynamic config from topology" )
277
+ for _ , k := range extraServiceConfigKeys {
278
+ v := s .SerivceConfig [k ]
279
+ if len (v ) > 0 {
280
+ // dingo-mdsv2.template.conf
281
+ out := fmt .Sprintf ("%s%s%s%s" , comm .MDSV2_CONFIG_PREFIX , k , s .KVFieldSplit , v )
282
+ output = append (output , out )
283
+ }
284
+ }
285
+ }
286
+
252
287
* s .Output = strings .Join (output , "\n " )
253
288
return nil
254
289
}
@@ -263,10 +298,11 @@ func (s *SyncFile) Execute(ctx *context.Context) error {
263
298
ExecOptions : s .ExecOptions ,
264
299
})
265
300
steps = append (steps , & Filter {
266
- KVFieldSplit : s .KVFieldSplit ,
267
- Mutate : s .Mutate ,
268
- Input : & input ,
269
- Output : & output ,
301
+ KVFieldSplit : s .KVFieldSplit ,
302
+ Mutate : s .Mutate ,
303
+ SerivceConfig : s .SerivceConfig ,
304
+ Input : & input ,
305
+ Output : & output ,
270
306
})
271
307
steps = append (steps , & InstallFile {
272
308
ContainerId : s .ContainerDestId ,
0 commit comments