2018-03-05 11:59:47 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 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 cephfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/golang/glog"
|
|
|
|
|
2018-11-24 18:48:36 +00:00
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
2018-03-05 11:59:47 +00:00
|
|
|
"github.com/kubernetes-csi/drivers/pkg/csi-common"
|
2018-12-19 14:26:16 +00:00
|
|
|
|
|
|
|
"github.com/ceph/ceph-csi/pkg/util"
|
2018-03-05 11:59:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-12-04 20:04:14 +00:00
|
|
|
PluginFolder = "/var/lib/kubelet/plugins_registry/csi-cephfsplugin"
|
2018-11-29 18:15:52 +00:00
|
|
|
Version = "1.0.0"
|
2018-03-05 11:59:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type cephfsDriver struct {
|
|
|
|
driver *csicommon.CSIDriver
|
|
|
|
|
2018-04-13 12:53:17 +00:00
|
|
|
is *identityServer
|
|
|
|
ns *nodeServer
|
|
|
|
cs *controllerServer
|
2018-03-05 11:59:47 +00:00
|
|
|
|
|
|
|
caps []*csi.VolumeCapability_AccessMode
|
|
|
|
cscaps []*csi.ControllerServiceCapability
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2018-04-13 12:53:17 +00:00
|
|
|
driver *cephfsDriver
|
|
|
|
DefaultVolumeMounter string
|
2018-03-05 11:59:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewCephFSDriver() *cephfsDriver {
|
|
|
|
return &cephfsDriver{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIdentityServer(d *csicommon.CSIDriver) *identityServer {
|
|
|
|
return &identityServer{
|
|
|
|
DefaultIdentityServer: csicommon.NewDefaultIdentityServer(d),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-19 14:26:16 +00:00
|
|
|
func NewControllerServer(d *csicommon.CSIDriver, cachePersister util.CachePersister) *controllerServer {
|
2018-03-05 11:59:47 +00:00
|
|
|
return &controllerServer{
|
|
|
|
DefaultControllerServer: csicommon.NewDefaultControllerServer(d),
|
2018-12-19 14:26:16 +00:00
|
|
|
MetadataStore: cachePersister,
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewNodeServer(d *csicommon.CSIDriver) *nodeServer {
|
|
|
|
return &nodeServer{
|
|
|
|
DefaultNodeServer: csicommon.NewDefaultNodeServer(d),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-19 14:26:16 +00:00
|
|
|
func (fs *cephfsDriver) Run(driverName, nodeId, endpoint, volumeMounter string, cachePersister util.CachePersister) {
|
2018-04-13 12:53:17 +00:00
|
|
|
glog.Infof("Driver: %v version: %v", driverName, Version)
|
|
|
|
|
|
|
|
// Configuration
|
|
|
|
|
2018-08-14 14:48:30 +00:00
|
|
|
if err := loadAvailableMounters(); err != nil {
|
|
|
|
glog.Fatalf("cephfs: failed to load ceph mounters: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-04-13 12:53:17 +00:00
|
|
|
if volumeMounter != "" {
|
|
|
|
if err := validateMounter(volumeMounter); err != nil {
|
|
|
|
glog.Fatalln(err)
|
|
|
|
} else {
|
|
|
|
DefaultVolumeMounter = volumeMounter
|
|
|
|
}
|
|
|
|
} else {
|
2018-08-14 14:48:30 +00:00
|
|
|
// Pick the first available mounter as the default one.
|
|
|
|
// The choice is biased towards "fuse" in case both
|
|
|
|
// ceph fuse and kernel mounters are available.
|
2018-08-14 09:19:41 +00:00
|
|
|
DefaultVolumeMounter = availableMounters[0]
|
2018-04-13 12:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glog.Infof("cephfs: setting default volume mounter to %s", DefaultVolumeMounter)
|
2018-03-05 11:59:47 +00:00
|
|
|
|
|
|
|
// Initialize default library driver
|
|
|
|
|
2018-04-13 12:53:17 +00:00
|
|
|
fs.driver = csicommon.NewCSIDriver(driverName, Version, nodeId)
|
2018-03-05 11:59:47 +00:00
|
|
|
if fs.driver == nil {
|
|
|
|
glog.Fatalln("Failed to initialize CSI driver")
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.driver.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{
|
|
|
|
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
|
|
|
|
})
|
|
|
|
|
|
|
|
fs.driver.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{
|
2018-03-07 13:11:54 +00:00
|
|
|
csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
|
2018-03-05 11:59:47 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Create gRPC servers
|
|
|
|
|
2018-04-13 12:53:17 +00:00
|
|
|
fs.is = NewIdentityServer(fs.driver)
|
2018-03-05 11:59:47 +00:00
|
|
|
fs.ns = NewNodeServer(fs.driver)
|
2018-12-19 14:26:16 +00:00
|
|
|
|
|
|
|
fs.cs = NewControllerServer(fs.driver, cachePersister)
|
2018-03-05 11:59:47 +00:00
|
|
|
|
|
|
|
server := csicommon.NewNonBlockingGRPCServer()
|
2018-04-13 12:53:17 +00:00
|
|
|
server.Start(endpoint, fs.is, fs.cs, fs.ns)
|
2018-03-05 11:59:47 +00:00
|
|
|
server.Wait()
|
|
|
|
}
|