fix: patch fallback json merge#285
Merged
Merged
Conversation
ea2b99a to
faa2d68
Compare
pepov
previously approved these changes
May 18, 2026
faa2d68 to
fd1c0b8
Compare
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
fd1c0b8 to
5edf371
Compare
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
…lure Resources whose Go types use a custom MarshalJSON that hoists map entries to top-level JSON keys — e.g. opentelemetry-operator's AnyConfig — fail reflective strategic-merge with "unable to find api field in struct ... for the json field ...". When PatchMaker.Calculate errors, the existing reconciler skips the "resource is in sync" short-circuit and issues a full Update on every reconcile, bumping the API server generation and triggering downstream churn. Wrap the default PatchMaker with FallbackPatchMaker, which retries with a three-way JSON merge patch when the primary maker errors. Behaviour is unchanged for types where strategic-merge succeeds.
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
5edf371 to
3c7806f
Compare
pepov
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resources whose Go types use a custom
MarshalJSONthat hoists map entries totop-level JSON keys — most notably opentelemetry-operator's
AnyConfigfail reflective strategic-merge insidek8s-objectmatcherwith:When
PatchMaker.Calculatereturns an error,ReconcileResourceskips thepatchResult.IsEmpty()"resource is in sync" short-circuit and issues a fullClient.Update(...)on every reconcile. The result is a generation bump onthe API server every loop, which in turn triggers the downstream operator
(opentelemetry-operator in our case) to reconcile, producing visible churn and
DEBUG log spam:
This PR introduces
FallbackPatchMaker, a thin wrapper around anypatch.Makerthat retries with a three-way JSON merge patch when the primary maker errors.
It is wired in as the default in
NewReconcilerWith, so every consumer ofoperator-toolspicks it up automatically.Behavior is unchanged for types where strategic-merge already succeeds — the
fallback path only runs on the error branch. Consumers who pass their own
WithPatchMaker(...)keep full control.Type of Change
Checklist