From dbd6efc1571de95147489767de103fb787b26ffc Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 20 Aug 2021 16:38:35 +0530 Subject: [PATCH] Add option to provide log verbosity (#23) --- cmd/kaniko-docker/main.go | 6 ++++++ cmd/kaniko-ecr/main.go | 6 ++++++ cmd/kaniko-gcr/main.go | 6 ++++++ kaniko.go | 11 ++++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/kaniko-docker/main.go b/cmd/kaniko-docker/main.go index 8576d46..8362880 100644 --- a/cmd/kaniko-docker/main.go +++ b/cmd/kaniko-docker/main.go @@ -132,6 +132,11 @@ func main() { Usage: "Set this flag if you only want to build the image, without pushing to a registry", EnvVar: "PLUGIN_NO_PUSH", }, + cli.StringFlag{ + Name: "verbosity", + Usage: "Set this flag with value as oneof to set the logging level for kaniko. Defaults to info.", + EnvVar: "PLUGIN_VERBOSITY", + }, } if err := app.Run(os.Args); err != nil { @@ -161,6 +166,7 @@ func run(c *cli.Context) error { CacheTTL: c.Int("cache-ttl"), DigestFile: defaultDigestFile, NoPush: c.Bool("no-push"), + Verbosity: c.String("verbosity"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-ecr/main.go b/cmd/kaniko-ecr/main.go index 7a34818..3540201 100644 --- a/cmd/kaniko-ecr/main.go +++ b/cmd/kaniko-ecr/main.go @@ -122,6 +122,11 @@ func main() { Usage: "Set this flag if you only want to build the image, without pushing to a registry", EnvVar: "PLUGIN_NO_PUSH", }, + cli.StringFlag{ + Name: "verbosity", + Usage: "Set this flag with value as oneof to set the logging level for kaniko. Defaults to info.", + EnvVar: "PLUGIN_VERBOSITY", + }, } if err := app.Run(os.Args); err != nil { @@ -150,6 +155,7 @@ func run(c *cli.Context) error { CacheTTL: c.Int("cache-ttl"), DigestFile: defaultDigestFile, NoPush: c.Bool("no-push"), + Verbosity: c.String("verbosity"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-gcr/main.go b/cmd/kaniko-gcr/main.go index 4d8e8b6..4fb9f20 100644 --- a/cmd/kaniko-gcr/main.go +++ b/cmd/kaniko-gcr/main.go @@ -118,6 +118,11 @@ func main() { Usage: "Set this flag if you only want to build the image, without pushing to a registry", EnvVar: "PLUGIN_NO_PUSH", }, + cli.StringFlag{ + Name: "verbosity", + Usage: "Set this flag as --verbosity= to set the logging level for kaniko. Defaults to info.", + EnvVar: "PLUGIN_VERBOSITY", + }, } if err := app.Run(os.Args); err != nil { @@ -150,6 +155,7 @@ func run(c *cli.Context) error { CacheTTL: c.Int("cache-ttl"), DigestFile: defaultDigestFile, NoPush: c.Bool("no-push"), + Verbosity: c.String("verbosity"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/kaniko.go b/kaniko.go index f9f851a..4d5a8de 100644 --- a/kaniko.go +++ b/kaniko.go @@ -27,6 +27,7 @@ type ( CacheTTL int // Cache timeout in hours DigestFile string // Digest file location NoPush bool // Set this flag if you only want to build the image, without pushing to a registry + Verbosity string // Log level } // Artifact defines content of artifact file Artifact struct { @@ -86,10 +87,10 @@ func (p Plugin) Exec() error { if p.Build.EnableCache == true { cmdArgs = append(cmdArgs, fmt.Sprintf("--cache=true")) - } - if p.Build.CacheRepo != "" { - cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-repo=%s", p.Build.CacheRepo)) + if p.Build.CacheRepo != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-repo=%s", p.Build.CacheRepo)) + } } if p.Build.CacheTTL != 0 { @@ -104,6 +105,10 @@ func (p Plugin) Exec() error { cmdArgs = append(cmdArgs, fmt.Sprintf("--no-push")) } + if p.Build.Verbosity != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--verbosity=%s", p.Build.Verbosity)) + } + cmd := exec.Command("/kaniko/executor", cmdArgs...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr