diff --git a/k8s-poolprovider/templates/redis.yaml b/k8s-poolprovider/templates/redis.yaml new file mode 100644 index 0000000..788df93 --- /dev/null +++ b/k8s-poolprovider/templates/redis.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.redis.appname }} + labels: + app: {{ .Values.app.name }} +spec: + ports: + - port: {{ .Values.redis.port }} + selector: + app: {{ .Values.app.name }} + tier: redis +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ .Values.redis.appname }} + labels: + app: {{ .Values.app.name }} +spec: + template: + metadata: + labels: + app: {{ .Values.app.name }} + tier: redis + spec: + containers: + - image: {{ .Values.redis.image }} + name: redis + ports: + - containerPort: {{ .Values.redis.port }} + name: redis \ No newline at end of file diff --git a/k8s-poolprovider/values.yaml b/k8s-poolprovider/values.yaml index 8f10f8c..c069a32 100644 --- a/k8s-poolprovider/values.yaml +++ b/k8s-poolprovider/values.yaml @@ -14,7 +14,7 @@ rbac: image: repository: divyanshm/k8s-poolprovider - tag: v2.15 + tag: v2.16 pullPolicy: IfNotPresent vsts: @@ -25,6 +25,11 @@ vsts: config: buildkitPodCount: 1 +redis: + appname: k8s-poolprovider-redis + port: 6379 + image: redis:3-alpine + tls: [] # - secretName: chart-example-tls # hosts: diff --git a/kubernetes.yaml b/kubernetes.yaml index f5902f1..7e61c22 100644 --- a/kubernetes.yaml +++ b/kubernetes.yaml @@ -68,7 +68,7 @@ spec: spec: serviceAccountName: pipelineprovider containers: - - image: divyanshm/k8s-poolprovider:v2.15 + - image: divyanshm/k8s-poolprovider:v2.16 name: k8s-poolprovider command: ["/app/main"] ports: diff --git a/main.go b/main.go index c761f9d..5ed899a 100644 --- a/main.go +++ b/main.go @@ -24,10 +24,8 @@ func main() { s.HandleFunc("/delete", func(w http.ResponseWriter, r *http.Request) { KubernetesDeleteHandler(w, r) }) // Test redis - s.HandleFunc("/storageget", StorageGetHandler(storage)) - s.HandleFunc("/storageset", StorageSetHandler(storage)) - s.HandleFunc("/storageping", PingHandler(storage)) - s.HandleFunc("/storagegetkeys", GetKeysHandler(storage)) + s.HandleFunc("/testredisdata", StorageSetHandler(storage)) + s.HandleFunc("/redisgetkeys", GetKeysHandler(storage)) // Start HTTP Server with request logging log.Fatal(http.ListenAndServe(":8082", s)) @@ -57,40 +55,18 @@ func KubernetesDeleteHandler(resp http.ResponseWriter, req *http.Request) { fmt.Fprintf(resp, "Response: %s", pods) } -func StorageGetHandler(s Storage) http.HandlerFunc { - return func(resp http.ResponseWriter, req *http.Request) { - key := req.URL.Query()["key"] - res, err := s.Get(key[0]) - if err != nil { - resp.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(resp, err.Error()) - return - } - resp.WriteHeader(http.StatusOK) - fmt.Fprintln(resp, res) - } -} - func StorageSetHandler(s Storage) http.HandlerFunc { return func(resp http.ResponseWriter, req *http.Request) { key := "some sample key" value := "some sample value" + // Retrieving information from backing Redis storage s.Set(key, value) retrievedValue, _ := s.Get(key) fmt.Fprintf(resp, "All good. Retrieved %s", retrievedValue) } } -func PingHandler(s Storage) http.HandlerFunc { - return func(resp http.ResponseWriter, req *http.Request) { - res := s.Init() - - resp.WriteHeader(http.StatusOK) - fmt.Fprintln(resp, res) - } -} - func GetKeysHandler(s Storage) http.HandlerFunc { return func(resp http.ResponseWriter, req *http.Request) { res, err := s.GetKeys("*") diff --git a/redis.go b/redis.go index c6d7da7..a62b153 100644 --- a/redis.go +++ b/redis.go @@ -2,7 +2,6 @@ package main import ( "time" - "fmt" "github.com/gomodule/redigo/redis" ) @@ -12,7 +11,6 @@ type Storage interface { Get(string) (string, error) Set(string, string) error GetKeys(string) ([]string, error) - Init() string } type RedisStorage struct { @@ -39,9 +37,6 @@ func NewRedisStorage(server string) Storage { } } -// Ping will "ping" the storage backend. -// The function can use to check the connection from -// the app to the storage backend. func (r *RedisStorage) Ping() (string, error) { conn := r.connectionPool.Get() defer conn.Close() @@ -50,21 +45,6 @@ func (r *RedisStorage) Ping() (string, error) { return res, err } -func (r *RedisStorage) Init() string { - conn := r.connectionPool.Get() - defer conn.Close() - - conn.Do("SET", "best_car_ever", "Tesla Model S") - conn.Do("SET", "worst_car_ever", "Geo Metro") - - worst_car_ever, err := redis.String(conn.Do("GET", "worst_car_ever")) - if err != nil { - fmt.Println("worst_car_ever not found", err) - } - - return worst_car_ever -} - func (r *RedisStorage) Get(key string) (string, error) { conn := r.connectionPool.Get() defer conn.Close()