Disable compose-warning-logs if PODMAN_COMPOSE_WARNING_LOGS=false

Fixes: e62c928642ad ("Make podman-compose refer to podman-compose(1) when using an external provider")

- test: add coverage for PODMAN_COMPOSE_WARNING_LOGS

Signed-off-by: Petter Mikkelsen <43xhyr9m@anonaddy.me>
This commit is contained in:
Petter Mikkelsen
2024-07-30 12:06:11 +00:00
parent 2316d914b5
commit cfac059d14
2 changed files with 23 additions and 7 deletions

View File

@ -170,6 +170,18 @@ func composeEnv() ([]string, error) {
}, nil
}
// composeShouldLogWarning returns whether a notice on engine redirection should be piped to stderr regardless of logging configuration
func composeShouldLogWarning() (bool, error) {
if shouldWarnLogsEnv, ok := os.LookupEnv("PODMAN_COMPOSE_WARNING_LOGS"); ok {
if shouldWarnLogsEnvVal, err := strconv.ParseBool(shouldWarnLogsEnv); err == nil {
return shouldWarnLogsEnvVal, nil
} else if shouldWarnLogsEnv != "" {
return true, fmt.Errorf("PODMAN_COMPOSE_WARNING_LOGS should be a boolean: %w", err)
}
}
return registry.PodmanConfig().ContainersConfDefaultsRO.Engine.ComposeWarningLogs, nil
}
// underline uses ANSI codes to underline the specified string.
func underline(str string) string {
return "\033[4m" + str + "\033[0m"
@ -229,7 +241,11 @@ func composeHelp(cmd *cobra.Command) error {
return err
}
return composeProviderExec([]string{"--help"}, nil, nil, registry.PodmanConfig().ContainersConfDefaultsRO.Engine.ComposeWarningLogs)
shouldLog, err := composeShouldLogWarning()
if err != nil {
return err
}
return composeProviderExec([]string{"--help"}, nil, nil, shouldLog)
}
// composeMain is the main function of the compose command.
@ -249,5 +265,9 @@ func composeMain(cmd *cobra.Command, args []string) error {
return composeHelp(cmd)
}
return composeProviderExec(args, nil, nil, registry.PodmanConfig().ContainersConfDefaultsRO.Engine.ComposeWarningLogs)
shouldLog, err := composeShouldLogWarning()
if err != nil {
return err
}
return composeProviderExec(args, nil, nil, shouldLog)
}

View File

@ -295,11 +295,7 @@ else
fi
# hide annoying podman compose warnings, some tests want to check compose stderr and this breaks it.
CONTAINERS_CONF_OVERRIDE="$WORKDIR/containers.conf"
echo '[engine]
compose_warning_logs=false' > "$CONTAINERS_CONF_OVERRIDE"
export CONTAINERS_CONF_OVERRIDE
export PODMAN_COMPOSE_WARNING_LOGS=false
# Identify the tests to run. If called with args, use those as globs.
tests_to_run=()