grim/tagpull

4f65422a6fcb
Parents 661a31198963
Children c65b5da80482
Add command line arguments and a flag for controlling the log level
  • +1 -0
    const.go
  • +3 -0
    go.mod
  • +7 -0
    go.sum
  • +22 -2
    main.go
  • --- a/const.go Sun Jul 05 05:06:31 2020 -0500
    +++ b/const.go Sun Jul 05 05:22:05 2020 -0500
    @@ -2,4 +2,5 @@
    const (
    Annotation = "tagops/autoupdate"
    + Version = "0.1.0"
    )
    --- a/go.mod Sun Jul 05 05:06:31 2020 -0500
    +++ b/go.mod Sun Jul 05 05:22:05 2020 -0500
    @@ -1,6 +1,9 @@
    module keep.imfreedom.org/grim/tagops
    require (
    + github.com/alecthomas/kingpin v2.2.6+incompatible
    + github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
    + github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
    github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 // indirect
    github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e // indirect
    github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550 // indirect
    --- a/go.sum Sun Jul 05 05:06:31 2020 -0500
    +++ b/go.sum Sun Jul 05 05:22:05 2020 -0500
    @@ -7,6 +7,13 @@
    github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
    github.com/OpenPeeDeeP/depguard v1.0.0/go.mod h1:7/4sitnI9YlQgTLLk734QlzXT8DuHVnAyztLplQjk+o=
    github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
    +github.com/alecthomas/kingpin v1.3.7 h1:GLMgiQ5nZb3rg5pozvF7KDbseQ12eNO1p7bB2t5K1fw=
    +github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI=
    +github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
    +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
    +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
    +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
    +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
    github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
    github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
    github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
    --- a/main.go Sun Jul 05 05:06:31 2020 -0500
    +++ b/main.go Sun Jul 05 05:22:05 2020 -0500
    @@ -4,19 +4,39 @@
    "os"
    "time"
    + "github.com/alecthomas/kingpin"
    log "github.com/sirupsen/logrus"
    )
    +var (
    + app = kingpin.New("tagpull", "A kubernetes operator to automatically restart deployments").Version(Version)
    +
    + logLevel = app.Flag("log-level", "The level of the logger").Short('l').Default("info").Enum("panic", "fatal", "error", "warn", "info", "debug", "trace")
    +)
    +
    func main() {
    tickrate := 1 * time.Minute
    namespace := ""
    + if _, err := app.Parse(os.Args[1:]); err != nil {
    + app.Usage(os.Args[1:])
    +
    + return
    + }
    +
    log.SetOutput(os.Stdout)
    - log.SetLevel(log.DebugLevel)
    +
    + level, err := log.ParseLevel(*logLevel)
    + if err != nil {
    + log.Fatalf("%v\n", err)
    +
    + return
    + }
    + log.SetLevel(level)
    operator, err := NewOperator(tickrate, namespace)
    if err != nil {
    - log.Fatalf("%v", err)
    + log.Fatalf("%v\n", err)
    return
    }