Skip to content

Commit

Permalink
Make csi-provisioner talk to soda apiserver via proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
asifdxtreme committed Sep 27, 2020
1 parent 668dcef commit b62824d
Showing 1 changed file with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import (
"context"
"errors"
"fmt"

"encoding/json"
"io/ioutil"
"net/http"

"math"
"os"
"strings"
Expand Down Expand Up @@ -182,8 +187,7 @@ var (
secretNameKey: prefixedControllerExpandSecretNameKey,
secretNamespaceKey: prefixedControllerExpandSecretNamespaceKey,
}
operationTimeout = 10*time.Second

operationTimeout = 10 * time.Second
)

// ProvisionerCSITranslator contains the set of CSI Translation functionality
Expand Down Expand Up @@ -424,6 +428,28 @@ func (p *csiProvisioner) Provision(options controller.ProvisionOptions) (*v1.Per
return pv, err
}

type CustomPropertiesSpec map[string]interface{}

func (cps CustomPropertiesSpec) IsEmpty() bool {
if nil == cps {
return true
}
return false
}

func (cps CustomPropertiesSpec) GetDriverPreference() string {
var driverName string
if cps.IsEmpty() {
return "NoDriverFound"
}
for k, v := range cps {
if k == "driver" {
driverName = fmt.Sprintf("%v", v)
fmt.Println(driverName)
}
}
return driverName
}
func (p *csiProvisioner) ProvisionExt(options controller.ProvisionOptions) (*v1.PersistentVolume, controller.ProvisioningState, error) {
if options.StorageClass == nil {
return nil, controller.ProvisioningFinished, errors.New("storage class was nil")
Expand All @@ -434,36 +460,34 @@ func (p *csiProvisioner) ProvisionExt(options controller.ProvisionOptions) (*v1.
if err != nil {
klog.Fatalf("Error getting CSI driver name: %s", err)
}
klog.Infof("The Backend Driver Name is : %s ",backendDriverName)
klog.Infof("The provisioner.DriverName is : %s ",p.driverName)
klog.Infof("The Backend Driver Name is : %s ", backendDriverName)
klog.Infof("The provisioner.DriverName is : %s ", p.driverName)
klog.Infof("The options.StorageClass.Provisioner is : %s ", options.StorageClass.Provisioner)

//TODO Make this code work with SODA API-Server (Issue is with Grpc version, soda uses v1.29.1 whereas csi-provisioner uses v1.26.0
/*client, err := opensds.GetClient("192.168.20.61:50040", "noauth")
if client == nil || err != nil {
klog.Errorf("get opensds client failed: %v", err)
}
if options.StorageClass.Provisioner == "soda-csi-block" {
if options.StorageClass.Provisioner == "soda-csi" {
for k, v := range options.StorageClass.Parameters {
klog.Infof("The parameters in the StorageClass are : %s ===== %s",k,v)
klog.Infof("The parameters in the StorageClass are : %s ===== %s", k, v)
if k == "profile" {

profile, errosds := client.GetProfile(v)
if errosds != nil {
klog.Infof("Got error in GetProfile : %s ===== %s", errosds.Error())
}
klog.Infof("The profile name recieved in the storageClass is: %s ===== %s",profile.Name)
if backendDriverName != profile.Name {
return nil, controller.ProvisioningFinished, &controller.IgnoredError{
Reason: fmt.Sprintf("PVC doesnot match the current driver name : %s with expected %s",
p.driverName, profile.Name),
response, err := http.Get("http://soda-proxy:50029/getprofile/" + v)
if err != nil {
klog.Infof("Got error in GetProfile : %s ===== %s", err.Error())
} else {
data, _ := ioutil.ReadAll(response.Body)
var customProperties *CustomPropertiesSpec
json.Unmarshal(data, &customProperties)
klog.Infof("The profile name recieved in the storageClass is: %s",customProperties.GetDriverPreference())
if backendDriverName != customProperties.GetDriverPreference() {
return nil, controller.ProvisioningFinished, &controller.IgnoredError{
Reason: fmt.Sprintf("PVC doesnot match the current driver name : %s with expected %s",
p.driverName, "profile.Name"),
}
}
}
}
}
}*/
if options.StorageClass.Provisioner == "soda-csi-block" {
}
/*if options.StorageClass.Provisioner == "soda-csi-block" {
for k, v := range options.StorageClass.Parameters {
klog.Infof("The parameters in the StorageClass are : %s ===== %s",k,v)
if k == "profile" {
Expand All @@ -475,8 +499,7 @@ func (p *csiProvisioner) ProvisionExt(options controller.ProvisionOptions) (*v1.
}
}
}
}

}*/

if options.PVC.Annotations[annStorageProvisioner] != p.driverName && options.PVC.Annotations[annMigratedTo] != p.driverName {
// The storage provisioner annotation may not equal driver name but the
Expand Down

0 comments on commit b62824d

Please sign in to comment.