GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

print.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package update
  2. import (
  3. "fmt"
  4. "io"
  5. "text/tabwriter"
  6. "github.com/weaveworks/flux"
  7. )
  8. // PrintResults outputs a result set to the `io.Writer` provided, at
  9. // the given level of verbosity:
  10. // - 2 = include skipped and ignored resources
  11. // - 1 = include skipped resources, exclude ignored resources
  12. // - 0 = exclude skipped and ignored resources
  13. func PrintResults(out io.Writer, results Result, verbosity int) {
  14. w := tabwriter.NewWriter(out, 0, 2, 2, ' ', 0)
  15. fmt.Fprintln(w, "CONTROLLER \tSTATUS \tUPDATES")
  16. for _, serviceID := range results.ServiceIDs() {
  17. result := results[flux.MustParseResourceID(serviceID)]
  18. switch result.Status {
  19. case ReleaseStatusIgnored:
  20. if verbosity < 2 {
  21. continue
  22. }
  23. case ReleaseStatusSkipped:
  24. if verbosity < 1 {
  25. continue
  26. }
  27. }
  28. var extraLines []string
  29. if result.Error != "" {
  30. extraLines = append(extraLines, result.Error)
  31. }
  32. for _, update := range result.PerContainer {
  33. extraLines = append(extraLines, fmt.Sprintf("%s: %s -> %s", update.Container, update.Current.String(), update.Target.Tag))
  34. }
  35. var inline string
  36. if len(extraLines) > 0 {
  37. inline = extraLines[0]
  38. extraLines = extraLines[1:]
  39. }
  40. fmt.Fprintf(w, "%s\t%s\t%s\n", serviceID, result.Status, inline)
  41. for _, lines := range extraLines {
  42. fmt.Fprintf(w, "\t\t%s\n", lines)
  43. }
  44. }
  45. w.Flush()
  46. }