Kubernetes Strategic Merge Patch: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=
* https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md
* https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md
* https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/
* https://github.com/kubernetes-sigs/kustomize/blob/master/docs/glossary.md#patchstrategicmerge
* https://github.com/kubernetes-sigs/kustomize/blob/master/docs/glossary.md#patchstrategicmerge


Line 10: Line 10:
* [[Kubectl_edit#Overview|kubectl edit]]
* [[Kubectl_edit#Overview|kubectl edit]]
* [[Kubectl_patch#Overview|kubectl patch]]
* [[Kubectl_patch#Overview|kubectl patch]]
* [[JSON Patch]]
* [[JSON Merge Patch]]


=Overview=
=Overview=


A strategic merge patch is a customized version of [[JSON Patch|JSON patch]] and it looks like an incomplete YAML specification of a k8s resource.
A strategic merge patch is a customized version of [[JSON Patch|JSON patch]] and it looks like an incomplete YAML specification of a Kubernetes resource.


The SMP includes <tt>TypeMeta</tt> fields to establish the group/version/kind/name of the resource to patch, then just enough remaining fields to step into a nested structure to specify a new field value, e.g. an image tag. By default, an SMP replaces values. This is usually the desired behavior when the target value is a simple string, but may not be desired when the target value is a list. To change this default behavior, add a directive. Recognized directives in YAML patches are:
The SMP includes <tt>TypeMeta</tt> fields to establish the group/version/kind/name of the resource to patch, then just enough remaining fields to step into a nested structure to specify a new field value, e.g. an image tag. By default, an SMP replaces values. This is usually the desired behavior when the target value is a simple string, but may not be desired when the target value is a list. To change this default behavior, add a directive. Recognized directives in YAML patches are:
* replace (the default)
* replace (the default)
* delete
* delete
Also see: {{Internal|JSON Patch|JSON Patch}}{{Internal|JSON Merge Patch|JSON Merge Patch}}
=Example=
The following patch updates the amount of memory allocated to a container in a pod and changes it to 1024Mi
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    resources:
      limits:
        memory: 1024Mi

Latest revision as of 17:59, 29 July 2021

External

Internal

Overview

A strategic merge patch is a customized version of JSON patch and it looks like an incomplete YAML specification of a Kubernetes resource.

The SMP includes TypeMeta fields to establish the group/version/kind/name of the resource to patch, then just enough remaining fields to step into a nested structure to specify a new field value, e.g. an image tag. By default, an SMP replaces values. This is usually the desired behavior when the target value is a simple string, but may not be desired when the target value is a list. To change this default behavior, add a directive. Recognized directives in YAML patches are:

  • replace (the default)
  • delete

Also see:

JSON Patch
JSON Merge Patch

Example

The following patch updates the amount of memory allocated to a container in a pod and changes it to 1024Mi

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
 containers:
 - name: my-container
   resources:
     limits:
       memory: 1024Mi