Skip to content

Commit

Permalink
go fmt project
Browse files Browse the repository at this point in the history
  • Loading branch information
asifdxtreme committed Jun 28, 2021
1 parent 42151ca commit b7055bc
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ const (

operationTimeout = 10 * time.Second

sodaProfileEndpoint = "soda-proxy:50029/getprofile/"
sodaProfileEndpoint = "soda-proxy:50029/getprofile/"
sodaSnapShotEnableEndpoint = "soda-proxy:50029/getprofile/"

)

var (
Expand Down Expand Up @@ -554,7 +553,7 @@ func (p *csiProvisioner) isCallForCurrentDriver(profileID string) (string, error
}

// Call the soda-syncer for Snapshot
func (p *csiProvisioner) snapShotEnable(profileID string) (error) {
func (p *csiProvisioner) snapShotEnable(profileID string) error {

// Call the SnapshotEnable
url := "http://" + sodaSnapShotEnableEndpoint + profileID
Expand All @@ -567,7 +566,6 @@ func (p *csiProvisioner) snapShotEnable(profileID string) (error) {
return nil
}


// prepareProvision does non-destructive parameter checking and preparations for provisioning a volume.
func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.PersistentVolumeClaim, sc *storagev1.StorageClass, selectedNode *v1.Node) (*prepareProvisionResult, controller.ProvisioningState, error) {
if sc == nil {
Expand All @@ -590,10 +588,7 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
sc.Provisioner = backendDriverName
}
}
fmt.Println("Calling the SnapshotFunction in GoRoutine")
go p.snapShotEnable(profileID)
fmt.Println("Continuing With the Flow")


migratedVolume := false
if p.supportsMigrationFromInTreePluginName != "" {
Expand Down
14 changes: 14 additions & 0 deletions csi-plug-n-play/sidecars/soda-proxy/cmd/proxy.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2021 The SodaFoundation Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:#www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
Expand Down
4 changes: 2 additions & 2 deletions csi-plug-n-play/sidecars/soda-proxy/deploy/sodaProxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ spec:
image: sodafoundation/soda-proxy:v1.0
env:
- name: OPENSDS_ENDPOINT
value: "http://192.168.20.62:50040"
value: "http://{YourHOSTIP}:50040"
- name: OPENSDS_AUTH_STRATEGY
value: "keystone"
- name: OS_AUTH_URL
value: "http://192.168.20.62/identity"
value: "http://{YourHOSTIP}/identity"
- name: OS_USERNAME
value: "admin"
- name: OS_PASSWORD
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2021 The SodaFoundation Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:#www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package profile

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2021 The SodaFoundation Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:#www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package snapshot

import (
Expand All @@ -11,16 +25,6 @@ import (
"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"`
Expand Down Expand Up @@ -58,7 +62,7 @@ func CreateSnapshot(w http.ResponseWriter, r *http.Request) {
requestBody := bytes.NewBuffer(postBody)
syncerEndpoint := os.Getenv("NODE_IP")

response, err := http.Post("http://" +syncerEndpoint+":50030/snapshot", "application/json", requestBody)
response, err := http.Post("http://"+syncerEndpoint+":50030/snapshot", "application/json", requestBody)
fmt.Println(response.Body)
json.NewEncoder(w).Encode(response.Body)
}
34 changes: 17 additions & 17 deletions soda-syncer/pkg/snapshot/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,41 @@ import (
)

type SnapshotProfile struct {
AwsAccesskey string `json:"AWS_ACCESS_KEY_ID"`
AwsSecretkey string `json:"AWS_SECRET_ACCESS_KEY"`
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"`
ResticPassword string `json:"RESTIC_PASSWORD"`
TimeInterval int `json:"timeInterval"`
ResticSourceRepo string `json:"resticSourceRepo"`
}

func CreateSnapshot(w http.ResponseWriter, r *http.Request) {

// TODO Remove this Sleep time after changing provisioner to send request after PVC Attachment event
time.Sleep(20*time.Second)
w.Header().Set("Content-Type","application/json")
time.Sleep(20 * time.Second)
w.Header().Set("Content-Type", "application/json")

fmt.Println("---------------------Getting Source Mount Point ---------------------")
//TODO Configure grep based on the pvc name recieved in this request
cmdToGetPVCMountPoint := "df -h --output=target | grep csi"
cmdToGetFileSystemMountPoint, errno := exec.Command("bash", "-c", cmdToGetPVCMountPoint).Output()
if errno != nil {
fmt.Sprintf("Failed to execute command: %s", cmdToGetFileSystemMountPoint)
fmt.Sprintf("Failed to execute command: %s", cmdToGetFileSystemMountPoint)
}
mountPointToBeBackedUp := string(cmdToGetFileSystemMountPoint)
fmt.Println("The MountPoint to be backed up : ",mountPointToBeBackedUp )
fmt.Println("The MountPoint to be backed up : ", mountPointToBeBackedUp)

fmt.Println("---------------------Backing Up ---------------------")
var snapshotProfile SnapshotProfile
_ = json.NewDecoder(r.Body).Decode(&snapshotProfile)
fmt.Println(snapshotProfile)
os.Setenv("AWS_ACCESS_KEY_ID",snapshotProfile.AwsAccesskey)
os.Setenv("AWS_SECRET_ACCESS_KEY",snapshotProfile.AwsSecretkey)
os.Setenv("RESTIC_REPOSITORY",snapshotProfile.ResticRepository)
os.Setenv("RESTIC_PASSWORD",snapshotProfile.ResticPassword)
os.Setenv("AWS_ACCESS_KEY_ID", snapshotProfile.AwsAccesskey)
os.Setenv("AWS_SECRET_ACCESS_KEY", snapshotProfile.AwsSecretkey)
os.Setenv("RESTIC_REPOSITORY", snapshotProfile.ResticRepository)
os.Setenv("RESTIC_PASSWORD", snapshotProfile.ResticPassword)

timeD := time.Duration(snapshotProfile.TimeInterval )
ticker := time.NewTicker(timeD* time.Second)
timeD := time.Duration(snapshotProfile.TimeInterval)
ticker := time.NewTicker(timeD * time.Second)
done := make(chan bool)
go func() {
for {
Expand All @@ -68,15 +68,15 @@ func CreateSnapshot(w http.ResponseWriter, r *http.Request) {
return
case t := <-ticker.C:
fmt.Println("Backup Started at", t)
cmdToDoBackup := "restic backup "+mountPointToBeBackedUp
cmdToDoBackup := "restic backup " + mountPointToBeBackedUp
cmdOutputForBackup, errBck := exec.Command("bash", "-c", cmdToDoBackup).Output()
if errBck != nil {
fmt.Sprintf("Failed to execute command: %s", string(cmdOutputForBackup))
}
fmt.Println("Backup Success : ", string(cmdOutputForBackup))

fmt.Println("---------------------SnapShots---------------------")
cmd := exec.Command("restic", "snapshots" )
cmd := exec.Command("restic", "snapshots")
cmd.Stderr = os.Stdout
cmd.Stdout = os.Stdout

Expand All @@ -89,4 +89,4 @@ func CreateSnapshot(w http.ResponseWriter, r *http.Request) {
}
}()
json.NewEncoder(w).Encode("Back Up Done Successfully")
}
}

0 comments on commit b7055bc

Please sign in to comment.