From b7055bc62375e2e815e4dff022445842764b0c27 Mon Sep 17 00:00:00 2001 From: asifdxtreme Date: Mon, 28 Jun 2021 21:32:06 +0530 Subject: [PATCH] go fmt project --- .../pkg/controller/controller.go | 9 ++--- .../sidecars/soda-proxy/cmd/proxy.go | 14 ++++++++ .../sidecars/soda-proxy/deploy/sodaProxy.yaml | 4 +-- .../pkg/controller/profile/profile.go | 14 ++++++++ .../pkg/controller/snapshot/snapshot.go | 26 ++++++++------ soda-syncer/pkg/snapshot/worker.go | 34 +++++++++---------- 6 files changed, 64 insertions(+), 37 deletions(-) diff --git a/csi-plug-n-play/sidecars/soda-csi-provisioner/external-provisioner/pkg/controller/controller.go b/csi-plug-n-play/sidecars/soda-csi-provisioner/external-provisioner/pkg/controller/controller.go index 9b88d5001..02538bd56 100644 --- a/csi-plug-n-play/sidecars/soda-csi-provisioner/external-provisioner/pkg/controller/controller.go +++ b/csi-plug-n-play/sidecars/soda-csi-provisioner/external-provisioner/pkg/controller/controller.go @@ -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 ( @@ -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 @@ -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 { @@ -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 != "" { diff --git a/csi-plug-n-play/sidecars/soda-proxy/cmd/proxy.go b/csi-plug-n-play/sidecars/soda-proxy/cmd/proxy.go index 9f42fb064..007beb5c3 100644 --- a/csi-plug-n-play/sidecars/soda-proxy/cmd/proxy.go +++ b/csi-plug-n-play/sidecars/soda-proxy/cmd/proxy.go @@ -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 ( diff --git a/csi-plug-n-play/sidecars/soda-proxy/deploy/sodaProxy.yaml b/csi-plug-n-play/sidecars/soda-proxy/deploy/sodaProxy.yaml index 1b7f4c829..4068a6b90 100644 --- a/csi-plug-n-play/sidecars/soda-proxy/deploy/sodaProxy.yaml +++ b/csi-plug-n-play/sidecars/soda-proxy/deploy/sodaProxy.yaml @@ -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 diff --git a/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/profile/profile.go b/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/profile/profile.go index f9ecdb723..9a6bddda4 100644 --- a/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/profile/profile.go +++ b/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/profile/profile.go @@ -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 ( diff --git a/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/snapshot/snapshot.go b/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/snapshot/snapshot.go index e227219e7..bc970e5cd 100644 --- a/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/snapshot/snapshot.go +++ b/csi-plug-n-play/sidecars/soda-proxy/pkg/controller/snapshot/snapshot.go @@ -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 ( @@ -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"` @@ -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) } diff --git a/soda-syncer/pkg/snapshot/worker.go b/soda-syncer/pkg/snapshot/worker.go index fdb8a11cd..644af7a7a 100644 --- a/soda-syncer/pkg/snapshot/worker.go +++ b/soda-syncer/pkg/snapshot/worker.go @@ -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 { @@ -68,7 +68,7 @@ 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)) @@ -76,7 +76,7 @@ func CreateSnapshot(w http.ResponseWriter, r *http.Request) { 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 @@ -89,4 +89,4 @@ func CreateSnapshot(w http.ResponseWriter, r *http.Request) { } }() json.NewEncoder(w).Encode("Back Up Done Successfully") -} \ No newline at end of file +}