Skip to content

Commit

Permalink
Update external-provisioner to use csi spec 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
msau42 committed Nov 15, 2018
1 parent 64d2d4e commit e9c88d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 8 additions & 8 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func getDriverCapabilities(conn *grpc.ClientConn, timeout time.Duration) (sets.I
switch service.GetType() {
case csi.PluginCapability_Service_CONTROLLER_SERVICE:
capabilities.Insert(PluginCapability_CONTROLLER_SERVICE)
case csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS:
case csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS:
capabilities.Insert(PluginCapability_ACCESSIBILITY_CONSTRAINTS)
}
}
Expand Down Expand Up @@ -458,7 +458,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
if err != nil {
return nil, err
}
req.ControllerCreateSecrets = provisionerCredentials
req.Secrets = provisionerCredentials

// Resolve controller publish, node stage, node publish secret references
controllerPublishSecretRef, err := getSecretReference(controllerPublishSecretNameKey, controllerPublishSecretNamespaceKey, options.Parameters, pvName, options.PVC)
Expand Down Expand Up @@ -503,16 +503,16 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
glog.V(3).Infof("create volume rep: %+v", *rep.Volume)
}
volumeAttributes := map[string]string{provisionerIDKey: p.identity}
for k, v := range rep.Volume.Attributes {
for k, v := range rep.Volume.VolumeContext {
volumeAttributes[k] = v
}
respCap := rep.GetVolume().GetCapacityBytes()
if respCap < volSizeBytes {
capErr := fmt.Errorf("created volume capacity %v less than requested capacity %v", respCap, volSizeBytes)
delReq := &csi.DeleteVolumeRequest{
VolumeId: rep.GetVolume().GetId(),
VolumeId: rep.GetVolume().GetVolumeId(),
}
delReq.ControllerDeleteSecrets = provisionerCredentials
delReq.Secrets = provisionerCredentials
ctx, cancel := context.WithTimeout(context.Background(), p.timeout)
defer cancel()
_, err := p.csiClient.DeleteVolume(ctx, delReq)
Expand All @@ -537,7 +537,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
PersistentVolumeSource: v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
Driver: driverState.driverName,
VolumeHandle: p.volumeIdToHandle(rep.Volume.Id),
VolumeHandle: p.volumeIdToHandle(rep.Volume.VolumeId),
FSType: fsType,
VolumeAttributes: volumeAttributes,
ControllerPublishSecretRef: controllerPublishSecretRef,
Expand Down Expand Up @@ -584,7 +584,7 @@ func (p *csiProvisioner) getVolumeContentSource(options controller.VolumeOptions

snapshotSource := csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
Id: snapContentObj.Spec.VolumeSnapshotSource.CSI.SnapshotHandle,
SnapshotId: snapContentObj.Spec.VolumeSnapshotSource.CSI.SnapshotHandle,
},
}
glog.V(5).Infof("VolumeContentSource_Snapshot %+v", snapshotSource)
Expand Down Expand Up @@ -641,7 +641,7 @@ func (p *csiProvisioner) Delete(volume *v1.PersistentVolume) error {
if err != nil {
return err
}
req.ControllerDeleteSecrets = credentials
req.Secrets = credentials
}

}
Expand Down
17 changes: 9 additions & 8 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/kubernetes-incubator/external-storage/lib/controller"
"google.golang.org/grpc"
"k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
storage "k8s.io/api/storage/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -287,7 +288,7 @@ func TestGetDriverCapabilities(t *testing.T) {
switch *cap {
case csi.PluginCapability_Service_CONTROLLER_SERVICE:
ok = ok && capabilities.Has(PluginCapability_CONTROLLER_SERVICE)
case csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS:
case csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS:
ok = ok && capabilities.Has(PluginCapability_ACCESSIBILITY_CONSTRAINTS)
}
}
Expand Down Expand Up @@ -443,7 +444,7 @@ func TestCreateDriverReturnsInvalidCapacityDuringProvision(t *testing.T) {
out := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: requestedBytes - 1,
Id: "test-volume-id",
VolumeId: "test-volume-id",
},
}

Expand Down Expand Up @@ -544,7 +545,7 @@ func provisionWithTopologyMockServerSetupExpectations(identityServer *driver.Moc
{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS,
Type: csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS,
},
},
},
Expand Down Expand Up @@ -1133,7 +1134,7 @@ func TestProvision(t *testing.T) {
out := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: requestedBytes,
Id: "test-volume-id",
VolumeId: "test-volume-id",
},
}

Expand Down Expand Up @@ -1220,7 +1221,7 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
SelfLink: "/apis/snapshot.storage.k8s.io/v1alpha1/namespaces/" + "default" + "/volumesnapshots/" + name,
},
Spec: crdv1.VolumeSnapshotSpec{
Source: &crdv1.TypedLocalObjectReference{
Source: &corev1.TypedLocalObjectReference{
Name: claimName,
Kind: "PersistentVolumeClaim",
},
Expand Down Expand Up @@ -1512,7 +1513,7 @@ func TestProvisionFromSnapshot(t *testing.T) {
out := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: requestedBytes,
Id: "test-volume-id",
VolumeId: "test-volume-id",
},
}

Expand Down Expand Up @@ -1607,7 +1608,7 @@ func TestProvisionWithTopology(t *testing.T) {
out := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: requestBytes,
Id: "test-volume-id",
VolumeId: "test-volume-id",
AccessibleTopology: accessibleTopology,
},
}
Expand Down Expand Up @@ -1645,7 +1646,7 @@ func TestProvisionWithMountOptions(t *testing.T) {
out := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: requestBytes,
Id: "test-volume-id",
VolumeId: "test-volume-id",
},
}

Expand Down

0 comments on commit e9c88d2

Please sign in to comment.