Skip to content

[sig-migrate]Add object apiversion check#364

Merged
ldmonster merged 2 commits into
mainfrom
sig-migrate-fix
May 21, 2026
Merged

[sig-migrate]Add object apiversion check#364
ldmonster merged 2 commits into
mainfrom
sig-migrate-fix

Conversation

@Suselz
Copy link
Copy Markdown
Member

@Suselz Suselz commented May 21, 2026

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 as v1alpha1).

Signed-off-by: suselz <suselz@mail.ru>
@Suselz Suselz self-assigned this May 21, 2026
@Suselz Suselz requested a review from ldmonster as a code owner May 21, 2026 14:15
@ldmonster ldmonster requested a review from Copilot May 21, 2026 14:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 collectAllObjects to 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.

Comment thread internal/tools/sigmigrate/sigmigrate.go
Signed-off-by: suselz <suselz@mail.ru>
@ldmonster ldmonster requested a review from Copilot May 21, 2026 15:06
@ldmonster ldmonster merged commit 4de25a8 into main May 21, 2026
5 checks passed
@ldmonster ldmonster deleted the sig-migrate-fix branch May 21, 2026 15:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

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
}
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.

3 participants