Skip to content

Commit e5a6051

Browse files
committed
[core] Add comments on gera and defaults/vars/userVars mechanism
1 parent b68946a commit e5a6051

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

common/gera/map.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
//
2727
// A gera.Map uses a map[string]interface{} as backing store, and it can wrap other gera.Map instances.
2828
// Values in child maps override any value provided by a gera.Map that's wrapped in the hierarchy.
29+
//
30+
// The name is reminiscent of hiera, as in hierarchical, but it was deemed desirable to avoid future confusion with the
31+
// Hiera KV store used by Puppet, a different product altogether, so instead of the ancient Greek root, "gera" comes
32+
// from the Italian root instead where "hi" becomes a soft "g".
2933
package gera
3034

3135
import (

core/workflow/rolebase.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ type roleBase struct {
5757
status SafeStatus
5858
state SafeState
5959

60+
// Defaults, Vars and UserVars are used to store each role's variables.
61+
// Defaults are the lowest priority, Vars are the second highest, and UserVars are the highest.
62+
//
63+
// These use the gera.Map type, which is a wrapper around a map[string]string that provides hierarchical KV store
64+
// semantics.
65+
// The gera.Map logic allows us to ensure that defaults are overridden by vars, and vars by userVars throughout the
66+
// workflow tree, and at the same time that defaults/vars/userVars set in a child role override the relevant values
67+
// set in its parent role.
68+
// The way we do this is by ensuring parent-child (Wrap) relationships between all the Default members in the
69+
// workflow tree, all the Vars members, and all the UserVars members, and then whenever we need to figure out what's
70+
// the consolidated KV map seen from the point of view of a given role, we Flatten each of these three, and then
71+
// Wrap and re-Flatten between the flattened defaults, vars and userVars (see ConsolidatedVarStack). This results in
72+
// a single map, generatable from the POV of any role within the tree.
6073
Defaults *gera.WrapMap[string, string] `yaml:"defaults,omitempty"`
6174
Vars *gera.WrapMap[string, string] `yaml:"vars,omitempty"`
6275
UserVars *gera.WrapMap[string, string] `yaml:"-"`
@@ -65,6 +78,8 @@ type roleBase struct {
6578
Enabled string `yaml:"enabled,omitempty"`
6679
}
6780

81+
// Needed for the yaml package to correctly unmarshal into gera.Map[string, string] those Defaults and Vars entries from
82+
// a workflow template, that have a !public tag to include input widget metadata.
6883
func kvStoreUnmarshalYAMLWithTags(w gera.Map[string, string], unmarshal func(interface{}) error) error {
6984
nodes := make(map[string]yaml.Node)
7085
err := unmarshal(&nodes)

0 commit comments

Comments
 (0)