forked from joe-elliott/cert-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (69 loc) · 3.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"flag"
"log"
"net/http"
"os"
"time"
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/joe-elliott/cert-exporter/src/args"
"github.com/joe-elliott/cert-exporter/src/checkers"
"github.com/joe-elliott/cert-exporter/src/exporters"
)
var (
version = "unknown"
commit = "unknown"
date = "unknown"
)
var (
includeCertGlobs args.GlobArgs
excludeCertGlobs args.GlobArgs
includeKubeConfigGlobs args.GlobArgs
excludeKubeConfigGlobs args.GlobArgs
prometheusListenAddress string
prometheusPath string
pollingPeriod time.Duration
kubeconfigPath string
secretsLabelSelector args.GlobArgs
secretsAnnotationSelector args.GlobArgs
secretsNamespace string
includeSecretsDataGlobs args.GlobArgs
excludeSecretsDataGlobs args.GlobArgs
)
func init() {
flag.Var(&includeCertGlobs, "include-cert-glob", "File globs to include when looking for certs.")
flag.Var(&excludeCertGlobs, "exclude-cert-glob", "File globs to exclude when looking for certs.")
flag.Var(&includeKubeConfigGlobs, "include-kubeconfig-glob", "File globs to include when looking for kubeconfigs.")
flag.Var(&excludeKubeConfigGlobs, "exclude-kubeconfig-glob", "File globs to exclude when looking for kubeconfigs.")
flag.StringVar(&prometheusPath, "prometheus-path", "/metrics", "The path to publish Prometheus metrics to.")
flag.StringVar(&prometheusListenAddress, "prometheus-listen-address", ":8080", "The address to listen on for Prometheus scrapes.")
flag.DurationVar(&pollingPeriod, "polling-period", time.Hour, "Periodic interval in which to check certs.")
flag.StringVar(&kubeconfigPath, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.Var(&secretsLabelSelector, "secrets-label-selector", "Label selector to find secrets to publish as metrics.")
flag.Var(&secretsAnnotationSelector, "secrets-annotation-selector", "Annotation selector to find secrets to publish as metrics.")
flag.StringVar(&secretsNamespace, "secrets-namespace", "", "Kubernetes namespace to list secrets.")
flag.Var(&includeSecretsDataGlobs, "secrets-include-glob", "Secret globs to include when looking for secret data keys (Default \"*\").")
flag.Var(&excludeSecretsDataGlobs, "secrets-exclude-glob", "Secret globs to exclude when looking for secret data keys.")
}
func main() {
flag.Parse()
glog.Infof("Starting cert-exporter (version %s; commit %s; date %s)", version, commit, date)
if len(includeCertGlobs) > 0 {
certChecker := checkers.NewCertChecker(pollingPeriod, includeCertGlobs, excludeCertGlobs, os.Getenv("NODE_NAME"), &exporters.CertExporter{})
go certChecker.StartChecking()
}
if len(includeKubeConfigGlobs) > 0 {
configChecker := checkers.NewCertChecker(pollingPeriod, includeKubeConfigGlobs, excludeKubeConfigGlobs, os.Getenv("NODE_NAME"), &exporters.KubeConfigExporter{})
go configChecker.StartChecking()
}
if len(secretsLabelSelector) > 0 || len(secretsAnnotationSelector) > 0 || len(includeSecretsDataGlobs) > 0 {
if len(includeSecretsDataGlobs) == 0 {
includeSecretsDataGlobs = args.GlobArgs([]string{"*"})
}
configChecker := checkers.NewSecretChecker(pollingPeriod, secretsLabelSelector, includeSecretsDataGlobs, excludeSecretsDataGlobs, secretsAnnotationSelector, secretsNamespace, kubeconfigPath, &exporters.SecretExporter{})
go configChecker.StartChecking()
}
http.Handle(prometheusPath, promhttp.Handler())
log.Fatal(http.ListenAndServe(prometheusListenAddress, nil))
}