patch-operator.libsonnet API reference

This page documents the fields and functions provided by the patch-operator.libsonnet component library.


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(
    metadata: {
      labels: {
        foo: 'bar'

  // output the patch
  ns_patch: ns_patch,

Function reference


Field apiVersion provides the API version of the Patch resources created by the library.

Return value

Patch(targetobj, patchtemplate, patchstrategy='application/strategic-merge-patch+json')



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, must be present. For namespaced resources, field metadata.namespace also must be present for accurate patch targeting.


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 as kubectl 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.


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

Return value

A list containing the rendered Patch custom resource.

We return a list, so that we could return additional resources if required. Users should always add the complete list to the component’s output to ensure that patches can be applied correctly.

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.



The patch to format. See the documentation for the Patch() function for details.


This parameter is deprecated, and no longer has any effect. It will be removed in a future release.


The patch ID to inject into the patch provided in argument patch. Defaults to patch1.

Return value

An object with key patch_id and value patch.