patch

package
v0.0.0-...-dd9793c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package patch implements a simple patching mechanism for k8s resources. Paths are specified in the form a.b.c.[key:value].d.[list_entry_value], where:

  • [key:value] selects a list entry in list c which contains an entry with key:value
  • [list_entry_value] selects a list entry in list d which is a regex match of list_entry_value.

Some examples are given below. Given a resource:

kind: Deployment
metadata:
  name: istio-citadel
  namespace: istio-system
a:
  b:
  - name: n1
    value: v1
  - name: n2
    list:
    - "vv1"
    - vv2=foo

values and list entries can be added, modified or deleted.

MODIFY

1. set v1 to v1new

path: a.b.[name:n1].value
value: v1new

2. set vv1 to vv3

// Note the lack of quotes around vv1 (see NOTES below).
path: a.b.[name:n2].list.[vv1]
value: vv3

3. set vv2=foo to vv2=bar (using regex match)

path: a.b.[name:n2].list.[vv2]
value: vv2=bar

4. replace a port whose port was 15010

  • path: spec.ports.[port:15010] value: port: 15020 name: grpc-xds protocol: TCP

DELETE

1. Delete container with name: n1

path: a.b.[name:n1]

2. Delete list value vv1

path: a.b.[name:n2].list.[vv1]

ADD

1. Add vv3 to list

path: a.b.[name:n2].list.[1000]
value: vv3

Note: the value 1000 is an example. That value used in the patch should be a value greater than number of the items in the list. Choose 1000 is just an example which normally is greater than the most of the lists used.

2. Add new key:value to container name: n1

path: a.b.[name:n1]
value:
  new_attr: v3

*NOTES* - Due to loss of string quoting during unmarshaling, keys and values should not be string quoted, even if they appear that way in the object being patched. - [key:value] treats ':' as a special separator character. Any ':' in the key or value string must be escaped as \:.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func YAMLManifestPatch

func YAMLManifestPatch(baseYAML string, defaultNamespace string, overlays []*v1alpha1.K8SObjectOverlay) (string, error)

YAMLManifestPatch patches a base YAML in the given namespace with a list of overlays. Each overlay has the format described in the K8SObjectOverlay definition. It returns the patched manifest YAML.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL