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

Add source_file to incus_image #169

Merged
merged 3 commits into from
Dec 17, 2024
Merged

Add source_file to incus_image #169

merged 3 commits into from
Dec 17, 2024

Conversation

breml
Copy link
Collaborator

@breml breml commented Nov 20, 2024

Resolves: #125

Comment on lines 570 to 599
// 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
Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member

@maveonair maveonair Nov 22, 2024

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": ""
  }
]

Copy link
Collaborator Author

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 mainbranch (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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Collaborator Author

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.

@breml breml force-pushed the issue-125 branch 2 times, most recently from 532ca52 to cc4f4fc Compare November 20, 2024 11:01
@breml breml force-pushed the issue-125 branch 2 times, most recently from ee40de2 to 80b786c Compare November 21, 2024 08:15
@breml
Copy link
Collaborator Author

breml commented Nov 22, 2024

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

@breml breml marked this pull request as ready for review November 26, 2024 06:37
@breml breml requested review from stgraber and maveonair November 26, 2024 06:41
Copy link
Member

@maveonair maveonair left a 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!

@breml breml requested a review from stgraber December 3, 2024 07:29
@stgraber stgraber enabled auto-merge December 4, 2024 02:32
@stgraber
Copy link
Member

stgraber commented Dec 4, 2024

=== RUN   TestAccImage_sourceFileSplitImage
    resource_image_test.go:336: Step 3/3 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to incus_image.from_file, provider
        "provider[\"registry.terraform.io/hashicorp/incus\"]" produced an unexpected
        new value: .aliases: was cty.SetVal([]cty.Value{cty.StringVal("able-snail"),
        cty.StringVal("teaching-spider")}), but now null.
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccImage_sourceFileSplitImage (7.01s)
=== RUN   TestAccImage_sourceFileUnifiedImage
    resource_image_test.go:385: Step 2/2 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to incus_image.from_file, provider
        "provider[\"registry.terraform.io/hashicorp/incus\"]" produced an unexpected
        new value: .aliases: was
        cty.SetVal([]cty.Value{cty.StringVal("destined-skylark"),
        cty.StringVal("sharing-terrier")}), but now null.
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccImage_sourceFileUnifiedImage (6.88s)

@breml
Copy link
Collaborator Author

breml commented Dec 4, 2024

=== RUN   TestAccImage_sourceFileSplitImage
    resource_image_test.go:336: Step 3/3 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to incus_image.from_file, provider
        "provider[\"registry.terraform.io/hashicorp/incus\"]" produced an unexpected
        new value: .aliases: was cty.SetVal([]cty.Value{cty.StringVal("able-snail"),
        cty.StringVal("teaching-spider")}), but now null.
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccImage_sourceFileSplitImage (7.01s)
=== RUN   TestAccImage_sourceFileUnifiedImage
    resource_image_test.go:385: Step 2/2 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to incus_image.from_file, provider
        "provider[\"registry.terraform.io/hashicorp/incus\"]" produced an unexpected
        new value: .aliases: was
        cty.SetVal([]cty.Value{cty.StringVal("destined-skylark"),
        cty.StringVal("sharing-terrier")}), but now null.
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccImage_sourceFileUnifiedImage (6.88s)

@stgraber Yes, I know. I commented about this in #169 (comment)

@stgraber
Copy link
Member

stgraber commented Dec 4, 2024

Ah, right, that makes sense, though the Terraform error here is absolutely horrible ;)

@stgraber stgraber added the Blocked Waiting on an external task label Dec 4, 2024
@stgraber
Copy link
Member

stgraber commented Dec 4, 2024

PR blocked until Incus 6.8 is out.

@breml
Copy link
Collaborator Author

breml commented Dec 16, 2024

Incus 6.8 is release: https://github.com/lxc/incus/releases/tag/v6.8.0

auto-merge was automatically disabled December 16, 2024 05:55

Head branch was pushed to by a user without write access

@breml breml mentioned this pull request Dec 16, 2024
@breml
Copy link
Collaborator Author

breml commented Dec 16, 2024

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 breml removed the Blocked Waiting on an external task label Dec 16, 2024
@maveonair
Copy link
Member

@breml Please merge origin main or rebase from origin main to get the latest fixes required for CI/CD to work.

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>
@breml
Copy link
Collaborator Author

breml commented Dec 17, 2024

@maveonair I rebased on origin main.

@stgraber stgraber merged commit 28f59a5 into lxc:main Dec 17, 2024
10 checks passed
@breml breml deleted the issue-125 branch December 17, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add source_file to incus_image
3 participants