Skip to content

fix: patch fallback json merge#285

Merged
pepov merged 9 commits into
cisco-open:masterfrom
csatib02:fix/patch-fallback-json-merge
May 19, 2026
Merged

fix: patch fallback json merge#285
pepov merged 9 commits into
cisco-open:masterfrom
csatib02:fix/patch-fallback-json-merge

Conversation

@csatib02

Copy link
Copy Markdown
Contributor

Description

Resources whose Go types use a custom MarshalJSON that hoists map entries to
top-level JSON keys — most notably opentelemetry-operator's AnyConfig fail reflective strategic-merge inside k8s-objectmatcher with:

unable to find api field in struct AnyConfig for the json field "prometheus/message_metrics_exporter"

When PatchMaker.Calculate returns an error, ReconcileResource skips the
patchResult.IsEmpty() "resource is in sync" short-circuit and issues a full
Client.Update(...) on every reconcile. The result is a generation bump on
the 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:

DEBUG could not match objects {"error": "Failed to generate strategic merge patch: unable to find api field in struct AnyConfig for the json field \"prometheus/message_metrics_exporter\""}

This PR introduces FallbackPatchMaker, a thin wrapper around any patch.Maker
that 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 of
operator-tools picks 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.

  • Also bumped go version to 1.25.0 and go.mod dependencies.
  • Ran go.fix.

Type of Change

  • Bug Fix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@csatib02 csatib02 changed the title Fix/patch fallback json mergea fix: patch fallback json merge May 18, 2026
@csatib02 csatib02 force-pushed the fix/patch-fallback-json-merge branch from ea2b99a to faa2d68 Compare May 18, 2026 19:43
pepov
pepov previously approved these changes May 18, 2026
@csatib02 csatib02 force-pushed the fix/patch-fallback-json-merge branch from faa2d68 to fd1c0b8 Compare May 18, 2026 19:45
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
@csatib02 csatib02 force-pushed the fix/patch-fallback-json-merge branch from fd1c0b8 to 5edf371 Compare May 19, 2026 08:45
csatib02 added 8 commits May 19, 2026 10:46
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>
@csatib02 csatib02 force-pushed the fix/patch-fallback-json-merge branch from 5edf371 to 3c7806f Compare May 19, 2026 08:46
@pepov pepov merged commit b0604f2 into cisco-open:master May 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants