[sig-migrate]Add object apiversion check#364
Merged
Merged
Conversation
Signed-off-by: suselz <suselz@mail.ru>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the sig-migrate object discovery/collection logic to prefer each API group’s preferred version when the same resource is discoverable under multiple versions, ensuring resources like NodeGroup are migrated via the intended API version (e.g., deckhouse.io/v1 instead of v1alpha1).
Changes:
- Added API-group preferred-version extraction (
preferredVersionByGroup) and collection upsert logic (upsertCollectedObject) to select the preferred GVR version per group. - Updated
collectAllObjectsto use the upsert logic instead of blindly overwriting collected objects. - Added unit tests covering preferred-version mapping and preferred-version selection behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/tools/sigmigrate/sigmigrate.go |
Adds preferred-version selection and upsert logic during object collection to preserve the preferred API version for resources. |
internal/tools/sigmigrate/sigmigrate_test.go |
Adds tests validating preferred-version extraction and that collection prefers the preferred API version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: suselz <suselz@mail.ru>
ldmonster
approved these changes
May 21, 2026
Comment on lines
92
to
96
| 1. **Resource Collection**: The command uses Kubernetes API discovery to automatically discover all available resources (both namespaced and cluster-wide). | ||
|
|
||
| 2. **Optional Object Filter**: If `--object` is specified, the command skips full resource fetching/listing and processes only the matching object (`namespace/name/kind`). | ||
| 2. **Optional Object Filter**: If `--object` is specified, the command skips full resource fetching/listing and processes matching object(s) by `namespace/name/resource`. If multiple API groups contain the same `namespace/name/resource`, all matching entries are selected. | ||
|
|
||
| 3. **Adding Annotation**: For each selected resource, an annotation `d8-migration=<timestamp>` is added, where `timestamp` is the current time in Unix timestamp format. |
Comment on lines
1078
to
+1082
| filtered := make(map[string]ObjectRef) | ||
| if object, exists := objects[key]; exists { | ||
| filtered[key] = object | ||
| for key, object := range objects { | ||
| if object.Namespace == namespace && object.Name == name && object.Kind == kind { | ||
| filtered[key] = object | ||
| } |
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.
This change makes sig-migrate select and preserve the correct API version for each resource during discovery and annotation, so objects like NodeGroup are migrated via their preferred version (for example,
deckhouse.io/v1) instead of an arbitrary discovered version (such asv1alpha1).