Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable compose_warning_logs if PODMAN_COMPOSE_WARNING_LOGS=false #23442

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions cmd/podman/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}
6 changes: 1 addition & 5 deletions test/compose/test-compose
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand Down