Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5914

data binding: a way to set the merge behaviour (like in the lookup() function) ?



    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • None
    • None
    • Language
    • None



      I use puppet 4 and data binding with much satisfaction. Just for memory, data binding for instance it's:

      1. A manifest foo/manifests/init.pp like that in a foo module:

      class foo (
          String[1]                  $param1,
          Hash[String[1], String[1]] $param2,
          Array[Data, 1]             $param3,
      ) {
          # The body of the class...

      2. This boilerplate function foo/lib/puppet/bindings/foo/default.rb:

      Puppet::Bindings.newbindings('foo::default') do
        bind {
          name         'foo'
          to           'function'
          in_multibind 'puppet::module_data'

      3. And a puppet function in foo/functions/data.pp:

      function foo::data {
        # Code where $default_param1, $default_param2 and $default_param3 are set...
          foo::param1: $default_param1,
          foo::param2: $default_param2,
          foo::param3: $default_param3,

      And now, in hiera, I can override the default value of a parameter like that:

      # Here I just want to override the default value of param2.
         key1: 'specific-value1'
         key2: 'specific-value2'

      The wish

      It's very useful but the merge behavior in the data binding mechanism is not changeable and it's necessarily the first behavior, ie the behavior where there is no merge (the first value found wins).

      It could be amazing if it was possible to set the merge behavior like in the lookup() function. I have no idea how the syntax could be but the first way I see is something like that in the declaration of the foo class:

      class foo (
                 String[1]                  $param1,
          deep   Hash[String[1], String[1]] $param2,
          unique Array[Data, 1]             $param3,
      ) {
          # The body of the class...

      The syntax will be

      [<merge behavior>] [<data type>] $<variable-name>

      where <merge behavior> will be a string like in the lookup() function, ie 'first', 'unique', 'hash' or 'deep' (cf here) etc. To keep compatibility with the "old" syntax:

          String[1] $param1,

      will be equivalent to:

          first String[1] $param1,

      I have absolutely no idea if the implementation of this feature will be possible and/or complicated (I'm unable to evaluate that and unable to implement that... unfortunately) but it seems to me that it could be a very useful feature and I'm ready to test an implementation of that when you want of course.

      Of course, it's just a wish. No problem if this ticket is rejected.

      Fran├žois Lafont

      PS: message edited (to just fix typo)


        Issue Links



              Unassigned Unassigned
              flaf Francois Lafont
              0 Vote for this issue
              3 Start watching this issue



                Zendesk Support