From 9a54dadc447f65f866d395031ae03b7727c4ef2a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 24 Apr 2022 22:26:09 +0200 Subject: [PATCH] daemon/config: MergeDaemonConfigurations() don't validate intermediates MergeDaemonConfigurations was validating the configs before and after merging. However, the "fileConfig" configuration may contain only a "partial" configuration (options to apply to / override the existing config). This means that some options may not be set and contain default or empty values. Validating such partial configurations can produce validation failures, so to prevent those, we should validate the configuration _after_ merging, to validate the "final" state. There's more cleaning up / improvements to be made in this area; for example, we currently use our "self crafted" `getConflictFreeConfiguration()` function, which is used to detect options that are not allowed to be overridden, and which could potentially be handled by mergo.Merge(), but leaving those changes for a future exercise. This patch removes the first validation step, changing the function to only validate the resulting configuration after merging. Signed-off-by: Sebastiaan van Stijn --- daemon/config/config.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/daemon/config/config.go b/daemon/config/config.go index 038b13e348..5d15d95ab6 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -374,17 +374,12 @@ func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, config return nil, err } - if err := Validate(fileConfig); err != nil { - return nil, errors.Wrap(err, "configuration validation from file failed") - } - // merge flags configuration on top of the file configuration if err := mergo.Merge(fileConfig, flagsConfig); err != nil { return nil, err } - // We need to validate again once both fileConfig and flagsConfig - // have been merged + // validate the merged fileConfig and flagsConfig if err := Validate(fileConfig); err != nil { return nil, errors.Wrap(err, "merged configuration validation from file and command line flags failed") }