@@ -893,6 +893,113 @@ kustomize.toolkit.fluxcd.io/force: enabled
893893This way, only the targeted resources are force-replaced when immutable field
894894changes are made. The annotation should be removed after the change is applied.
895895
896+ # ## Drift Ignore Rules
897+
898+ ` .spec.ignore` is an optional list used to selectively ignore changes
899+ to specific fields during drift detection and correction. This allows external
900+ controllers or tools to manage certain fields on Kubernetes resources without
901+ having those changes reverted by the kustomize-controller during reconciliation.
902+
903+ Each item in the list must have the following fields :
904+
905+ - `paths` (required) : A list of [JSON Pointer (RFC 6901)](https://datatracker.ietf.org/doc/html/rfc6901)
906+ paths to exclude from drift detection. These paths refer to specific fields
907+ within the Kubernetes object manifest.
908+ - `target` (optional) : A selector to scope the rule to specific Kubernetes
909+ resources. If not set, the paths are ignored for all resources in the
910+ Kustomization.
911+
912+ **Warning:** Omitting the `target` selector causes the rule to match **all**
913+ objects managed by the Kustomization. Always scope rules to specific resources
914+ using `target` unless you intentionally want to ignore the specified paths
915+ across every resource.
916+
917+ The `target` selector supports the following fields :
918+
919+ | Field | Description |
920+ |----------------------|--------------------------------------|
921+ | `group` | API group (regex) |
922+ | `version` | API version (regex) |
923+ | `kind` | Resource kind (regex) |
924+ | `name` | Resource name (regex) |
925+ | `namespace` | Resource namespace (regex) |
926+ | `labelSelector` | Kubernetes label selector expression |
927+ | `annotationSelector` | Kubernetes annotation selector expression |
928+
929+ **Note:** The `group`, `version`, `kind`, `name`, and `namespace` fields
930+ support regex patterns. The `labelSelector` and `annotationSelector` fields
931+ use the standard Kubernetes
932+ [label selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors)
933+ syntax.
934+
935+ **Note:** For JSON Pointer paths that contain `/` in the key name (e.g.
936+ annotation keys), the `/` must be escaped as `~1` per
937+ [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901#section-3).
938+ For example, the annotation `external-dns.alpha.kubernetes.io/hostname`
939+ would be referenced as `/metadata/annotations/external-dns.alpha.kubernetes.io~1hostname`.
940+
941+ To ignore fields only on resources that match a target selector :
942+
943+ ` ` ` yaml
944+ ---
945+ apiVersion: kustomize.toolkit.fluxcd.io/v1
946+ kind: Kustomization
947+ metadata:
948+ name: app
949+ namespace: flux-system
950+ spec:
951+ # ...omitted for brevity
952+ ignore:
953+ - paths:
954+ - "/spec/replicas"
955+ target:
956+ kind: Deployment
957+ - paths:
958+ - "/metadata/annotations/external-dns.alpha.kubernetes.io~1hostname"
959+ target:
960+ kind: Service
961+ name: my-service
962+ - paths:
963+ - "/spec/template/spec/containers/0/resources"
964+ target:
965+ kind: Deployment
966+ name: my-app
967+ ` ` `
968+
969+ In the above example :
970+
971+ - The `/spec/replicas` field is ignored on all Deployments, allowing
972+ an HPA or other autoscaler to manage the replica count without
973+ interference from the kustomize-controller.
974+ - The `external-dns.alpha.kubernetes.io/hostname` annotation is ignored
975+ on a specific Service named `my-service`, allowing external-dns to
976+ manage this annotation.
977+ - The entire `/resources` subtree under container spec is ignored on
978+ a specific Deployment named `my-app`, allowing a VPA or other resource
979+ management tool to adjust container resources.
980+
981+ **Note:** Changes to ignored fields alone do not trigger a reconciliation.
982+ The controller excludes ignored paths when comparing the desired state against
983+ the live object, so modifications made by external controllers to those fields
984+ will not cause unnecessary applies or resource version bumps.
985+
986+ **Important:** Drift ignore rules work with the
987+ [server-side apply](https://kubernetes.io/docs/reference/using-api/server-side-apply/)
988+ field ownership model. When a reconciliation is triggered (e.g. by a source
989+ revision change or drift in non-ignored fields),
990+ the controller resolves each ignored path using one of two strategies based on
991+ field ownership :
992+
993+ - **Strip** — If the ignored field is owned by another Apply-type field manager
994+ (e.g. another controller using server-side apply), the field is removed from
995+ the apply payload. This relinquishes the controller's ownership and allows the
996+ other manager to retain full control of the field.
997+ - **Adopt** — If the controller is the sole Apply-type field manager for the
998+ field, the in-cluster value is copied into the apply payload. This preserves
999+ the current value without reverting changes made by Update-type operations
1000+ (e.g. `kubectl patch`, `kubectl edit`, or client-go Update calls) while
1001+ keeping the controller's field ownership intact.
1002+
8961003# ## KubeConfig (Remote clusters)
8971004
8981005With the `.spec.kubeConfig` field a Kustomization
0 commit comments