-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5ab205
commit 050bdaf
Showing
4 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
63 changes: 63 additions & 0 deletions
63
csi-plug-n-play/sidecars/soda-proxy/pkg/controller/snapshot/snapshot.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |