Skip to content

Commit

Permalink
feat: ensure the config is fully parsed
Browse files Browse the repository at this point in the history
Return an error otherwise.

This actually helped to find an error in 4.9 config (which is fixed).
Before the fix, the error looked like this:

> Error: unknown keys in config: [node."podman-catatonit-3.2.3-0.12.module+el8.4.0+14908+81312c48.x86_64".filter_images]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 11, 2023
1 parent 83f74ee commit 2eb1908
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/releases/4.9/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ filter_files = [
"/sbin/ldconfig",
]

# List of images to ignore.
filter_images = [ ]

# these node exceptions via rpm have been manually validated
[node."cri-o-1.22.5-20.rhaos4.9.gitdf6ec18.el8.x86_64"]
filter_files = [
Expand All @@ -39,9 +42,6 @@ filter_files = [ "/usr/bin/pinns" ]
[node."podman-catatonit-3.2.3-0.12.module+el8.4.0+14908+81312c48.x86_64"]
filter_files = [ "/usr/libexec/catatonit/catatonit" ]

# List of images to ignore.
filter_images = [ ]

# Payload Components

[payload.multus-cni-alt-container]
Expand Down
24 changes: 20 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,23 @@ func main() {
}
}

func getConfig(config *Config) error {
func getConfig(config *Config) (retErr error) {
var (
res toml.MetaData
err error
)

// Check if the configuration was fully parsed.
defer func() {
if retErr != nil {
return
}
un := res.Undecoded()
if len(un) != 0 {
retErr = fmt.Errorf("unknown keys in config: %+v", un)
}
}()

// Handle --config-for-version first.
if configForVersion != "" {
if configFile != "" {
Expand All @@ -226,7 +242,7 @@ func getConfig(config *Config) error {
if err != nil {
return err
}
_, err = toml.Decode(string(cfg), &config)
res, err = toml.Decode(string(cfg), &config)
if err != nil { // Should never happen.
panic("invalid embedded config: " + err.Error())
}
Expand All @@ -238,7 +254,7 @@ func getConfig(config *Config) error {
if file == "" {
file = defaultConfigFile
}
_, err := toml.DecodeFile(file, &config)
res, err = toml.DecodeFile(file, &config)
if err == nil {
klog.Infof("using config file: %v", file)
return nil
Expand All @@ -248,7 +264,7 @@ func getConfig(config *Config) error {
// defaultConfigFile is not found, fall back to embedded config.
if errors.Is(err, os.ErrNotExist) && configFile == "" {
klog.Info("using embedded config")
_, err = toml.Decode(embeddedConfig, &config)
res, err = toml.Decode(embeddedConfig, &config)
if err != nil { // Should never happen.
panic("invalid embedded config: " + err.Error())
}
Expand Down

0 comments on commit 2eb1908

Please sign in to comment.