Skip to content

Commit

Permalink
Improve environment handling
Browse files Browse the repository at this point in the history
Dash in names are impractical for environment variables names.
Also, the required KUBE_ALERT_ prefix should be documented.
  • Loading branch information
bpineau committed Sep 26, 2017
1 parent 53ef04f commit a46815e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Currently support alerting to Datadog and logs (ie. syslog).
Assuming you have go 1.9 and glide in the path, and GOPATH configured:

```shell
make dep
make deps
make build
```

## Usage

The daemon may run as a pod in the cluster, or outside of the cluster.
He should find the Kubernetes api-server automatically, but you can
provide this server's address with "-s" flag, or a full config with "-k".
The daemon may run either as a pod, or outside of the Kubernetes cluster.
He should find the Kubernetes api-server automatically (but you can
provide this server's address with "-s" flag, or a kube config with "-k").

You can pass configuration values either by command line arguments, or
environment variables, or with a yaml configuration file.
environment variables, a yaml configuration file, or a combination or those.

The command line flags are:
```
Expand All @@ -33,7 +33,7 @@ Flags:
-i, --datadog-api-key string datadog api key
-a, --datadog-app-key string datadog app key
-d, --dry-run dry-run mode
-p, --healthcheck-port int port for answering healtchecks
-p, --healthcheck-port int port for answering healthchecks
-h, --help help for kube-alert
-k, --kube-config string kube config path
-v, --log-level string log level (default "debug")
Expand All @@ -56,3 +56,16 @@ datadog:
app-key: xxx
```
The environment variable consumed by kube-alert are option names prefixed
by ```KUBE_ALERT_``` and using underscore instead of dash. Except KUBECONFIG,
used without a prefix (to match kubernetes conventions).
```
env KUBECONFIG=/etc/kube/config \
KUBE_ALERT_HEALTHCHECK_PORT=8081 \
KUBE_ALERT_DATADOG.APP_KEY="xxx" \
KUBE_ALERT_DATADOG.API_KEY="xxx" \
KUBE_ALERT_DRY_RUN=true \
KUBE_ALERT_LOG.LEVEL=info \
KUBE_ALERT_API_SERVER="http://example.com:8080" \
kube-alert
```
5 changes: 4 additions & 1 deletion cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"strings"

"github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -85,7 +86,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&ddApiKey, "datadog-api-key", "i", "", "datadog api key")
viper.BindPFlag("datadog.api-key", rootCmd.PersistentFlags().Lookup("datadog-api-key"))

rootCmd.PersistentFlags().IntVarP(&healthP, "healthcheck-port", "p", 0, "port for answering healtchecks")
rootCmd.PersistentFlags().IntVarP(&healthP, "healthcheck-port", "p", 0, "port for answering healthchecks")
viper.BindPFlag("healthcheck-port", rootCmd.PersistentFlags().Lookup("healthcheck-port"))
}

Expand All @@ -107,6 +108,8 @@ func initConfig() {

// allow config params through prefixed env variables
viper.SetEnvPrefix("KUBE_ALERT")
replacer := strings.NewReplacer("-", "_")
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()

if err := viper.ReadInConfig(); err == nil {
Expand Down

0 comments on commit a46815e

Please sign in to comment.