@@ -36,6 +36,7 @@ import (
3636 "github.com/AliceO2Group/Control/core/task/channel"
3737 "github.com/AliceO2Group/Control/core/task/sm"
3838 "github.com/sirupsen/logrus"
39+ "gopkg.in/yaml.v3"
3940
4041 "github.com/AliceO2Group/Control/core/task"
4142 "github.com/AliceO2Group/Control/core/task/constraint"
@@ -64,6 +65,36 @@ type roleBase struct {
6465 Enabled string `yaml:"enabled,omitempty"`
6566}
6667
68+ func kvStoreUnmarshalYAMLWithTags (w gera.Map [string , string ], unmarshal func (interface {}) error ) error {
69+ nodes := make (map [string ]yaml.Node )
70+ err := unmarshal (& nodes )
71+ if err == nil {
72+ m := make (map [string ]string )
73+ for k , v := range nodes {
74+ if v .Kind == yaml .ScalarNode {
75+ m [k ] = v .Value
76+ } else if v .Kind == yaml .MappingNode && v .Tag == "!public" {
77+ type auxType struct {
78+ Value string
79+ }
80+ var aux auxType
81+ err = v .Decode (& aux )
82+ if err != nil {
83+ continue
84+ }
85+ m [k ] = aux .Value
86+ }
87+ }
88+
89+ wPtr := w .(* gera.WrapMap [string , string ])
90+ * wPtr = * gera .MakeMapWithMap (m )
91+ } else {
92+ wPtr := w .(* gera.WrapMap [string , string ])
93+ * wPtr = * gera .MakeMap [string , string ]()
94+ }
95+ return err
96+ }
97+
6798func (r * roleBase ) IsEnabled () bool {
6899 // Only valid after ProcessTemplates
69100 trimmed := strings .ToLower (strings .TrimSpace (r .Enabled ))
@@ -227,25 +258,16 @@ func (r *roleBase) UnmarshalYAML(unmarshal func(interface{}) error) (err error)
227258 // recurse back to this function forever
228259 type _roleBase roleBase
229260 role := _roleBase {
230- Defaults : nil ,
231- Vars : nil ,
232- UserVars : nil ,
261+ Defaults : gera . MakeMap [ string , string ](). WithUnmarshalYAML ( kvStoreUnmarshalYAMLWithTags ) ,
262+ Vars : gera . MakeMap [ string , string ](). WithUnmarshalYAML ( kvStoreUnmarshalYAMLWithTags ) ,
263+ UserVars : gera . MakeMap [ string , string ](). WithUnmarshalYAML ( kvStoreUnmarshalYAMLWithTags ) ,
233264 Locals : make (map [string ]string ),
234265 status : SafeStatus {status : task .INACTIVE },
235266 state : SafeState {state : sm .STANDBY },
236267 Enabled : "true" ,
237268 }
238269 err = unmarshal (& role )
239270 if err == nil {
240- if role .Defaults == nil {
241- role .Defaults = gera .MakeMap [string , string ]()
242- }
243- if role .Vars == nil {
244- role .Vars = gera .MakeMap [string , string ]()
245- }
246- if role .UserVars == nil {
247- role .UserVars = gera .MakeMap [string , string ]()
248- }
249271 * r = roleBase (role )
250272 }
251273 return
0 commit comments