getporter/porter

porter credentials apply outputs to stderr even when successful

Closed this issue · 4 comments

porter credentials apply command outputs the message "Applied <namespace/credentials set name> credential set" to stderr instead of stdout. This is especially problematic when Porter is used in DevOps pipelines as they are typically set to fail if there is any output in stderr.

Tested with version porter v1.0.15 (be5c66a9).

Steps to reproduce the behavior

  1. Have a credentials file ready
  2. Run the command: porter credentials apply <credentials filename>

Expected behavior

Output in stdout: "Applied <namespace/credentials set name> credential set"

Actual behavior

Message "Applied <namespace/credentials set name> credential set" in stderr stream while the stdout stream is empty.

span.Info(f) methods that behaving badly? "execution completed successfully!" message also possibly being written to stderr.

image

This seems to be by design, but don't know if you want it changed @schristoff?
It completely get the problem described in the issue

stderr := c.Err
if f, ok := stderr.(*os.File); ok {
if isatty.IsTerminal(f.Fd()) {
stderr = colorable.NewColorable(f)
encoding.EncodeLevel = zapcore.LowercaseColorLevelEncoder
}
}
// if structured-logs feature isn't enabled, keep the logs looking like they do now, with just the message printed
if !c.logCfg.StructuredLogs {
encoding.TimeKey = ""
encoding.LevelKey = ""
}
consoleEncoder := zapcore.NewConsoleEncoder(encoding)
return zapcore.NewCore(consoleEncoder, zapcore.AddSync(stderr), c.logCfg.Verbosity)

Taking a peak at this, this is not an expected behavior and would be considered a bug - @kichristensen I would say go ahead and change it!
I wanted to triple check this wouldn't break anything, but I think ultimately our users aren't expecting this to go to stderr :)

@schristoff Just changing it in the referenced code, won't work as it also will affect warning and error messages. But I will take a look and see how it can be handled