forked from moby/swarmkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds code for creating CSI volumes. This includes: * The basic Plugin object, which manages the connection to the CSI plugin * The basic VolumeManager object, which manages plugins and responds to store events This also includes lots of tests and tests rigging, including fake CSI clients. Signed-off-by: Drew Erny <derny@mirantis.com>
- Loading branch information
Showing
17 changed files
with
2,661 additions
and
927 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package volumes | ||
|
||
import ( | ||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"github.com/docker/swarmkit/api" | ||
) | ||
|
||
// convert.go contains functions for converting swarm objects into CSI requests | ||
// and back again. | ||
|
||
// makeTopology converts a swarmkit topology into a CSI topology. | ||
func makeTopologyRequirement(t *api.TopologyRequirement) *csi.TopologyRequirement { | ||
return &csi.TopologyRequirement{ | ||
Requisite: makeTopologies(t.Requisite), | ||
Preferred: makeTopologies(t.Preferred), | ||
} | ||
} | ||
|
||
// makeTopologies converts a slice of swarmkit topologies into a slice of CSI | ||
// topologies. | ||
func makeTopologies(ts []*api.Topology) []*csi.Topology { | ||
if ts == nil { | ||
return nil | ||
} | ||
csiTops := make([]*csi.Topology, len(ts)) | ||
for i, t := range ts { | ||
csiTops[i] = makeTopology(t) | ||
} | ||
|
||
return csiTops | ||
} | ||
|
||
// makeTopology converts a swarmkit topology into a CSI topology. These types | ||
// are essentially homologous, with the swarm type being copied verbatim from | ||
// the CSI type (for build reasons). | ||
func makeTopology(t *api.Topology) *csi.Topology { | ||
return &csi.Topology{ | ||
Segments: t.Segments, | ||
} | ||
} | ||
|
||
func makeAccessMode(am *api.VolumeAccessMode) *csi.VolumeCapability { | ||
var mode csi.VolumeCapability_AccessMode_Mode | ||
switch am.Scope { | ||
case api.VolumeScopeSingleNode: | ||
switch am.Sharing { | ||
case api.VolumeSharingNone, api.VolumeSharingOneWriter, api.VolumeSharingAll: | ||
mode = csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER | ||
case api.VolumeSharingReadOnly: | ||
mode = csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY | ||
} | ||
case api.VolumeScopeMultiNode: | ||
switch am.Sharing { | ||
case api.VolumeSharingReadOnly: | ||
mode = csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY | ||
case api.VolumeSharingOneWriter: | ||
mode = csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER | ||
case api.VolumeSharingAll: | ||
mode = csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER | ||
} | ||
} | ||
|
||
return &csi.VolumeCapability{ | ||
AccessMode: &csi.VolumeCapability_AccessMode{ | ||
Mode: mode, | ||
}, | ||
} | ||
} | ||
|
||
// makeCapcityRange converts the swarmkit CapacityRange object to the | ||
// equivalent CSI object | ||
func makeCapacityRange(cr *api.CapacityRange) *csi.CapacityRange { | ||
if cr == nil { | ||
return nil | ||
} | ||
|
||
return &csi.CapacityRange{ | ||
RequiredBytes: cr.RequiredBytes, | ||
LimitBytes: cr.LimitBytes, | ||
} | ||
} | ||
|
||
// unmakeTopologies transforms a CSI-type topology into the equivalent swarm | ||
// type. it is called "unmakeTopologies" because it performs the inverse of | ||
// "makeTopologies". | ||
func unmakeTopologies(topologies []*csi.Topology) []*api.Topology { | ||
if topologies == nil { | ||
return nil | ||
} | ||
swarmTopologies := make([]*api.Topology, len(topologies)) | ||
for i, t := range topologies { | ||
swarmTopologies[i] = unmakeTopology(t) | ||
} | ||
return swarmTopologies | ||
} | ||
|
||
// unmakeTopology transforms a CSI-type topology into the equivalent swarm | ||
// type. | ||
func unmakeTopology(topology *csi.Topology) *api.Topology { | ||
return &api.Topology{ | ||
Segments: topology.Segments, | ||
} | ||
} | ||
|
||
// makeVolumeInfo converts a csi.Volume object into a swarmkit VolumeInfo | ||
// object. | ||
func makeVolumeInfo(csiVolume *csi.Volume) *api.VolumeInfo { | ||
return &api.VolumeInfo{ | ||
CapacityBytes: csiVolume.CapacityBytes, | ||
VolumeContext: csiVolume.VolumeContext, | ||
VolumeID: csiVolume.VolumeId, | ||
AccessibleTopology: unmakeTopologies(csiVolume.AccessibleTopology), | ||
} | ||
} |
Oops, something went wrong.