JSON Merge patch

The json-merge-patch trait permits to patch the rendered component to modify its structure, and or parameters. Notice that this trait will work for webservice, and worker component definitions. This trait is useful to patch options not yet supported by the components, but its usage is generally discourage for maintainability reason. The same behavior can be obtained with a combination of traits such as annotations, labels, or sidecar.

The following snippets shows an example application that uses a json-merge-patch trait to modify the resulting labels (label1 and label2), adding a new container container-updated.

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: json-patch-app
  annotations: 
    version: "v0.0.1"
    description: "My json-patch application"
spec:
  components:
    - name: json-patch-component
      type: webservice
      properties:
        image: my-app-image:v1.0.0
        cmd: ["server", "run"]
        cpu: "0.25"
        memory: "200Mi"
        labels:
          label1: value1
          label2: value2
      traits:        
        - type: json-merge-patch # Set to json-merge-patch
          properties:
            # EXAMPLES
            spec:
              # replace replicas
              replicas: 2
              template:
                metadata:
                  labels:
                    # Update pod label
                    label1: updated
                    # Remove pod label
                    label2: null
                spec:
                  containers: # Add a new container
                    - name: container-updated
                      image: busybox:1.34
                      command: ["sleep", "864000"]
                      resources:
                        requests:
                          cpu: 200m
                          memory: 100Mi