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

DB: Fix update-schema to support lxd in non-GOPATH locations #14704

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

tomponline
Copy link
Member

No description provided.

@tomponline tomponline self-assigned this Dec 20, 2024
@tomponline tomponline changed the title DB: Fix update-schema support lxd in non-GOPATH locations DB: Fix update-schema to support lxd in non-GOPATH locations Dec 20, 2024
if strings.HasPrefix(filename, "github.com") {
filename = filepath.Join(os.Getenv("GOPATH"), "src", filename)
filename = strings.TrimPrefix(filename, "github.com/canonical/lxd/lxd/db/")
Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly I'm finding it strange that this is required at all.

As far as I can tell, schema generation is only used by LXD and not any consumers or lxd-generate (microcloud, microceph, etc.), they only use it for query generation.

lxd-generate is directly importing

	"github.com/canonical/lxd/lxd/db/cluster"
	"github.com/canonical/lxd/lxd/db/node"

to call cluster.SchemaDotGo and node.SchemaDotGo for generating schemas.

I think it'd be easier to reason about if we take this out of lxd-generate and have a small go program call these functions and input the exact filepath we want.

Copy link
Member Author

Choose a reason for hiding this comment

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

@markylaing @masnax tells me that its used by micro* too.

Copy link
Member Author

@tomponline tomponline Dec 20, 2024

Choose a reason for hiding this comment

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

I'm happy to have it reworked, but we need it to be working now (its broken right now and blocking a PR), and I dont have time to focus on a larger rework right now im afraid. But we can follow up with a better refactor if you have time for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@markylaing for context it was broken in this commit 63b017e

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it'd be easier to reason about if we take this out of lxd-generate and have a small go program call these functions and input the exact filepath we want.

I dont follow you. It's lxd-generate's job to update these files?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could increase the specificity of if strings.HasPrefix(filename, "github.com") { to check for github.com/canonical/lxd/lxd/db/ if you think that would help with microcloud usage?

Copy link
Contributor

Choose a reason for hiding this comment

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

@masnax tells me that its used by micro* too.

micro* may be using query generation but I don't see how it's possible that they're using lxd-generate schema since it doesn't take any arguments, it only generates the LXD schema.

I've just seen the thread for this (I didn't realise it was blocking a PR) so will approve for now and we can discuss more in the new year :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

micro* may be using query generation but I don't see how it's possible that they're using lxd-generate schema since it doesn't take any arguments, it only generates the LXD schema.

You may well be right, all I got from @masnax so far that gave me that impression was:

One small issue might be with goimports which does not properly handle non-v1/v0 go module packages. But that wouldn't affect LXD, only Micro*, which also use lxd-generate

@tomponline tomponline merged commit a5439fb into canonical:main Dec 20, 2024
26 checks passed
@tomponline tomponline deleted the tp-lxd-schema branch December 20, 2024 10:26
tomponline added a commit that referenced this pull request Dec 20, 2024
This is an alternative to #14704 

I didn't understand why `runtime.Caller` was required. It was because of
where the `SchemaDotGo` functions were defined in the `node` and
`cluster` packages.

We can instead just split the `go:generate` directives into their
respective packages so that invocation there will cause the `schema.go`
files to be created in the current directory.

As an aside, since `lxd-generate` is used by `micro*` packages, I'd also
be in favour of removing the `schema` subcommand from it, as it only
supports generating the LXD node or cluster schemas.
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.

2 participants