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

VM: Move check for container-specific prefixed keys applied to VMs up #14680

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

kadinsayani
Copy link
Contributor

This PR fixes the following regression:
https://github.com/canonical/lxd-ci/actions/runs/12367790805/job/34516721509#step:11:93.

We always need to check config keys applied to VM's to ensure container-specific prefixed keys are disallowed.

@kadinsayani kadinsayani changed the title lxd/instance: Move check for container-specific prefixed keys applied to VMs up VM: Move check for container-specific prefixed keys applied to VMs up Dec 17, 2024
if instanceType == instancetype.VM && shared.StringHasPrefix(key, instancetype.ConfigKeyPrefixesContainer...) {
return fmt.Errorf("%q isn't supported for %q", key, instanceType)
}

// Check if the key is a valid prefix and whether or not it requires a subkey.
knownPrefixes := append(instancetype.ConfigKeyPrefixesAny, instancetype.ConfigKeyPrefixesContainer...)
if strings.HasSuffix(key, ".") {
Copy link
Member

@simondeziel simondeziel Dec 17, 2024

Choose a reason for hiding this comment

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

Shouldn't we simply reject anything that ends with a trailing . as that's never going to be a valid config key anyway so why bother doing more checks?

Copy link
Contributor Author

@kadinsayani kadinsayani Dec 17, 2024

Choose a reason for hiding this comment

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

We can do that, however, the additional check allows us to return more specific error messages:
"Unknown configuration key: %q" if the key is not known and "%q requires a subkey" if the key is known but missing a subkey. Also, the check is pretty inexpensive computationally since the knownPrefixes slice is only 5 elements.

@tomponline tomponline merged commit e19037e into canonical:main Dec 17, 2024
27 checks passed
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.

3 participants