ssa/jsondiff: honor ignored fields before dry-run validation

Open
#1,330 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@lubronzhan is already working on this.

Since Oct 16, 2026.

  • #1331 by @lubronzhan — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go, helm, kubernetes
Domain
devops

Research direction

Start in ssa/jsondiff/unstructured.go, in Unstructured(), where the live object is fetched and the desired object is dry-run applied before ignored paths are removed. Read the existing tests for the ignore-path filtering, then decide how live values at ignored paths should be copied into a temporary desired object, including the missing-path and array cases. Done means a regression test where a validating webhook rejects a decrease of an ignored field now passes the dry-run, unrelated drift is still reported, and the error still returns without the rule. The semantics need maintainer agreement first.

Written by the indexing model from the issue text.

Description

Problem

jsondiff.Unstructured() applies ignored paths only after its server-side dry-run succeeds. An ignored field can therefore cause admission validation to reject the dry-run before the ignore rules take effect.

Reported downstream in https://github.com/fluxcd/helm-controller/issues/1613 with helm-controller v1.4.5 and a StackGres SGShardedCluster. The same ordering is present in ssa/v0.80.0.

Example

The downstream reporter ignores these fields because an in-cluster controller updates them after installation:

  • /spec/coordinator/pods/persistentVolume/size
  • /spec/shards/pods/persistentVolume/size
  • /spec/shards/overrides

When the live volume size is larger than the value in the Helm release manifest, the dry-run submits the smaller manifest value. The validating webhook rejects the attempted shrink, even though that field is ignored for drift detection. This prevents comparison and correction of unrelated fields on the resource.

This example comes from the downstream report; I have traced the code but have not independently reproduced it against StackGres.

Code path

Unstructured() first fetches the live resource, then copies the desired object and submits it with client.Apply and client.DryRunAll:

https://github.com/fluxcd/pkg/blob/ssa/v0.80.0/ssa/jsondiff/unstructured.go#L158-L166

Only after that succeeds does it remove ignored paths from the dry-run result and the live object before calculating the diff:

https://github.com/fluxcd/pkg/blob/ssa/v0.80.0/ssa/jsondiff/unstructured.go#L176-L186

The ordering has existed since the introduction of jsondiff in #657. The ApplyOptions.DriftIgnoreRules work in #1157 is a separate path; helm-controller calls jsondiff.UnstructuredList() directly.

Expected behavior / proposed approach

For existing resources, consider preserving live values at matching ignored paths in a temporary copy of the desired object before submitting the dry-run. Keep the existing post-dry-run filtering so ignored fields do not appear in the correction patch. The original desired object should remain unchanged, and missing resources should retain the full desired manifest for creation.

The semantics for paths missing from either object, array paths, and overlapping paths need to be defined and tested. Simply deleting ignored fields before server-side apply may affect required fields or field ownership, so it is not necessarily equivalent to preserving live values.

A regression test should use validation that rejects a decrease of an ignored field, verify that the dry-run succeeds with the rule, and verify that unrelated drift remains detectable and correctable. Without the rule, the validation error should still be returned.

Workaround

The downstream reporter disables drift detection for the entire resource with helm.toolkit.fluxcd.io/driftDetection: disabled, losing drift detection for its other fields.

Dominant language
Go
Stars
63
Forks
162
Avg merge
9h 54m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fluxcd/pkg

All issues in fluxcd/pkg

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.