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.
  1. Ensure patch-operator is deployed on the cluster.

    c-cluster-id.yaml
    applications:
      - patch-operator
  2. Define your Patch object containing your patch(es)

    For example, to patch a service object my-service in namespace my-app to expose target port 8000 on port 8000 in addition to existing port configurations, we’d supply the following Patch object.

    manifests/c-cluster-id/service-patch.yaml
    kind: 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 to kubectl patch --type=json

    • application/merge-patch+json — equivalent to kubectl patch --type=merge

    • application/strategic-merge-patch+json — equivalent to kubectl patch --type=strategic

    • application/apply-patch+yaml — equivalent to kubectl 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 the spec.patches object in the Patch object.

  3. 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.

  4. Recompile the cluster catalog