@@ -854,6 +854,115 @@ kustomize.toolkit.fluxcd.io/force: enabled
854854This way, only the targeted resources are force-replaced when immutable field
855855changes are made. The annotation should be removed after the change is applied.
856856
857+ # ## Drift Ignore Rules
858+
859+ ` .spec.driftIgnoreRules` is an optional list used to selectively ignore changes
860+ to specific fields during drift detection and correction. This allows external
861+ controllers or tools to manage certain fields on Kubernetes resources without
862+ having those changes reverted by the kustomize-controller during reconciliation.
863+
864+ Each item in the list must have the following fields :
865+
866+ - `paths` (required) : A list of [JSON Pointer (RFC 6901)](https://datatracker.ietf.org/doc/html/rfc6901)
867+ paths to exclude from drift detection. These paths refer to specific fields
868+ within the Kubernetes object manifest.
869+ - `target` (optional) : A selector to scope the rule to specific Kubernetes
870+ resources. If not set, the paths are ignored for all resources in the
871+ Kustomization.
872+
873+ The `target` selector supports the following fields :
874+
875+ | Field | Description |
876+ |----------------------|--------------------------------------|
877+ | `group` | API group (regex) |
878+ | `version` | API version (regex) |
879+ | `kind` | Resource kind (regex) |
880+ | `name` | Resource name (regex) |
881+ | `namespace` | Resource namespace (regex) |
882+ | `labelSelector` | Kubernetes label selector expression |
883+ | `annotationSelector` | Kubernetes annotation selector expression |
884+
885+ **Note:** The `group`, `version`, `kind`, `name`, and `namespace` fields
886+ support regex patterns. The `labelSelector` and `annotationSelector` fields
887+ use the standard Kubernetes
888+ [label selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors)
889+ syntax.
890+
891+ **Note:** For JSON Pointer paths that contain `/` in the key name (e.g.
892+ annotation keys), the `/` must be escaped as `~1` per
893+ [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901#section-3).
894+ For example, the annotation `external-dns.alpha.kubernetes.io/hostname`
895+ would be referenced as `/metadata/annotations/external-dns.alpha.kubernetes.io~1hostname`.
896+
897+ # ### Ignore a field on all resources
898+
899+ To ignore a specific field on all resources managed by the Kustomization :
900+
901+ ` ` ` yaml
902+ ---
903+ apiVersion: kustomize.toolkit.fluxcd.io/v1
904+ kind: Kustomization
905+ metadata:
906+ name: app
907+ namespace: flux-system
908+ spec:
909+ # ...omitted for brevity
910+ driftIgnoreRules:
911+ - paths:
912+ - "/spec/replicas"
913+ ` ` `
914+
915+ # ### Ignore fields on specific resources
916+
917+ To ignore fields only on resources that match a target selector :
918+
919+ ` ` ` yaml
920+ ---
921+ apiVersion: kustomize.toolkit.fluxcd.io/v1
922+ kind: Kustomization
923+ metadata:
924+ name: app
925+ namespace: flux-system
926+ spec:
927+ # ...omitted for brevity
928+ driftIgnoreRules:
929+ - paths:
930+ - "/spec/replicas"
931+ target:
932+ kind: Deployment
933+ - paths:
934+ - "/metadata/annotations/external-dns.alpha.kubernetes.io~1hostname"
935+ target:
936+ kind: Service
937+ name: my-service
938+ - paths:
939+ - "/spec/template/spec/containers/0/resources"
940+ target:
941+ kind: Deployment
942+ name: my-app
943+ ` ` `
944+
945+ In the above example :
946+
947+ - The `/spec/replicas` field is ignored on all Deployments, allowing
948+ an HPA or other autoscaler to manage the replica count without
949+ interference from the kustomize-controller.
950+ - The `external-dns.alpha.kubernetes.io/hostname` annotation is ignored
951+ on a specific Service named `my-service`, allowing external-dns to
952+ manage this annotation.
953+ - The entire `/resources` subtree under container spec is ignored on
954+ a specific Deployment named `my-app`, allowing a VPA or other resource
955+ management tool to adjust container resources.
956+
957+ **Important:** Drift ignore rules work with the
958+ [server-side apply](https://kubernetes.io/docs/reference/using-api/server-side-apply/)
959+ field ownership model. The ignored paths are removed from the desired state
960+ before the controller applies, which relinquishes the controller's ownership of
961+ those fields. For the ignored fields to be preserved, they must be owned by
962+ another field manager (e.g. another controller or a `kubectl apply --server-side
963+ --field-manager=<name>` invocation). If no other field manager owns the field,
964+ the API server may remove it during garbage collection of abandoned fields.
965+
857966# ## KubeConfig (Remote clusters)
858967
859968With the `.spec.kubeConfig` field a Kustomization
0 commit comments