Skip to content

Commit

Permalink
Containerize soda-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
asifdxtreme committed Jun 28, 2021
1 parent b5ab205 commit 050bdaf
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 3 deletions.
8 changes: 8 additions & 0 deletions csi-plug-n-play/sidecars/soda-proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Based on ubuntu
FROM ubuntu:xenial
LABEL maintainers="Mohammad Asif Siddiqui <asifdiatm@gmail.com>"

COPY soda-proxy /soda-proxy

# Define default command
ENTRYPOINT ["/soda-proxy"]
10 changes: 7 additions & 3 deletions csi-plug-n-play/sidecars/soda-proxy/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package main
import (
"github.com/gorilla/mux"
"github.com/sodafoundation/nbp/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/profile"
"github.com/sodafoundation/nbp/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/snapshot"

"log"
"net/http"
)

func handleRequests() {
myRouter := mux.NewRouter().StrictSlash(true)
myRouter.HandleFunc("/getprofile/{id}", profile.GetProfile)
log.Fatal(http.ListenAndServe("0.0.0.0:50029", myRouter))
sodaProxyRouter := mux.NewRouter().StrictSlash(true)
sodaProxyRouter.HandleFunc("/getprofile/{id}", profile.GetProfile)
sodaProxyRouter.HandleFunc("/snapshot/{id}", snapshot.CreateSnapshot)
log.Fatal(http.ListenAndServe("0.0.0.0:50029", sodaProxyRouter))

}

func main() {
Expand Down
63 changes: 63 additions & 0 deletions csi-plug-n-play/sidecars/soda-proxy/deploy/sodaProxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: soda-proxy
namespace: default
labels:
soda-app: proxy
spec:
selector:
matchLabels:
soda-app: proxy
template:
metadata:
labels:
soda-app: proxy
spec:
containers:
- name: soda-proxy
image: sodafoundation/soda-proxy:v1.0
env:
- name: OPENSDS_ENDPOINT
value: "http://192.168.20.62:50040"
- name: OPENSDS_AUTH_STRATEGY
value: "keystone"
- name: OS_AUTH_URL
value: "http://192.168.20.62/identity"
- name: OS_USERNAME
value: "admin"
- name: OS_PASSWORD
value: "opensds@123"
- name: OS_TENANT_NAME
value: "admin"
- name: OS_PROJECT_NAME
value: "admin"
- name: OS_USER_DOMAIN_ID
value: "default"
- name: NODE_IP
valueFrom:
fieldRef:
status.hostIP
ports:
- containerPort: 50029
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
terminationGracePeriodSeconds: 30

---
apiVersion: v1
kind: Service
metadata:
name: soda-proxy
labels:
soda-app: proxy
spec:
ports:
- port: 50029
protocol: TCP
selector:
soda-app: proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package snapshot

import (
"bytes"
"fmt"
"github.com/gorilla/mux"

"encoding/json"
"github.com/sodafoundation/nbp/client/opensds"
"net/http"
"os"
)

type CustomPropertiesSpec map[string]interface{}

func (cps CustomPropertiesSpec) GetSnapshotProfile() (string, string, string, string, int) {
var timeInterval int
timeFloat := cps["TimeInterval"].(float64)
timeInterval = int(timeFloat)
return fmt.Sprintf("%v", cps["AWS_ACCESS_KEY_ID"]), fmt.Sprintf("%v", cps["AWS_SECRET_ACCESS_KEY"]), fmt.Sprintf("%v", cps["RESTIC_REPOSITORY"]), fmt.Sprintf("%v", cps["RESTIC_PASSWORD"]), timeInterval
}

type SnapshotProfile struct {
AwsAccesskey string `json:"AWS_ACCESS_KEY_ID"`
AwsSecretkey string `json:"AWS_SECRET_ACCESS_KEY"`
ResticRepository string `json:"RESTIC_REPOSITORY"`
ResticPassword string `json:"RESTIC_PASSWORD"`
TimeInterval int `json:"timeInterval"`
ResticSourceRepo string `json:"resticSourceRepo"`
}

func CreateSnapshot(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
key := vars["id"]
opensdsEndpoint, errLookUp := os.LookupEnv("OPENSDS_ENDPOINT")
if !errLookUp {
fmt.Println("No env variables found for endpoint, switching to default")
opensdsEndpoint = "http://127.0.0.1:50040"
}
client, err := opensds.GetClient(opensdsEndpoint, "keystone")
if client == nil || err != nil {
fmt.Printf("get opensds client failed: %v", err)
}
profile, errosds := client.GetProfile(key)
if errosds != nil {
fmt.Printf("got error in GetProfile : %s", errosds.Error())
}

var customProperties CustomPropertiesSpec
customProperties = CustomPropertiesSpec(profile.CustomProperties)

ak, sk, repo, passwd, timeInterval := customProperties.GetSnapshotProfile()
snapshotProfile := SnapshotProfile{AwsAccesskey: ak, AwsSecretkey: sk, ResticRepository: repo, ResticPassword: passwd, TimeInterval: timeInterval, ResticSourceRepo: ""}

postBody, _ := json.Marshal(snapshotProfile)
fmt.Println(postBody)
responseBody := bytes.NewBuffer(postBody)
syncerEndpoint := os.Getenv("POD_IP")
response, err := http.Post("http://" +syncerEndpoint+":50030/snapshot", "application/json", responseBody)
fmt.Println(response.Body)
fmt.Println(err)

}

0 comments on commit 050bdaf

Please sign in to comment.