fix read-only resource extractors observing the empty desired base#116
Merged
Conversation
) readResource fetched the cluster object into a deep copy that was then discarded; BaseResource.ExtractData re-deep-copied DesiredObject, so extractors on read-only resources only ever saw the inert base used to build the resource. Add concepts.ObservationRecorder, implement it on BaseResource, and have readResource invoke RecordObservation after Get so the fetched object is visible to subsequent extractors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a framework bug where data extractors on read-only resources observed the empty “desired base” object instead of the object fetched from the cluster (issue #115). The PR introduces an observation-recording hook so the fetched object is recorded back onto the resource before subsequent inspection (notably data extraction) occurs, and updates docs/tests accordingly.
Changes:
- Add
concepts.ObservationRecorderand implementRecordObservation(observed client.Object) errorongeneric.BaseResource. - Update the read-only fetch path (
readResource) to callRecordObservationafterclient.Get, enabling extractors to observe live cluster state. - Add unit/integration tests and update documentation/GoDoc to reflect the new behavior and forwarding requirement for custom wrappers.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/generic/resource_static_test.go | Adds unit coverage verifying RecordObservation makes observed state visible to ExtractData and rejects wrong types. |
| pkg/generic/resource_base.go | Implements RecordObservation by storing the observed typed object; clarifies ExtractData semantics for managed vs read-only. |
| pkg/generic/builder_base.go | Updates WithDataExtractor GoDoc to describe managed vs read-only extractor inputs and idempotency expectations. |
| pkg/component/zz_mock_resource_test.go | Adds a mock resource type implementing RecordObservation for component tests. |
| pkg/component/read.go | Calls RecordObservation after fetching a read-only resource from the cluster. |
| pkg/component/read_test.go | Adds integration tests ensuring readResource records observations and propagates recorder errors with resource identity context. |
| pkg/component/concepts/observable.go | Introduces the ObservationRecorder interface and its contract. |
| docs/custom-resource.md | Updates wrapper guidance and “Typical Methods” table to include RecordObservation forwarding for read-only extractor support. |
| docs/component.md | Updates Phase 4 lifecycle docs to include observation recording before extraction for read-only resources. |
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.
Summary
readResourcefetched the cluster object into a deep copy that was then discarded;BaseResource.ExtractDatare-deep-copiedDesiredObject, so extractors on read-only resources only ever saw the inert base used to build the resource. Documented in Read-only resource extractors receive the empty desired-object base, not the fetched cluster object #115.concepts.ObservationRecorderwithRecordObservation(observed client.Object) error, implement it onBaseResource, and invoke it fromreadResourceafterGetso the fetched object is visible to subsequent extractors. Resources built fromgeneric.BaseResourcepick this up automatically; custom wrappers that want read-only extractor support forward the method to their base.WithDataExtractorGoDoc, the Phase 4 description indocs/component.md, and the custom-resource guide so the new method shows up in the typical-methods table and example wrapper.Closes #115.
Test plan
make all(lint, fmt, full unit suite, example builds) clean.pkg/generic/resource_static_test.goprovesBaseResource.RecordObservationmakes the observed object visible toExtractData, and rejects wrong-type input.pkg/component/read_test.goprovereadResourceinvokesRecordObservationwith the populated cluster object and that errors from it propagate with resource identity context.WithDataExtractorcapturingsecret.DataHashconfirms rotation triggers downstream rollouts.🤖 Generated with Claude Code