diff --git a/Dockerfile b/Dockerfile index 077a055..87db881 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM golang:alpine -MAINTAINER Divyansh Manchanda - RUN apk add --no-cache git mercurial \ && go get github.com/garyburd/redigo/redis \ && go get github.com/gorilla/handlers \ diff --git a/kubernetes.go b/kubernetes.go index 07a7d3f..474cb62 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -49,11 +49,12 @@ func CreatePod() string { securityContext: privileged: true volumeMounts: - - name: daemon-storage + - name: agent-pv-storage mountPath: /var/lib/docker volumes: - - name: daemon-storage - emptyDir: {} + - name: agent-pv-storage + persistentVolumeClaim: + claimName: agent-pv-volume2 ` var p1 v1.Pod diff --git a/kubernetes.yaml b/kubernetes.yaml index b34f5b5..54f2b96 100644 --- a/kubernetes.yaml +++ b/kubernetes.yaml @@ -27,7 +27,7 @@ spec: tier: frontend spec: containers: - - image: divyanshm/goserver:v1.12 + - image: divyanshm/goserver:v1.13 name: goserver command: ["/app/main", "-redis", "goserver-redis:6379"] ports: diff --git a/main.go b/main.go index 5d48fc2..67f744f 100644 --- a/main.go +++ b/main.go @@ -26,16 +26,15 @@ func main() { flag.Parse() // Create Redis storage - r := NewRedisStorage(*redisFlag) + storage := NewRedisStorage(*redisFlag) // Define HTTP endpoints s := http.NewServeMux() - s.HandleFunc("/", RootHandler) - s.HandleFunc("/ping", PingHandler(r)) + s.HandleFunc("/ping", PingHandler(storage)) s.HandleFunc("/version", VersionHandler) s.HandleFunc("/payload", PayloadHandler) - s.HandleFunc("/create", KubernetesCreateHandler) - s.HandleFunc("/delete", KubernetesDeleteHandler) + s.HandleFunc("/create", func(w http.ResponseWriter, r *http.Request) { KubernetesCreateHandler(w, r, storage) }) + s.HandleFunc("/delete", func(w http.ResponseWriter, r *http.Request) { KubernetesDeleteHandler(w, r, storage) }) // Bootstrap logger logger := log.New(os.Stdout, "", log.LstdFlags) @@ -46,12 +45,6 @@ func main() { log.Fatal(http.ListenAndServe(*listenFlag, loggingHandler)) } -// RootHandler handles requests to the "/" path. -// It will redirect the request to /ping with a 303 HTTP header -func RootHandler(resp http.ResponseWriter, req *http.Request) { - http.Redirect(resp, req, "/ping", http.StatusSeeOther) -} - // PingHandler handles request to the "/ping" endpoint. // It will send a PING request to Redis and return the response // of the NoSQL database. @@ -104,7 +97,7 @@ func PayloadHandler(resp http.ResponseWriter, req *http.Request) { fmt.Fprintf(resp, "Payload: %s", string(body)) } -func KubernetesCreateHandler(resp http.ResponseWriter, req *http.Request) { +func KubernetesCreateHandler(resp http.ResponseWriter, req *http.Request, s Storage) { _, err := ioutil.ReadAll(req.Body) if err != nil { resp.WriteHeader(http.StatusInternalServerError) @@ -116,7 +109,7 @@ func KubernetesCreateHandler(resp http.ResponseWriter, req *http.Request) { fmt.Fprintf(resp, "Pods: %s", pods) } -func KubernetesDeleteHandler(resp http.ResponseWriter, req *http.Request) { +func KubernetesDeleteHandler(resp http.ResponseWriter, req *http.Request, s Storage) { podname := req.URL.Query()["podname"][0] if podname == "" { fmt.Fprintf(resp, "Provide pod name as ?podname=somename");