feat: [FEP-0001] add placement resource snapshot manager (1/) - #844
Open
Chen Yu (michaelawyu) wants to merge 4 commits into
Open
feat: [FEP-0001] add placement resource snapshot manager (1/)#844Chen Yu (michaelawyu) wants to merge 4 commits into
Chen Yu (michaelawyu) wants to merge 4 commits into
Conversation
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
Member
Author
|
Important:
|
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces the v1 Placement Resource Snapshot Manager for KubeFleet, adding snapshot creation/retrieval logic (including cache indexing and per-placement locking) and extending the dynamic informer manager with an explicit “is informer registered” check to avoid unintended informer creation.
Changes:
- Added a new
placementresourcesnapshotmanager (setup, locking, resource retrieval/hashing, snapshot ops, and name generation helpers). - Standardized labeling/annotation keys for placement resource snapshots and added accessor interfaces for placement policy/snapshot/binding types (namespaced + cluster-scoped).
- Enhanced the dynamic informer manager with
IsInformerSetand documented implicit informer-creation side effects.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/utils/informer/manager.go | Extends FakeManager to satisfy the updated informer Manager interface (IsInformerSet). |
| pkg/v1/managers/placementresourcesnapshot/uniquename.go | Adds snapshot unique-name generation with truncation + hash behavior. |
| pkg/v1/managers/placementresourcesnapshot/snapshots.go | Adds helpers to construct primary/secondary snapshot objects with labels/annotations and controller refs. |
| pkg/v1/managers/placementresourcesnapshot/resources.go | Implements selected-resource retrieval (cache-first) and deterministic hashing, plus snapshot-size grouping. |
| pkg/v1/managers/placementresourcesnapshot/ops.go | Implements latest-snapshot retrieval, up-to-date checks (dry-run), and snapshot creation/orphan cleanup. |
| pkg/v1/managers/placementresourcesnapshot/manager.go | Adds manager wiring, cache field indices, and per-placement sharded locking. |
| pkg/utils/informer/informermanager.go | Documents implicit informer creation and adds IsInformerSet implementation. |
| apis/kubefleet.dev/placement/v1alpha1/placementresourcesnapshot_types.go | Introduces labeling/annotation constants for placement resource snapshots. |
| apis/kubefleet.dev/placement/v1alpha1/interface.go | Adds accessor interfaces + implementations for placement policy/snapshot/binding resources. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+214
to
+225
| latestPrimarySnapshot := snapshots[len(snapshots)-1] | ||
| // Check if there are snapshots with the same index. | ||
| subIndexedSnapshotCntStr := latestPrimarySnapshot.GetLabels()[placementv1alpha1.SubIndexedPlacementResourceSnapshotCountLabelKey] | ||
| if subIndexedSnapshotCntStr == "1" { | ||
| // The primary placement resource snapshot is the only snapshot with the latest index; return it. | ||
| return []placementv1alpha1.PlacementResourceSnapshotAccessor{latestPrimarySnapshot}, nil | ||
| } | ||
| subIndexedSnapshotCnt, err := strconv.Atoi(subIndexedSnapshotCntStr) | ||
| if err != nil { | ||
| return nil, errors.NewUnexpectedError(err, "failed to convert sub-indexed placement resource snapshot count label to integer", | ||
| "placementResourceSnapshot", klog.KObj(latestPrimarySnapshot)) | ||
| } |
Comment on lines
+62
to
+65
| // `[PLACEMENT-POLICY-NAME-TRUNCATED]-resource-snapshot-[INDEX-TRUNCATED]-[HASH]`, | ||
| // | ||
| // where `[HASH]` is the first few characters of the hash of the value | ||
| // `[PLACEMENT-POLICY-NAME-TRUNCATED]-resource-snapshot-[SNAPSHOT-INDEX]-[SNAPSHOT-SUB-INDEX]`. |
Comment on lines
+53
to
+55
| // IsInformerSet returns if an informer has been set up for the given resource. | ||
| IsInformerSet(gvk schema.GroupVersionKind) bool | ||
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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 of your changes
This pull request introduces a new Placement Resource Snapshot Manager for KubeFleet, providing a robust foundation for managing placement resource snapshots. It also adds new accessor interfaces for placement-related resources, constants for snapshot labeling, and improvements to the informer manager utility. The changes enhance modularity, maintainability, and clarity in handling placement resource snapshots and their indices.
The most important changes are:
Placement Resource Snapshot Manager:
Managerinpkg/v1/managers/placementresourcesnapshot/manager.goresponsible for managing placement resource snapshots, including setup of custom field indices for efficient querying and per-placement-policy locking for concurrency control.primaryPlacementResourceSnapshotandsecondaryPlacementResourceSnapshot) inpkg/v1/managers/placementresourcesnapshot/snapshots.gofor constructing and labeling snapshot resources with proper controller references.Placement Resource Snapshot Labeling and Accessors:
apis/kubefleet.dev/placement/v1alpha1/placementresourcesnapshot_types.gofor standardized snapshot labeling and annotation, enabling consistent identification and management of placement resource snapshots and their indices/sub-indices.apis/kubefleet.dev/placement/v1alpha1/interface.goto provide unified access to the spec and status of placement policies, resource snapshots, and bindings for both namespace-scoped and cluster-scoped resources.Informer Manager Utility Improvements:
pkg/utils/informer/informermanager.goby documenting side effects of implicit informer creation, adding anIsInformerSetmethod to check if an informer is set up for a resource, and implementing the method for safer informer usage. [1] [2] [3]Related to #787
I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
For size control reasons, tests have been skipped in this PR. Will add in subsequent PRs.
Special notes for your reviewer