diff --git a/helm/ip-whitelister/Chart.yaml b/helm/ip-whitelister/Chart.yaml index b1cca94..0fa149e 100644 --- a/helm/ip-whitelister/Chart.yaml +++ b/helm/ip-whitelister/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.4.0 +version: 0.5.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/helm/ip-whitelister/README.md b/helm/ip-whitelister/README.md index 09b1b99..75c09e6 100644 --- a/helm/ip-whitelister/README.md +++ b/helm/ip-whitelister/README.md @@ -130,6 +130,6 @@ resource_configs: 4. Deploy to your Kubernetes cluster ``` -helm upgrade ip-whitelister https://github.com/alec-pinson/ip-whitelister/releases/download/v1.0.8/helm-chart-ip-whitelister-0.4.0.tgz --install --wait -f values.yaml +helm upgrade ip-whitelister https://github.com/alec-pinson/ip-whitelister/releases/download/v1.1.0/helm-chart-ip-whitelister-0.5.0.tgz --install --wait -f values.yaml ``` diff --git a/helm/ip-whitelister/templates/deployment.yaml b/helm/ip-whitelister/templates/deployment.yaml index 57238a5..33c9c7b 100644 --- a/helm/ip-whitelister/templates/deployment.yaml +++ b/helm/ip-whitelister/templates/deployment.yaml @@ -52,12 +52,12 @@ spec: mountPath: /app/config/resources livenessProbe: httpGet: - path: / - port: http + path: /live + port: 8090 readinessProbe: httpGet: - path: / - port: http + path: /ready + port: 8090 resources: {{- toYaml .Values.resources | nindent 12 }} volumes: diff --git a/http.go b/http.go index 2ec7579..7a3a0d6 100644 --- a/http.go +++ b/http.go @@ -19,6 +19,9 @@ import ( type handle func(w http.ResponseWriter, req *http.Request) error +var httpLive bool = true +var httpReady bool = false + type Error struct { Code int Message string @@ -150,8 +153,15 @@ func (a *Authentication) initAzure() { Scopes: []string{"profile"}, } + http.Handle("/live", handle(livenessHandler)) + http.Handle("/ready", handle(readinessHandler)) http.Handle("/callback", handle(callbackHandler)) http.Handle("/", handle(IndexHandler)) + log.Fatal(http.ListenAndServe(":8090", nil)) +} + +func (a *Authentication) start() { + httpReady = true log.Print("http.initAzure(): ip whitelister started") log.Fatal(http.ListenAndServe(":8080", nil)) } @@ -221,3 +231,27 @@ func IndexHandler(w http.ResponseWriter, req *http.Request) error { return indexTempl.Execute(w, &data) } + +func livenessHandler(w http.ResponseWriter, req *http.Request) error { + var err error + if httpLive { + w.WriteHeader(200) + _, err = w.Write([]byte("ok")) + } else { + w.WriteHeader(500) + _, err = w.Write([]byte("not ok")) + } + return err +} + +func readinessHandler(w http.ResponseWriter, req *http.Request) error { + var err error + if httpReady { + w.WriteHeader(200) + _, err = w.Write([]byte("ok")) + } else { + w.WriteHeader(500) + _, err = w.Write([]byte("not ok")) + } + return err +} diff --git a/whitelist.go b/whitelist.go index 6c8aed7..b8c5e79 100644 --- a/whitelist.go +++ b/whitelist.go @@ -24,11 +24,14 @@ func (*Whitelist) init() { // enable ttl check on whitelisted ips go w.ttl() + // initialize authentication + go h.init(c.Auth) + // update resources on startup w.updateResources() - // initialize http/authentication - h.init(c.Auth) + // initialize http + h.start() } func (w *Whitelist) add(u *User) bool {