Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxd: Fix target profile on snapshot copy #15155

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

skozina
Copy link

@skozina skozina commented Mar 10, 2025

Fixes #15078

lxd/instance.go Outdated
@@ -397,7 +397,7 @@ func instanceCreateAsCopy(s *state.State, opts instanceCreateAsCopyOpts, op *ope
Description: srcSnap.Description(),
Ephemeral: srcSnap.IsEphemeral(),
Name: newSnapName,
Profiles: srcSnap.Profiles(),
Profiles: opts.targetInstance.Profiles,
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @skozina this indeed looks like the culprit.

I'm slightly concerned that this is going to change the default behaviour where previously the historic profiles were retained within each snapshot, but now we are going to update each copied snapshot to use the same profiles as request by the client (or default if not specified at all as per line 1158 in instances_post.go).

This is a classic example of existing historical behaviour not being well defined, and so the "correct thing" to do is not always clear. Some users may be expecting the existing behaviour, as we aim to not alter snapshots where possible.

The question here I suppose can be more concisely stated as:

Do the --profile and --no-profiles flags refer to just the main instance or the main instance and its snapshots?

I've run out of time now as have a meeting, but we can discuss more later on.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for quick review!
Yes, I'm not sure what's the best way to proceed. I suppose the best "fix" would be to only fix the behavior if some explicit flags are specified by the user. Ie. apply to target instance profiles only if the --no-profiles was specified. I'm not sure if we can detect such case as the arguments are not passed to lxd, and I'm not sure if the "empty profiles list" is a definitive indication if the --no-profiles was specified?
Lets talk later. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Yes, its made more difficult by the fact that the lxc CLI is responsible for retrieving the current instance's profiles and then populating that list for the new instance, so the lxd server doesn't know if that list has been explicitly set by the user or is coming from the source instance.

Copy link
Member

Choose a reason for hiding this comment

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

A similar issue exists for snapshot config:

https://github.com/canonical/lxd/pull/15155/files#diff-272a0e97fc7cdf4bb7a22457a8bf507889f75f3b6df9689074820b8c1168e4feL393
https://github.com/canonical/lxd/pull/15155/files#diff-272a0e97fc7cdf4bb7a22457a8bf507889f75f3b6df9689074820b8c1168e4feL396

api.InstanceSource (which is used in api.InstancesPost as the Source field when copying/migrating instances) has the InstanceOnly field indicating to copy only the main volume and not snapshots from the source.

I wonder if we could add a field to api.InstanceSource with an API extension to alter how copies/migrations treat snapshot config (profiles, local config and local devices).

Copy link
Member

Choose a reason for hiding this comment

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

Got another meeting to attend now, but this is where im at currently...

@tomponline tomponline marked this pull request as draft March 11, 2025 14:11
@tomponline
Copy link
Member

converted to draft until we figure out approach.

@github-actions github-actions bot added Documentation Documentation needs updating API Changes to the REST API labels Mar 14, 2025
@skozina skozina force-pushed the ersin-issue15078 branch 2 times, most recently from d11069c to 88c2549 Compare March 14, 2025 14:47
@skozina skozina marked this pull request as ready for review March 14, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes to the REST API Documentation Documentation needs updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot copy an instance that has snapshots across projects
2 participants