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
Patch
object containing your patch(es)For example, to patch a service object
my-service
in namespacemy-app
to expose target port 8000 on port 8000 in addition to existing port configurations, we’d supply the followingPatch
object.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-service
1 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=true
If the field isn’t specified, it will default to
application/strategic-merge-patch+json
.
4 The object to patch A
Patch
object can contain multiple patches. Just add additional key-value pairs to thespec.patches
object in thePatch
object. -
-
Add your
Patch
manifest in the tenant repo for the cluster on which you want to apply the patch.The file holding the
Patch
manifest can be named arbitrarily. -
Recompile the cluster catalog