[v2.16] redis cleanup and helm chart update
This commit is contained in:
Родитель
28c60ef59a
Коммит
d922b03dfa
|
@ -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
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
30
main.go
30
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("*")
|
||||
|
|
20
redis.go
20
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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче