Skip to content

Extend ssa.Apply with field ignore rules #696

Closed

Description

@stefanprodan

To make kustomize-controller compatible with VPA, HPA for custom resources and other controllers which mutate Flux-managed fields in-cluster, we need to wire the ssa/jsondiff logic into the SSA apply functions.

Tasks:

  • Move the saa functions used in jsondiff to a dedicated package
  • Add []jsondiff.IgnoreRule to the ssa.ApplyOptions
  • Remove the ignored fields before the final apply if they diverge

Example:

	appliedObject := object.DeepCopy()

	if existingObject.GetResourceVersion() != "" {
		var sm = make(map[*jsondiff.SelectorRegex][]string, len(opts.DriftIgnoreRule))
		for _, ips := range opts.DriftIgnoreRule {
			sr, err := jsondiff.NewSelectorRegex(ips.Selector)
			if err != nil {
				return nil, fmt.Errorf("failed to create ignore rule selector: %w", err)
			}
			sm[sr] = ips.Paths
		}

		var ignorePaths jsondiff.IgnorePaths
		for sr, paths := range sm {
			if sr.MatchUnstructured(appliedObject) {
				ignorePaths = append(ignorePaths, paths...)
			}
		}

		if len(ignorePaths) > 0 {
			patch := jsondiff.GenerateRemovePatch(ignorePaths...)
			if err := jsondiff.ApplyPatchToUnstructured(appliedObject, patch); err != nil {
				return nil, err
			}
		}
	}

	if err := m.apply(ctx, appliedObject); err != nil {
		return nil, fmt.Errorf("%s apply failed: %w", FmtUnstructured(appliedObject), err)
	}

Activity

  1. added
    enhancement
    area/server-side-apply
    on Dec 1, 2023
  2. alxbse commented on Oct 21, 2024

    @alxbse

    Would like to contribute to getting this solved as flux has been great for my use cases until I now need to manage a CRD with a conversion webhook and a cert-manager caBundle that would keep getting removed/added.

    Is it "just" a lack of priority and contributions that is blocking this issue or is there something else related to adding the ignore rules that makes this extra complicated to solve?

  3. stefanprodan commented on Jul 17, 2025

    @stefanprodan
    MemberAuthor

    @alxbse the CRD conversion webhook CA bundle issue was fixed in #952 and will be available in Flux 2.7

  4. stealthybox commented on Feb 5, 2026

    @stealthybox
    Member

    We're touching on this in the US Flux Dev meeting --
    where should we allow people to define this ignored paths?

    Currently, we can control some SSA behavior and inventory lifecycle via annotations that come from the resource definitions themselves:
    https://fluxcd.io/flux/components/kustomize/kustomizations/#controlling-the-apply-behavior-of-resources

    This is nice because there can be no mismatch from selecting the resource Group/Version/Kind/Name/Namespace.

    Another option is to provide some sort of resourceSelector API similar to kustomizePatches on the flux Kustomization.spec
    This would be a new set of fields.
    It would behave very differently -- should we warn if no paths actually match or not?
    It enables a single place where you can select all VPA resources within a large kustomization without having to edit the resource YAML's.

    at the same time, if it's annotations on the resource, a kustomize patch within either a kustomization.yaml or a Flux Kustomization.spec can already set them at a higher level.
    (ex: patch all VPA's in a specific namespace with a specific ignore Path annotation)

    If it's annotations, we also have to decide on how the paths are represented.
    It can either be a single key where the right-hand-side (RHS) is managed as a string that parses to a single JSON/YAML list, or the LHS key can be made to represent the ignorePaths which would make them mergeable.

  5. stefanprodan commented on Feb 5, 2026

    @stefanprodan
    MemberAuthor

    This has been already implemented in HelmRelease. I don't think we should come up with a different API, IMO the Flux Kustomization will have a .spec.driftDetection.ignore with the array of JSON pointers.

  6. 8bitseppel commented on Feb 19, 2026

    @8bitseppel

    This has been already implemented in HelmRelease. I don't think we should come up with a different API, IMO the Flux Kustomization will have a .spec.driftDetection.ignore with the array of JSON pointers.

    Sounds great! Do you know when this will be released?

  7. matheuscscp commented on Feb 19, 2026

    @matheuscscp
    Member

    Sounds great! Do you know when this will be released?

    Flux 2.9, end of Q2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/server-side-applyenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions