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 API types for configuration metadata #14132

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

Conversation

markylaing
Copy link
Contributor

This is so that we can manage configuration metadata with API extensions as we do with any other API response over /1.0

  • Adds an API extension for adding entity metadata to GET /1.0/configuration/metadata.
  • Adds types under shared/api for configuration metadata.
  • Updates entity metadata such that each entity maps to a JSON object, with requires_project and entitlements fields.
  • Enforces that generated metadata conforms to the new API type.
  • Updates the swagger doc for GET /1.0/configuration/metadata to include the newly defined type.

@markylaing markylaing self-assigned this Sep 19, 2024
@github-actions github-actions bot added Documentation Documentation needs updating API Changes to the REST API labels Sep 19, 2024
Copy link

Heads up @mionaalex - the "Documentation" label was applied to this issue.

kadinsayani
kadinsayani previously approved these changes Sep 19, 2024
Copy link
Contributor

@kadinsayani kadinsayani left a comment

Choose a reason for hiding this comment

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

LGTM - thanks!

@@ -285,7 +253,7 @@ func parse(path string, outputJSONPath string, excludedPaths []string, substitut
continue
}

configKeyEntry[metadataMap["key"]].(map[string]any)[dataKVMatch[1]] = detectType(dataKVMatch[2])
configKeyEntry[metadataMap["key"]].(map[string]any)[dataKVMatch[1]] = dataKVMatch[2]
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this change.

Where is the value in dataKVMatch[2] coming from?

As for how these are classified, whilst I agree that all config values are strings, my understanding of the metadata definition here is in order to indicate in the docs what sort of string values are allowed for a particular config key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like dataKVMatch is coming from this regular expression (?m)([\S]+):[\s]+([\S \"\']+) on the key value section of the lxdmeta:generate section of the doc block e.g.:

type: string
defaultdesc: `auto`
liveupdate: no
shortdesc: What to do when evacuating the instance

In this example, the first dataKVMatch outputted from lxdDocDataRegex.FindAllStringSubmatch(data, -1) would have

dataKVMatch[1] -> "type"
dataKVMatch[2] -> "string"

My feeling is that lxd-generate shouldn't be too clever about figuring out which config keys are which type. We should just include that in the description of the key. There is only one config key for which this appears to work.

Copy link
Member

Choose a reason for hiding this comment

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

There is only one config key for which this appears to work.
which one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The commit directly after this change shows the result of make update-metadata. Only one field is changed: 2614bb5#diff-d3459341f992192c3b18b6130aa7e165d305183794a84f219c7ab7512b1b31bcL4316

It is changing the value of defaultdesc from a boolean true to a string "true".

@@ -309,6 +309,13 @@ func parse(path string, outputJSONPath string, excludedPaths []string, substitut
return nil, fmt.Errorf("Error while marshaling project documentation: %v", err)
}

// Validate that what we've generated is valid against our API definition.
var metadataConfiguration api.MetadataConfiguration
Copy link
Member

Choose a reason for hiding this comment

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

nice touch

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

Apart from the data type change at the start, this seems all good.

@tomponline
Copy link
Member

needs a rebase.

@edlerd are you happy with this change btw?

Signed-off-by: Mark Laing <mark.laing@canonical.com>
They may be something like "true", but this is still a string.

Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
This includes adding the `requires_project` field, which will be required
for validating `lxc auth permission add/remove` command arguments.

Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
…finition.

Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
@markylaing
Copy link
Contributor Author

needs a rebase.

Done 👍

@edlerd
Copy link
Contributor

edlerd commented Sep 25, 2024

@edlerd are you happy with this change btw?

Happy is a big word for a change breaking our integration ;-) It looks all right to me.

One concern is the project_specific field being boolean. It seems not 100% correct, as some entities can be project specific or not, depending on how the project is set up. So IMHO for networks there should be a third option depends and the project_specific field be modelled as non-binary.

@markylaing
Copy link
Contributor Author

@edlerd are you happy with this change btw?

Happy is a big word for a change breaking our integration ;-) It looks all right to me.

One concern is the project_specific field being boolean. It seems not 100% correct, as some entities can be project specific or not, depending on how the project is set up. So IMHO for networks there should be a third option depends and the project_specific field be modelled as non-binary.

I'm a bit confused about this, does this relate to the features.* config on a project?

@edlerd
Copy link
Contributor

edlerd commented Sep 25, 2024

I'm a bit confused about this, does this relate to the features.* config on a project?

Yes, exactly. You can share a network between all projects, so it is not really project specific. Or you can enable the features.networks option on a project, and then the networks created in that project are project specific.

@markylaing
Copy link
Contributor Author

I'm a bit confused about this, does this relate to the features.* config on a project?

Yes, exactly. You can share a network between all projects, so it is not really project specific. Or you can enable the features.networks option on a project, and then the networks created in that project are project specific.

I guess this is a difference in phrasing. When a network is "shared" it is just a network in the default project. It's still project specific because it is in the default project.

Let's say you create project "foo" with features.networks=false and lxdbr0 is available. lxdbr0 is still in the default project, so while lxc network show lxdbr0 --project foo would work, lxc auth group permission add <group> network lxdbr0 can_view project=foo would not work because the network is not truly in the foo project.

@markylaing
Copy link
Contributor Author

I'm a bit confused about this, does this relate to the features.* config on a project?

Yes, exactly. You can share a network between all projects, so it is not really project specific. Or you can enable the features.networks option on a project, and then the networks created in that project are project specific.

I guess this is a difference in phrasing. When a network is "shared" it is just a network in the default project. It's still project specific because it is in the default project.

Let's say you create project "foo" with features.networks=false and lxdbr0 is available. lxdbr0 is still in the default project, so while lxc network show lxdbr0 --project foo would work, lxc auth group permission add <group> network lxdbr0 can_view project=foo would not work because the network is not truly in the foo project.

Project features have been a real headache for fine-grained authorization for this reason. I've added a warning to the documentation on this: https://documentation.ubuntu.com/lxd/en/latest/explanation/projects/#isolation-of-projects.

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.

4 participants