aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTy Davis <tydavis@gmail.com>2016-06-01 16:38:08 -0700
committerTy Davis <tydavis@gmail.com>2016-06-01 16:38:08 -0700
commitfc9faa7b0d6a60ba9267162a15ebdd0c0b72de39 (patch)
tree502339bc830faab91774fadc219b8c6b1f4080f0
parent429cc1b9ea1b4779daccf58181914ef46dbec2ad (diff)
downloadshow-readiness-fc9faa7b0d6a60ba9267162a15ebdd0c0b72de39.tar.gz
show-readiness-fc9faa7b0d6a60ba9267162a15ebdd0c0b72de39.zip
Should be ready, adding dockerfile
-rw-r--r--Dockerfile6
-rw-r--r--main.go38
2 files changed, 41 insertions, 3 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..e80e143
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,6 @@
+FROM busybox:latest
+MAINTAINER Ty Davis <tydavis@gmail.com>
+
+EXPOSE 80
+COPY showReadiness /
+CMD /showReadiness
diff --git a/main.go b/main.go
index 370b9cd..76460f3 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"log"
"net/http"
"os"
@@ -13,6 +14,26 @@ var ReadyValue = http.StatusOK
var LiveValue = http.StatusOK
var hostname string
+func makeNotReady(w http.ResponseWriter, r *http.Request) {
+ ReadyValue = http.StatusBadRequest
+ w.Header().Set("responding-pod", hostname)
+ fmt.Fprintf(w, "%s", "Set Readiness Value to a failure state")
+
+}
+
+func makePodReady(w http.ResponseWriter, r *http.Request) {
+ ReadyValue = http.StatusOK
+ w.Header().Set("responding-pod", hostname)
+ fmt.Fprintf(w, "%s", "Set Readiness Value to successful (OK) state")
+
+}
+
+func killMe(w http.ResponseWriter, r *http.Request) {
+ LiveValue = http.StatusBadRequest
+ w.Header().Set("responding-pod", hostname)
+ fmt.Fprintf(w, "%s", "Set Liveness Value to a failure state")
+}
+
func readinessCheck(w http.ResponseWriter, r *http.Request) {
w.Header().Set("responding-pod", hostname)
http.Error(w, "", ReadyValue)
@@ -25,16 +46,26 @@ func livenessCheck(w http.ResponseWriter, r *http.Request) {
func rootHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("responding-pod", hostname)
- w.Fprintf(w, "%s", "I'm serving traffic!")
+ fmt.Fprintf(w, "%s", "I'm serving traffic!")
}
func main() {
// Force log output to stdout for Docker
log.SetOutput(os.Stdout)
+
// Delay for startup
- time.Sleep(1 * time.Second)
- hostname, _ = os.Hostname()
+ var delay time.Duration = (1 * time.Second)
+ if os.Getenv("APPDELAY") != "" {
+ var err error
+ delay, err = time.ParseDuration(os.Getenv("APPDELAY"))
+ if err != nil {
+ log.Fatalf("Failed to parse time duration: %v", err)
+ }
+ }
+ time.Sleep(delay)
+ // Finish startup
+ hostname, _ = os.Hostname()
log.Println("Service started on port 80")
mux := http.NewServeMux()
@@ -43,6 +74,7 @@ func main() {
mux.HandleFunc("/ready", readinessCheck)
mux.HandleFunc("/makeNotReady", makeNotReady)
mux.HandleFunc("/makePodReady", makePodReady)
+ mux.HandleFunc("/killMe", killMe)
server := &http.Server{
Addr: ":80",