From fed5f9d498f2c7ecde149c13751624403d5d2899 Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Thu, 19 Dec 2024 12:23:35 -0700 Subject: [PATCH] lxc/completion: Fix `cmpInstanceSetKeys` to return set instance config keys This commit fixes `cmpInstanceSetKeys` to return any set instance configuration key rather than just keys with known prefixes. We don't need to validate type here since a VM specific config key cannot be set for a container, and vice-versa, and we only return config keys that show up in an instance's full config. Signed-off-by: Kadin Sayani (cherry picked from commit 4307f76a10d83d5e67d8be7161d35e9808b2d354) --- lxc/completion.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lxc/completion.go b/lxc/completion.go index d70348c0cea6..f3850b2d85d4 100644 --- a/lxc/completion.go +++ b/lxc/completion.go @@ -359,8 +359,6 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She return nil, cobra.ShellCompDirectiveError } - instanceType := instance.Type - // Fetch all config keys that can be set by a user based on instance type. allInstanceConfigKeys, _ := g.cmpInstanceKeys(instanceName) @@ -377,12 +375,9 @@ func (g *cmdGlobal) cmpInstanceSetKeys(instanceName string) ([]string, cobra.She for configKey := range instance.Config { // We only want to return the intersection between allInstanceConfigKeys and configKeys to avoid returning the full instance config. _, exists := keySet[configKey] - if exists { - if shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixesAny...) { - configKeys = append(configKeys, configKey) - } else if instanceType == string(api.InstanceTypeContainer) && shared.StringHasPrefix(configKey, instancetype.ConfigKeyPrefixesContainer...) { - configKeys = append(configKeys, configKey) - } + knownPrefixes := append(instancetype.ConfigKeyPrefixesAny, instancetype.ConfigKeyPrefixesContainer...) + if exists || strings.HasPrefix(configKey, instancetype.ConfigVolatilePrefix) || shared.StringHasPrefix(configKey, knownPrefixes...) { + configKeys = append(configKeys, configKey) } }