vendor update for CSI 0.3.0

This commit is contained in:
gman
2018-07-18 16:47:22 +02:00
parent 6f484f92fc
commit 8ea659f0d5
6810 changed files with 438061 additions and 193861 deletions

View File

@ -13,7 +13,7 @@ $ sudo ./_output/hostpathplugin --endpoint tcp://127.0.0.1:10000 --nodeid CSINod
```
### Test using csc
Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc
Get ```csc``` tool from https://github.com/rexray/gocsi/tree/master/csc
#### Get plugin info
```
@ -21,12 +21,6 @@ $ csc identity plugin-info --endpoint tcp://127.0.0.1:10000
"csi-hostpath" "0.1.0"
```
#### Get supported versions
```
$ csc identity supported-versions --endpoint tcp://127.0.0.1:10000
0.1.0
```
#### Create a volume
```
$ csc controller new --endpoint tcp://127.0.0.1:10000 --cap 1,block CSIVolumeName

View File

@ -17,6 +17,7 @@ limitations under the License.
package hostpath
import (
"fmt"
"os"
"github.com/golang/glog"
@ -30,8 +31,9 @@ import (
)
const (
deviceID = "deviceID"
provisionRoot = "/tmp/"
deviceID = "deviceID"
provisionRoot = "/tmp/"
maxStorageCapacity = tib
)
type controllerServer struct {
@ -39,6 +41,10 @@ type controllerServer struct {
}
func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
glog.V(3).Infof("invalid create volume req: %v", req)
return nil, err
}
// Check arguments
if len(req.GetName()) == 0 {
@ -47,23 +53,49 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
if req.GetVolumeCapabilities() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume Capabilities missing in request")
}
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
glog.V(3).Infof("invalid create volume req: %v", req)
return nil, err
// Need to check for already existing volume name, and if found
// check for the requested capacity and already allocated capacity
if exVol, err := getVolumeByName(req.GetName()); err == nil {
// Since err is nil, it means the volume with the same name already exists
// need to check if the size of exisiting volume is the same as in new
// request
if exVol.VolSize >= int64(req.GetCapacityRange().GetRequiredBytes()) {
// exisiting volume is compatible with new request and should be reused.
// TODO (sbezverk) Do I need to make sure that RBD volume still exists?
return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
Id: exVol.VolID,
CapacityBytes: int64(exVol.VolSize),
Attributes: req.GetParameters(),
},
}, nil
}
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("Volume with the same name: %s but with different size already exist", req.GetName()))
}
volumeId := uuid.NewUUID().String()
path := provisionRoot + volumeId
// Check for maximum available capacity
capacity := int64(req.GetCapacityRange().GetRequiredBytes())
if capacity >= maxStorageCapacity {
return nil, status.Errorf(codes.OutOfRange, "Requested capacity %d exceeds maximum allowed %d", capacity, maxStorageCapacity)
}
volumeID := uuid.NewUUID().String()
path := provisionRoot + volumeID
err := os.MkdirAll(path, 0777)
if err != nil {
glog.V(3).Infof("failed to create volume: %v", err)
return nil, err
}
glog.V(4).Infof("create volume %s", path)
hostPathVol := hostPathVolume{}
hostPathVol.VolName = req.GetName()
hostPathVol.VolID = volumeID
hostPathVol.VolSize = capacity
hostPathVol.VolPath = path
hostPathVolumes[volumeID] = hostPathVol
return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
Id: volumeId,
Id: volumeID,
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
Attributes: req.GetParameters(),
},
}, nil
}
@ -79,11 +111,11 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
glog.V(3).Infof("invalid delete volume req: %v", req)
return nil, err
}
volumeId := req.VolumeId
glog.V(4).Infof("deleting volume %s", volumeId)
path := provisionRoot + volumeId
volumeID := req.VolumeId
glog.V(4).Infof("deleting volume %s", volumeID)
path := provisionRoot + volumeID
os.RemoveAll(path)
delete(hostPathVolumes, volumeID)
return &csi.DeleteVolumeResponse{}, nil
}
@ -96,6 +128,9 @@ func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req
if req.GetVolumeCapabilities() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume capabilities missing in request")
}
if _, ok := hostPathVolumes[req.GetVolumeId()]; !ok {
return nil, status.Error(codes.NotFound, "Volume does not exist")
}
for _, cap := range req.VolumeCapabilities {
if cap.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {

View File

@ -1,6 +0,0 @@
FROM alpine
LABEL maintainers="Kubernetes Authors"
LABEL description="HostPath CSI Plugin"
COPY hostpathplugin /hostpathplugin
ENTRYPOINT ["/hostpathplugin"]

View File

@ -1,13 +0,0 @@
FROM golang:alpine
LABEL maintainers="Kubernetes Authors"
LABEL description="HostPath CSI Plugin"
RUN apk add --no-cache git make wget
RUN wget https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 && \
chmod +x dep-linux-amd64 && \
mv dep-linux-amd64 /usr/bin/dep
RUN go get -d github.com/kubernetes-csi/drivers/app/hostpathplugin
RUN cd /go/src/github.com/kubernetes-csi/drivers && \
dep ensure && \
make hostpath && \
cp _output/hostpathplugin /hostpathplugin

View File

@ -1,10 +0,0 @@
#!/bin/sh
PROG=hostpathplugin
docker build --rm -f Dockerfile.builder -t ${PROG}:builder .
docker run --rm --privileged -v $PWD:/host ${PROG}:builder cp /${PROG} /host/${PROG}
sudo chown $USER ${PROG}
docker build --rm -t docker.io/k8scsi/${PROG} .
docker rmi ${PROG}:builder
rm -f ${PROG}

View File

@ -17,12 +17,23 @@ limitations under the License.
package hostpath
import (
"fmt"
"github.com/container-storage-interface/spec/lib/go/csi/v0"
"github.com/golang/glog"
"github.com/kubernetes-csi/drivers/pkg/csi-common"
)
const (
kib int64 = 1024
mib int64 = kib * 1024
gib int64 = mib * 1024
gib100 int64 = gib * 100
tib int64 = gib * 1024
tib100 int64 = tib * 100
)
type hostPath struct {
driver *csicommon.CSIDriver
@ -34,11 +45,24 @@ type hostPath struct {
cscap []*csi.ControllerServiceCapability
}
type hostPathVolume struct {
VolName string `json:"volName"`
VolID string `json:"volID"`
VolSize int64 `json:"volSize"`
VolPath string `json:"volPath"`
}
var hostPathVolumes map[string]hostPathVolume
var (
hostPathDriver *hostPath
vendorVersion = "0.2.0"
vendorVersion = "0.3.0"
)
func init() {
hostPathVolumes = map[string]hostPathVolume{}
}
func GetHostPathDriver() *hostPath {
return &hostPath{}
}
@ -81,3 +105,19 @@ func (hp *hostPath) Run(driverName, nodeID, endpoint string) {
s.Start(endpoint, hp.ids, hp.cs, hp.ns)
s.Wait()
}
func getVolumeByID(volumeID string) (hostPathVolume, error) {
if hostPathVol, ok := hostPathVolumes[volumeID]; ok {
return hostPathVol, nil
}
return hostPathVolume{}, fmt.Errorf("volume id %s does not exit in the volumes list", volumeID)
}
func getVolumeByName(volName string) (hostPathVolume, error) {
for _, hostPathVol := range hostPathVolumes {
if hostPathVol.VolName == volName {
return hostPathVol, nil
}
}
return hostPathVolume{}, fmt.Errorf("volume name %s does not exit in the volumes list", volName)
}

View File

@ -76,7 +76,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
attrib := req.GetVolumeAttributes()
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
glog.V(4).Infof("target %v\nfstype %v\ndevice %v\nreadonly %v\nattributes %v\n mountflags %v\n",
glog.V(4).Infof("target %v\nfstype %v\ndevice %v\nreadonly %v\nvolumeId %v\nattributes %v\nmountflags %v\n",
targetPath, fsType, deviceId, readOnly, volumeId, attrib, mountFlags)
options := []string{"bind"}