ceph-csi/vendor/github.com/kubernetes-csi/drivers/pkg/flexadapter/controllerserver.go

91 lines
2.8 KiB
Go
Raw Normal View History

2018-01-09 18:57:14 +00:00
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flexadapter
import (
2018-11-26 18:23:56 +00:00
"github.com/container-storage-interface/spec/lib/go/csi"
2018-01-09 18:57:14 +00:00
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/kubernetes-csi/drivers/pkg/csi-common"
)
const (
deviceID = "deviceID"
)
type controllerServer struct {
2018-02-15 13:50:31 +00:00
flexDriver *flexVolumeDriver
2018-01-09 18:57:14 +00:00
*csicommon.DefaultControllerServer
}
func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
2018-03-06 22:33:18 +00:00
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME); err != nil {
2018-01-09 18:57:14 +00:00
return nil, err
}
2018-02-15 13:50:31 +00:00
cap := req.GetVolumeCapability()
fsType := "ext4"
if cap != nil {
mount := req.GetVolumeCapability().GetMount()
fsType = mount.FsType
}
2018-01-09 18:57:14 +00:00
2018-02-15 13:50:31 +00:00
call := cs.flexDriver.NewDriverCall(attachCmd)
2018-11-26 18:23:56 +00:00
call.AppendSpec(req.GetVolumeId(), fsType, req.GetReadonly(), req.GetVolumeContext())
2018-01-09 18:57:14 +00:00
call.Append(req.GetNodeId())
callStatus, err := call.Run()
if isCmdNotSupportedErr(err) {
return nil, status.Error(codes.Unimplemented, "")
} else if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
2018-11-26 18:23:56 +00:00
publishContext := map[string]string{}
2018-01-09 18:57:14 +00:00
2018-11-26 18:23:56 +00:00
publishContext[deviceID] = callStatus.DevicePath
2018-01-09 18:57:14 +00:00
return &csi.ControllerPublishVolumeResponse{
2018-11-26 18:23:56 +00:00
PublishContext: publishContext,
2018-01-09 18:57:14 +00:00
}, nil
}
func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
2018-03-06 22:33:18 +00:00
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME); err != nil {
2018-01-09 18:57:14 +00:00
return nil, err
}
2018-02-15 13:50:31 +00:00
call := cs.flexDriver.NewDriverCall(detachCmd)
2018-01-09 18:57:14 +00:00
call.Append(req.GetVolumeId())
call.Append(req.GetNodeId())
_, err := call.Run()
if isCmdNotSupportedErr(err) {
return nil, status.Error(codes.Unimplemented, "")
} else if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &csi.ControllerUnpublishVolumeResponse{}, nil
}
func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
2018-11-26 18:23:56 +00:00
return cs.DefaultControllerServer.ValidateVolumeCapabilities(ctx, req)
2018-01-09 18:57:14 +00:00
}