Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from openebs/openebs-provisioner-dev
Browse files Browse the repository at this point in the history
Add the fixes for non default namespace
  • Loading branch information
kmova authored Dec 25, 2017
2 parents bf25c9f + a1b5a6e commit d922e54
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
24 changes: 21 additions & 3 deletions openebs/openebs-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import (

const (
provisionerName = "openebs.io/provisioner-iscsi"
// BetaStorageClassAnnotation represents the beta/previous StorageClass annotation.
// It's currently still used and will be held for backwards compatibility
BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class"
)

type openEBSProvisioner struct {
Expand Down Expand Up @@ -90,7 +93,13 @@ func (p *openEBSProvisioner) Provision(options controller.VolumeOptions) (*v1.Pe
volSize := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
volumeSpec.Metadata.Labels.Storage = volSize.String()

volumeSpec.Metadata.Labels.StorageClass = *options.PVC.Spec.StorageClassName
className := GetStorageClassName(options)

if className == nil {
glog.Errorf("Volume has no storage class specified")
} else {
volumeSpec.Metadata.Labels.StorageClass = *className
}
volumeSpec.Metadata.Labels.Namespace = options.PVC.Namespace
volumeSpec.Metadata.Name = options.PVName

Expand All @@ -100,7 +109,7 @@ func (p *openEBSProvisioner) Provision(options controller.VolumeOptions) (*v1.Pe
return nil, err
}

err = openebsVol.ListVolume(options.PVName, &volume)
err = openebsVol.ListVolume(options.PVName, options.PVC.Namespace, &volume)
if err != nil {
glog.Errorf("Error getting volume details: %v", err)
return nil, err
Expand Down Expand Up @@ -195,7 +204,7 @@ func (p *openEBSProvisioner) Delete(volume *v1.PersistentVolume) error {
}

// Issue a delete request to Maya API Server
err := openebsVol.DeleteVolume(volume.Name)
err := openebsVol.DeleteVolume(volume.Name, volume.Spec.ClaimRef.Namespace)
if err != nil {
glog.Errorf("Error while deleting volume: %v", err)
return err
Expand Down Expand Up @@ -252,3 +261,12 @@ func main() {
}

}

// GetPersistentVolumeClass returns StorageClassName.
func GetStorageClassName(options controller.VolumeOptions) *string {
// Use beta annotation first
if class, found := options.PVC.Annotations[BetaStorageClassAnnotation]; found {
return &class
}
return options.PVC.Spec.StorageClassName
}
16 changes: 14 additions & 2 deletions openebs/pkg/v1/maya_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (v OpenEBSVolume) CreateVolume(vs mayav1.VolumeSpec) (string, error) {
}

// ListVolume to get the info of Vsm through a API call to m-apiserver
func (v OpenEBSVolume) ListVolume(vname string, obj interface{}) error {
func (v OpenEBSVolume) ListVolume(vname string, namespace string, obj interface{}) error {

addr := os.Getenv("MAPI_ADDR")
if addr == "" {
Expand All @@ -136,6 +136,12 @@ func (v OpenEBSVolume) ListVolume(vname string, obj interface{}) error {
glog.V(2).Infof("[DEBUG] Get details for Volume :%v", string(vname))

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}

req.Header.Set("namespace", namespace)

c := &http.Client{
Timeout: timeout,
}
Expand All @@ -156,7 +162,7 @@ func (v OpenEBSVolume) ListVolume(vname string, obj interface{}) error {
}

// DeleteVolume to get delete Vsm through a API call to m-apiserver
func (v OpenEBSVolume) DeleteVolume(vname string) error {
func (v OpenEBSVolume) DeleteVolume(vname string, namespace string) error {

addr := os.Getenv("MAPI_ADDR")
if addr == "" {
Expand All @@ -169,6 +175,12 @@ func (v OpenEBSVolume) DeleteVolume(vname string) error {
glog.V(2).Infof("[DEBUG] Delete Volume :%v", string(vname))

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}

req.Header.Set("namespace", namespace)

c := &http.Client{
Timeout: timeout,
}
Expand Down

0 comments on commit d922e54

Please sign in to comment.