Skip to content

Commit

Permalink
lxd/instance: Improve error messages for invalid configuration keys b…
Browse files Browse the repository at this point in the history
…ased on instance type

Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Dec 5, 2024
1 parent 24a8739 commit d325f4c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lxd/instance/instance_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ func ValidConfig(sysOS *sys.OS, config map[string]string, expanded bool, instanc
}

func validConfigKey(os *sys.OS, key string, value string, instanceType instancetype.Type) error {
if shared.StringHasPrefix(key, instancetype.ConfigKeyPrefixesContainer...) &&
instanceType == instancetype.VM {
return fmt.Errorf("%s isn't supported for VMs", key)
}

_, exists := instancetype.InstanceConfigKeysContainer[key]
if !exists && instanceType == instancetype.Container {
return fmt.Errorf("%s isn't supported for containers", key)
}

_, exists = instancetype.InstanceConfigKeysVM[key]
if !exists && instanceType == instancetype.VM {
return fmt.Errorf("%s isn't supported for VMs", key)
}

f, err := instancetype.ConfigKeyChecker(key, instanceType)
if err != nil {
return err
Expand All @@ -137,10 +152,6 @@ func validConfigKey(os *sys.OS, key string, value string, instanceType instancet
return err
}

if strings.HasPrefix(key, "limits.kernel.") && instanceType == instancetype.VM {
return fmt.Errorf("%s isn't supported for VMs", key)
}

if key == "raw.lxc" {
return lxcValidConfig(value)
}
Expand Down

0 comments on commit d325f4c

Please sign in to comment.