Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

[Feature]Support for merging multiple JSON/XML fragments to cover complex types #157

Open
ifree613 opened this issue Jul 31, 2020 · 3 comments

Comments

@ifree613
Copy link

Is your feature request related to a problem? Please describe.

Ref to Pull requests : #134

Describe the solution you'd like

Support for merging multiple JSON/XML fragments to cover complex types

  • Sample JSON fragment 1,patch1
{
  "spec": {
    "containers": [
      {
        "env": [
          {
            "name": "DEBUG_ENABLE",
            "value": "true"
          },
          {
            "name": "ENV_FLAG",
            "value": "test"
          }
        ]
      }
    ]
  }
}
  • Sample JSON fragment 1,patch2
{
  "spec": {
    "containers": [
      {
        "env": [
          {
            "name": "OPEN_TRACING",
            "value": "true"
          },
          {
            "name": "ENV_FLAG",
            "value": "dev"
          }
        ]
      }
    ]
  }
}
  • Call the merge API sample

data := mergeTool.merge(&patch1,patch2)

Note: By specifying the merged parameters, the first is used as the basis, and the subsequent ones override and append related parameters in turn

  • The result of the merge
{
  "spec": {
    "containers": [
      {
        "env": [
          {
            "name": "DEBUG_ENABLE",
            "value": "true"
          },
          {
            "name": "OPEN_TRACING",
            "value": "true"
          },
          {
            "name": "ENV_FLAG",
            "value": "dev"
          }
        ]
      }
    ]
  }
}
@hongchaodeng
Copy link
Member

FYI, this is what json merge patch does: https://tools.ietf.org/html/rfc7386

@wonderflow
Copy link
Member

Can we use kustomize to solve this issue?

Support both patchesJson6902 and patchesStrategicMerge.

@wonderflow
Copy link
Member

This issue is actually the same with K8s strategicMergepatch in library at "k8s.io/apimachinery/pkg/util/strategicpatch"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants