Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2742

Allow each supplementary augments file to have a specified merge stragety

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Need more Info
    • Priority: Low
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      It would be nice if each additional augments could be defined with its own merge
      strategy.

      An entry that specifies a merge strategy could be of the form:

        { "file": "myfile.json", "merge": "deep|overwrite|function" }
      

      Allowing the following where sys.flavor.json is merged with the default
      strategy and the host-specific augments is merged deeply to extend the data
      instead of overwriting it.

      {
       "augments": [ 
          "$(sys.workdir)/cmdb/$(sys.flavor).json",
          { "file": "$(sys.workdir)/cmdb/$(sys.fqhost).json": "merge": "deep" }
          { "file": "$(sys.workdir)/cmdb/$(sys.key_digest).json": "merge": "FUNCTION()" }
        ]
      }
      

      Current override strategy used by mergedata()

      Here is an example of the extension so that after loading def.json we merge it
      with a flavor specific augments, followed by a host-specific augments.

      {
       "augments": [ "$(sys.workdir)/cmdb/$(sys.flavor).json", "$(sys.workdir)/cmdb/$(sys.fqhost).json" ]
      }
      

      Here is an example showing how vars would be merged using the above augments
      specification on a Centos 6 host.

      sys.flavor.json (centos_6.json)

      {
       "vars": {
          "dir_templates": "$(sys.workdir)/templates/$(sys.flavor).json",
          "setting_2": "value for setting 2",
          "deep": {
            "keys": "are not merged deeply"
          }
        }
      }
      

      sys.fqhost.json (host001.json)

      {
       "vars": {
          "owner": "nick anderson",
          "setting_2": "Setting 2 has been overridden at the host level"
          "deep": {
            "overrides": "Last object wins"
        }
      }
      

      Expected merged result after expansion:

      {
       "vars": {
              "dir_templates": "/var/cfengine/templates/centos_6.json",
              "owner": "nick anderson",
              "setting_2": "Setting 2 has been overridden at the host level",
              "deep": {
                "overrides": "Last object wins"
             }
        }
      }
      

      And here are the expected variable values:

      def.dir_templates = /var/cfengine/templates/centos_6.json
      def.owner = nick anderson
      def.setting_2 = Setting 2 has been overridden at the host level
      def.deep = { "overrides": "Last object wins" };
      

      Deep merge

      Need specification

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                a10042 Nick Anderson
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: