-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add source_file to incus_image #169
Conversation
internal/image/resource_image.go
Outdated
// NOTE: this does not seem to have an effect | ||
// imageAliases := make([]api.ImageAlias, 0, len(aliases)) | ||
// for _, alias := range aliases { | ||
// // Ensure image alias does not already exist. | ||
// aliasTarget, _, _ := server.GetImageAlias(alias) | ||
// if aliasTarget != nil { | ||
// resp.Diagnostics.AddError(fmt.Sprintf("Image alias %q already exists", alias), "") | ||
// return | ||
// } | ||
|
||
// ia := api.ImageAlias{ | ||
// Name: alias, | ||
// } | ||
|
||
// imageAliases = append(imageAliases, ia) | ||
// } | ||
// image.Aliases = imageAliases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expected incus to respect the Aliases
provided in the api.ImagesPost
request, but this is currently not the case. Therefore I added the aliases manually, see https://github.com/lxc/terraform-provider-incus/pull/169/files#diff-dedceb2079bdc5668f6c75a9b22a13d869a760a187b2804ac22f83eeac6d50e7R611
Not sure, about the correct thing to do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure the server does, but the client code wants the extra Aliases passed through args.Aliases ImageCopyArgs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lxc/incus#1409 switches our CLI client to actually using this feature and it seems to be working just fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean with it does not respect the aliases provided? because when I set the aliases in a incus_image
then I see those created:
resource "incus_image" "alpine" {
project = "default"
aliases = ["alpine", "alpine/edge"]
source_image = {
remote = "images"
name = "alpine/edge"
type = "container"
architecture = "aarch64"
}
}
$ incus image list
+-----------------+--------------+--------+------------------------------------+--------------+-----------+---------+----------------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCHITECTURE | TYPE | SIZE | UPLOAD DATE |
+-----------------+--------------+--------+------------------------------------+--------------+-----------+---------+----------------------+
| alpine (1 more) | 57c20fddd750 | no | Alpine edge arm64 (20241119_13:00) | aarch64 | CONTAINER | 3.31MiB | 2024/11/22 22:50 CET |
+-----------------+--------------+--------+------------------------------------+--------------+-----------+---------+----------------------+
$ incus image list -f json | jq .[].aliases
[
{
"name": "alpine",
"description": ""
},
{
"name": "alpine/edge",
"description": ""
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the import from source_file
with inucs from main
branch (including lxc/incus#1409) and the acceptance test is not successful, if I use the commented out section from above without the manual adding of the aliases.
The reason in my opinion is, that the import from_source
file does use client.CreateImage
directly and this function does still not respect the Aliases
. The fix from lxc/incus#1409 does change it for incus image copy
, but not for incus image import
. There it is still done as part of the code of the cmd in the incus cli and not in the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, that's because incus image import
doesn't get to send an API struct to the server as we instead send raw image data and rely on headers for the rest.
So having the logic applying the aliases after import makes sense.
We should be able to extend the API to allow for aliases to be passed as HTTP headers too but that still won't be as flexible if we ever want to support alias re-use like we do in the CLI now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stgraber thanks for the addition in lxc/incus#1434. This will become available with incus 6.8, which is not yet released. But for now, this is not available and I assume, that the incus terraform provider should also be backwards compatible and work with older versions of incus. Therefore I assume, that we stick to the current implementation. Do you agree?
CC: @maveonair
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally I'd agree but given that this is a new feature which won't be in a stable version of the provider for another few weeks, combined with Incus 6.8 being released next week, I think we can just rely on it.
On the Incus side, only the latest release is supported so 6.7 will no longer be officially supported once 6.8 comes out. The exception there is the LTS release, but 6.0.3 will come out a week after 6.8 and will include this API improvement, so we'll have it everywhere we care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I updated the code to use aliases directly for the new feature and I successfully tested the change locally with incus from main
and a go.work
setup, such that the terraform provider also uses incus from main.
The tests in CI now fail, since the terraform provider is still using the old version of incus: https://github.com/lxc/terraform-provider-incus/actions/runs/12134741456/job/33832497665?pr=169#step:8:157
@stgraber there are some more locations, where the aliases are set explicitly instead of using the aliases from api.ImagesPost
.
532ca52
to
cc4f4fc
Compare
ee40de2
to
80b786c
Compare
@maveonair I know, this PR is still in draft, but it works on my machine as well as in CI and therefore I would appreciate some feedback, especially if I have missed something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@breml Very well done!
|
@stgraber Yes, I know. I commented about this in #169 (comment) |
Ah, right, that makes sense, though the Terraform error here is absolutely horrible ;) |
PR blocked until Incus 6.8 is out. |
Incus 6.8 is release: https://github.com/lxc/incus/releases/tag/v6.8.0 |
Head branch was pushed to by a user without write access
CI pipeline is currently failing, because virtualization tests can not run on GH actions, see also: https://github.com/lxc/terraform-provider-incus/pull/186/files#r1886242549 |
@breml Please merge |
Signed-off-by: Lucas Bremgartner <lucas.bremgartner@futurfusion.io>
Signed-off-by: Lucas Bremgartner <lucas.bremgartner@futurfusion.io>
Signed-off-by: Lucas Bremgartner <lucas.bremgartner@futurfusion.io>
@maveonair I rebased on |
Resolves: #125