diff --git a/README.md b/README.md index 68b9a8e2..2abc32dd 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ A single line gets ignored if the first non-blank character is # in that line. * `POLL_INTERVAL_SECONDS` - (int) Number of seconds to wait between each check for new commits to the repo (default is 5). Set to 0 to disable the wait period. * `FULL_RUN_INTERVAL_SECONDS` - (int) Number of seconds between automatic full runs (default is 300, or 5 minutes). Set to 0 to disable the wait period. * `DIFF_URL_FORMAT` - (string) If specified, allows the status page to display a link to the source code referencing the diff for a specific commit. `DIFF_URL_FORMAT` should be a URL for a hosted remote repo that supports linking to a commit hash. Replace the commit hash portion with "%s" so it can be filled in by kube-applier (e.g. `https://github.com/kubernetes/kubernetes/commit/%s`). +* `LOG_LEVEL` - (int) Sets the `-v` flag on all `kubectl` commands run. Use this option to configure more verbose logging. If not specified, the `-v` flag is not set on `kubectl` commands defaulting to standard log verbosity. ### Mounting the Git Repository diff --git a/kube/client.go b/kube/client.go index c523b55b..1cd76db7 100644 --- a/kube/client.go +++ b/kube/client.go @@ -2,13 +2,14 @@ package kube import ( "fmt" - "github.com/box/kube-applier/sysutil" "io/ioutil" "log" "os/exec" "regexp" "strconv" "strings" + + "github.com/box/kube-applier/sysutil" ) const ( @@ -31,6 +32,8 @@ type Client struct { Server string // Location of the written kubeconfig file within the container kubeconfigFilePath string + // if <0, no verbosity level is specified in the commands run + LogLevel int } // Configure writes the kubeconfig file to be used for authenticating kubectl commands. @@ -42,7 +45,7 @@ func (c *Client) Configure() error { f, err := ioutil.TempFile("", "kubeConfig") c.kubeconfigFilePath = f.Name() - log.Printf("Using kubeConfig file:", c.kubeconfigFilePath) + log.Printf("Using kubeConfig file: %s", c.kubeconfigFilePath) if err != nil { return fmt.Errorf("Error creating kubeconfig file: %v", err) @@ -75,6 +78,9 @@ func (c *Client) Configure() error { // CheckVersion returns an error if the server and client have incompatible versions, otherwise returns nil. func (c *Client) CheckVersion() error { args := []string{"kubectl", "version"} + if c.LogLevel > -1 { + args = append(args, fmt.Sprintf("-v=%d", c.LogLevel)) + } if c.Server != "" { args = append(args, fmt.Sprintf("--kubeconfig=%s", c.kubeconfigFilePath)) } @@ -126,6 +132,9 @@ func isCompatible(clientMajor, clientMinor, serverMajor, serverMinor string) err // It returns the full apply command and its output. func (c *Client) Apply(path string) (cmd, output string, err error) { args := []string{"kubectl", "apply", "-f", path} + if c.LogLevel > -1 { + args = append(args, fmt.Sprintf("-v=%d", c.LogLevel)) + } if c.Server != "" { args = append(args, fmt.Sprintf("--kubeconfig=%s", c.kubeconfigFilePath)) } diff --git a/main.go b/main.go index ddb9bad8..56781eea 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,10 @@ package main import ( + "log" + "strings" + "time" + "github.com/box/kube-applier/applylist" "github.com/box/kube-applier/git" "github.com/box/kube-applier/kube" @@ -8,9 +12,6 @@ import ( "github.com/box/kube-applier/run" "github.com/box/kube-applier/sysutil" "github.com/box/kube-applier/webserver" - "log" - "strings" - "time" ) const ( @@ -30,6 +31,7 @@ func main() { listenPort := sysutil.GetRequiredEnvInt("LISTEN_PORT") server := sysutil.GetEnvStringOrDefault("SERVER", "") blacklistPath := sysutil.GetEnvStringOrDefault("BLACKLIST_PATH", "") + logLevel := sysutil.GetEnvIntOrDefault("LOG_LEVEL", -1) // A file that contains a list of files to consider for application. // If the env var is not defined or if the file is empty act like a no-op and @@ -49,7 +51,10 @@ func main() { log.Fatal(err) } - kubeClient := &kube.Client{Server: server} + kubeClient := &kube.Client{ + Server: server, + LogLevel: logLevel, + } kubeClient.Configure() gitUtil := &git.GitUtil{repoPath}