patch-operator.libsonnet
API reference
This page documents the fields and functions provided by the patch-operator.libsonnet
component library.
Usage
The library is intended to provide an easy interface to patch single resources to other components.
For example, to add a custom label to an existing namespace on the cluster, you can use the following Jsonnet snippet.
local kube = import 'lib/kube.libjsonnet';
local p = import 'lib/patch-operator.libsonnet';
// Create a strategic merge patch for the namespace
local ns_patch = p.Patch(
kube.Namespace('the-namespace'),
{
metadata: {
labels: {
foo: 'bar'
},
},
}
);
{
// output the patch
ns_patch: ns_patch,
}
Function reference
Patch(targetobj, patchtemplate, patchstrategy='application/strategic-merge-patch+json')
Arguments
targetobj
-
The target object to patch. The library expects this to be a valid Kubernetes object definition. The object doesn’t need to be complete, but fields
apiVersion
,kind
,metadata.name
must be present. For namespaced resources, fieldmetadata.namespace
also must be present for accurate patch targeting. patchtemplate
-
An object describing the patch to apply. The exact format of this object is defined by parameter
patchstrategy
. The operator supports the same patch formats askubectl patch
.
See the Kubernetes docs on patching objects for more information on supported formats.
See the patch-operator README for more details on additional features provided by patch-operator.
Please note that this function doesn’t support selecting multiple target objects for a patch, but users are free to modify the returned patch object to do so.
patchstrategy
-
The strategy to use to apply the patch provided in parameter
patchtemplate
. The parameter defaults to Kubernetes' strategic merge patch (application/strategic-merge-patch+json
).
Supported strategies are
-
application/json-patch+json
for RFC 6902 JSON patches -
application/merge-patch+json
for RFC 7386 JSON merge patches -
application/strategic-merge-patch+json
for Kubernetes' strategic merge patches
render_patch(patch, rl_version, patch_id='patch1')
This function can be used to render individual patches. There’s no real need for this function anymore, and it may be removed in a future release.
Arguments
patch
-
The patch to format. See the documentation for the
Patch()
function for details. rl_version
-
This parameter is deprecated, and no longer has any effect. It will be removed in a future release.
patch_id
-
The patch ID to inject into the patch provided in argument
patch
. Defaults topatch1
.