Patching existing objects
In this guide we show how you can patch existing objects on a cluster using the adhoc-configurations component.
The guide assumes that
* You’ve already followed the quick-start guide to enable the component and setup a directory for manifests in your tenant repository.
* You’ve prepared your object patches in a format that kubectl patch understands
An object patch in the context of this guide is a patch that could be applied with kubectl patch.
|
-
Ensure patch-operator is deployed on the cluster.
c-cluster-id.yamlapplications: - patch-operator -
Define your
Patchobject containing your patch(es)For example, to patch a service object
my-servicein namespacemy-appto expose target port 8000 on port 8000 in addition to existing port configurations, we’d supply the followingPatchobject.manifests/c-cluster-id/service-patch.yamlkind: Patch metadata: name: my-first-patch spec: patches: my-app-service: (1) patchTemplate: |- (2) spec: ports: - protocol: TCP port: 8000 targetPort: 8000 patchType: application/strategic-merge-patch+json (3) targetObjectRef: (4) apiVersion: v1 kind: Service namespace: my-app name: my-service1 The internal identifier for the patch. The patch-operator uses the patch id to provide metrics about patch errors and reconcile times for the patch. Users should try to keep patch identifiers unique to ensure patch-operator metrics remain usable. 2 The patch to apply. 3 The patch strategy to use when applying the patch, must be one of -
application/json-patch+json— equivalent tokubectl patch --type=json -
application/merge-patch+json— equivalent tokubectl patch --type=merge -
application/strategic-merge-patch+json— equivalent tokubectl patch --type=strategic -
application/apply-patch+yaml— equivalent tokubectl apply --server-side=trueIf the field isn’t specified, it will default to
application/strategic-merge-patch+json.
4 The object to patch A
Patchobject can contain multiple patches. Just add additional key-value pairs to thespec.patchesobject in thePatchobject. -
-
Add your
Patchmanifest in the tenant repo for the cluster on which you want to apply the patch.The file holding the
Patchmanifest can be named arbitrarily. -
Recompile the cluster catalog