Skip to content

Commit a46815e

Browse files
committed
Improve environment handling
Dash in names are impractical for environment variables names. Also, the required KUBE_ALERT_ prefix should be documented.
1 parent 53ef04f commit a46815e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

README.md

+19-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ Currently support alerting to Datadog and logs (ie. syslog).
99
Assuming you have go 1.9 and glide in the path, and GOPATH configured:
1010

1111
```shell
12-
make dep
12+
make deps
1313
make build
1414
```
1515

1616
## Usage
1717

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

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

2525
The command line flags are:
2626
```
@@ -33,7 +33,7 @@ Flags:
3333
-i, --datadog-api-key string datadog api key
3434
-a, --datadog-app-key string datadog app key
3535
-d, --dry-run dry-run mode
36-
-p, --healthcheck-port int port for answering healtchecks
36+
-p, --healthcheck-port int port for answering healthchecks
3737
-h, --help help for kube-alert
3838
-k, --kube-config string kube config path
3939
-v, --log-level string log level (default "debug")
@@ -56,3 +56,16 @@ datadog:
5656
app-key: xxx
5757
```
5858
59+
The environment variable consumed by kube-alert are option names prefixed
60+
by ```KUBE_ALERT_``` and using underscore instead of dash. Except KUBECONFIG,
61+
used without a prefix (to match kubernetes conventions).
62+
```
63+
env KUBECONFIG=/etc/kube/config \
64+
KUBE_ALERT_HEALTHCHECK_PORT=8081 \
65+
KUBE_ALERT_DATADOG.APP_KEY="xxx" \
66+
KUBE_ALERT_DATADOG.API_KEY="xxx" \
67+
KUBE_ALERT_DRY_RUN=true \
68+
KUBE_ALERT_LOG.LEVEL=info \
69+
KUBE_ALERT_API_SERVER="http://example.com:8080" \
70+
kube-alert
71+
```

cmd/execute.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"os"
5+
"strings"
56

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

88-
rootCmd.PersistentFlags().IntVarP(&healthP, "healthcheck-port", "p", 0, "port for answering healtchecks")
89+
rootCmd.PersistentFlags().IntVarP(&healthP, "healthcheck-port", "p", 0, "port for answering healthchecks")
8990
viper.BindPFlag("healthcheck-port", rootCmd.PersistentFlags().Lookup("healthcheck-port"))
9091
}
9192

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

108109
// allow config params through prefixed env variables
109110
viper.SetEnvPrefix("KUBE_ALERT")
111+
replacer := strings.NewReplacer("-", "_")
112+
viper.SetEnvKeyReplacer(replacer)
110113
viper.AutomaticEnv()
111114

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

0 commit comments

Comments
 (0)