| garciadeblas | 83775ba | 2025-07-23 18:35:24 +0200 | [diff] [blame] | 1 | ####################################################################################### |
| 2 | # Copyright ETSI Contributors and Others. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 13 | # implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | ####################################################################################### |
| 17 | |
| 18 | # Module with helper functions to create strategic merge patches for Kubernetes resources (patchStrategicMerge). |
| 19 | |
| 20 | |
| 21 | # Helper to create a full strategic merge patch, including the target object specification and partial resource manifest. |
| 22 | # |
| 23 | # Example: |
| 24 | # $ strategicmergepatch create {kind: Deployment, name: podinfo} ( |
| 25 | # 'apiVersion: apps/v1 |
| 26 | # kind: Deployment |
| 27 | # metadata: |
| 28 | # name: not-used |
| 29 | # spec: |
| 30 | # template: |
| 31 | # metadata: |
| 32 | # annotations: |
| 33 | # cluster-autoscaler.kubernetes.io/safe-to-evict: "true"' | from yaml |
| 34 | # ) | to yaml |
| 35 | # |
| 36 | # target: |
| 37 | # kind: Deployment |
| 38 | # name: podinfo |
| 39 | # patch: | |
| 40 | # apiVersion: apps/v1 |
| 41 | # kind: Deployment |
| 42 | # metadata: |
| 43 | # name: not-used |
| 44 | # spec: |
| 45 | # template: |
| 46 | # metadata: |
| 47 | # annotations: |
| 48 | # cluster-autoscaler.kubernetes.io/safe-to-evict: 'true' |
| 49 | # |
| 50 | # Further information about advanced syntax for strategic merge patch (e.g. '$patch' directives) can be found at <https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md> |
| 51 | export def "create" [ |
| 52 | target: record, # Target resource specification as per <https://github.com/kubernetes-sigs/kustomize/blob/master/examples/patchMultipleObjects.md> |
| 53 | patch: record # Partial resource manifest |
| 54 | ]: [ |
| 55 | nothing -> record |
| 56 | ] { |
| 57 | { |
| 58 | target: $target, |
| 59 | patch: ($patch | to yaml) |
| 60 | } |
| 61 | } |