2018-03-05 12:59:47 +01:00
|
|
|
/*
|
2019-04-03 10:46:15 +02:00
|
|
|
Copyright 2018 The Ceph-CSI Authors.
|
2018-03-05 12:59:47 +01:00
|
|
|
|
|
|
|
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 (
|
2023-07-11 20:48:51 +05:30
|
|
|
"fmt"
|
|
|
|
|
2021-09-16 20:16:07 +05:30
|
|
|
"github.com/ceph/ceph-csi/internal/cephfs/mounter"
|
2022-02-15 17:41:09 +05:30
|
|
|
"github.com/ceph/ceph-csi/internal/cephfs/store"
|
2021-09-16 19:17:57 +05:30
|
|
|
fsutil "github.com/ceph/ceph-csi/internal/cephfs/util"
|
2023-07-11 20:48:51 +05:30
|
|
|
casceph "github.com/ceph/ceph-csi/internal/csi-addons/cephfs"
|
|
|
|
csiaddons "github.com/ceph/ceph-csi/internal/csi-addons/server"
|
2020-04-17 11:23:49 +02:00
|
|
|
csicommon "github.com/ceph/ceph-csi/internal/csi-common"
|
2023-09-13 16:05:27 +02:00
|
|
|
hc "github.com/ceph/ceph-csi/internal/health-checker"
|
2020-04-23 14:22:55 -04:00
|
|
|
"github.com/ceph/ceph-csi/internal/journal"
|
2020-04-17 11:23:49 +02:00
|
|
|
"github.com/ceph/ceph-csi/internal/util"
|
2023-11-17 11:59:00 +05:30
|
|
|
"github.com/ceph/ceph-csi/internal/util/k8s"
|
2021-08-24 17:03:25 +02:00
|
|
|
"github.com/ceph/ceph-csi/internal/util/log"
|
2019-02-18 17:00:28 +05:30
|
|
|
|
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
2018-03-05 12:59:47 +01:00
|
|
|
)
|
|
|
|
|
2020-07-19 17:51:03 +05:30
|
|
|
// Driver contains the default identity,node and controller struct.
|
2019-01-17 13:21:06 +05:30
|
|
|
type Driver struct {
|
2019-01-17 11:48:18 +05:30
|
|
|
cd *csicommon.CSIDriver
|
2018-03-05 12:59:47 +01:00
|
|
|
|
2019-01-17 13:21:06 +05:30
|
|
|
is *IdentityServer
|
|
|
|
ns *NodeServer
|
|
|
|
cs *ControllerServer
|
2023-07-11 20:48:51 +05:30
|
|
|
// cas is the CSIAddonsServer where CSI-Addons services are handled
|
|
|
|
cas *csiaddons.CSIAddonsServer
|
2018-03-05 12:59:47 +01:00
|
|
|
}
|
|
|
|
|
2020-07-19 17:51:03 +05:30
|
|
|
// NewDriver returns new ceph driver.
|
2019-01-17 13:21:06 +05:30
|
|
|
func NewDriver() *Driver {
|
|
|
|
return &Driver{}
|
2018-03-05 12:59:47 +01:00
|
|
|
}
|
|
|
|
|
2020-07-19 17:51:03 +05:30
|
|
|
// NewIdentityServer initialize a identity server for ceph CSI driver.
|
2019-01-17 13:21:06 +05:30
|
|
|
func NewIdentityServer(d *csicommon.CSIDriver) *IdentityServer {
|
|
|
|
return &IdentityServer{
|
2018-03-05 12:59:47 +01:00
|
|
|
DefaultIdentityServer: csicommon.NewDefaultIdentityServer(d),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 17:51:03 +05:30
|
|
|
// NewControllerServer initialize a controller server for ceph CSI driver.
|
2020-07-10 16:14:59 +05:30
|
|
|
func NewControllerServer(d *csicommon.CSIDriver) *ControllerServer {
|
2019-01-17 13:21:06 +05:30
|
|
|
return &ControllerServer{
|
2018-03-05 12:59:47 +01:00
|
|
|
DefaultControllerServer: csicommon.NewDefaultControllerServer(d),
|
2019-09-12 10:23:37 +05:30
|
|
|
VolumeLocks: util.NewVolumeLocks(),
|
2020-08-04 09:20:13 +05:30
|
|
|
SnapshotLocks: util.NewVolumeLocks(),
|
2024-02-13 14:24:45 +01:00
|
|
|
VolumeGroupLocks: util.NewVolumeLocks(),
|
2020-08-04 09:20:13 +05:30
|
|
|
OperationLocks: util.NewOperationLock(),
|
2018-03-05 12:59:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 17:17:06 +05:30
|
|
|
// NewNodeServer initialize a node server for ceph CSI driver.
|
2022-07-07 00:46:12 +09:00
|
|
|
func NewNodeServer(
|
|
|
|
d *csicommon.CSIDriver,
|
|
|
|
t string,
|
|
|
|
kernelMountOptions string,
|
|
|
|
fuseMountOptions string,
|
2023-11-17 11:59:00 +05:30
|
|
|
nodeLabels, topology, crushLocationMap map[string]string,
|
2022-07-07 00:46:12 +09:00
|
|
|
) *NodeServer {
|
2023-11-17 11:59:00 +05:30
|
|
|
cliReadAffinityMapOptions := util.ConstructReadAffinityMapOption(crushLocationMap)
|
|
|
|
ns := &NodeServer{
|
|
|
|
DefaultNodeServer: csicommon.NewDefaultNodeServer(d, t, cliReadAffinityMapOptions, topology, nodeLabels),
|
2022-07-07 00:46:12 +09:00
|
|
|
VolumeLocks: util.NewVolumeLocks(),
|
|
|
|
kernelMountOptions: kernelMountOptions,
|
|
|
|
fuseMountOptions: fuseMountOptions,
|
2023-09-13 16:05:27 +02:00
|
|
|
healthChecker: hc.NewHealthCheckManager(),
|
2018-03-05 12:59:47 +01:00
|
|
|
}
|
2023-11-17 11:59:00 +05:30
|
|
|
|
|
|
|
return ns
|
2018-03-05 12:59:47 +01:00
|
|
|
}
|
|
|
|
|
2019-01-28 17:17:06 +05:30
|
|
|
// Run start a non-blocking grpc controller,node and identityserver for
|
2020-07-19 17:51:03 +05:30
|
|
|
// ceph CSI driver which can serve multiple parallel requests.
|
2020-07-10 16:14:59 +05:30
|
|
|
func (fs *Driver) Run(conf *util.Config) {
|
2023-11-17 11:59:00 +05:30
|
|
|
var (
|
|
|
|
err error
|
|
|
|
nodeLabels, topology, crushLocationMap map[string]string
|
|
|
|
)
|
2020-01-24 11:26:56 -05:00
|
|
|
|
2018-04-13 14:53:17 +02:00
|
|
|
// Configuration
|
2021-09-16 20:16:07 +05:30
|
|
|
if err = mounter.LoadAvailableMounters(conf); err != nil {
|
2021-08-24 17:03:25 +02:00
|
|
|
log.FatalLogMsg("cephfs: failed to load ceph mounters: %v", err)
|
2018-08-14 16:48:30 +02:00
|
|
|
}
|
|
|
|
|
2024-07-06 07:10:29 +02:00
|
|
|
// Use passed in radosNamespace, if provided for storing CSI specific objects and keys.
|
|
|
|
if conf.RadosNamespaceCephFS != "" {
|
|
|
|
fsutil.RadosNamespace = conf.RadosNamespaceCephFS
|
|
|
|
}
|
|
|
|
|
2023-11-17 11:59:00 +05:30
|
|
|
if conf.IsNodeServer && k8s.RunsOnKubernetes() {
|
|
|
|
nodeLabels, err = k8s.GetNodeLabels(conf.NodeID)
|
|
|
|
if err != nil {
|
2024-12-20 18:23:59 +05:30
|
|
|
log.FatalLogMsg("%v", err.Error())
|
2023-11-17 11:59:00 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.EnableReadAffinity {
|
|
|
|
crushLocationMap = util.GetCrushLocationMap(conf.CrushLocationLabels, nodeLabels)
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:21:30 -04:00
|
|
|
// Create an instance of the volume journal
|
2024-08-05 16:05:24 +02:00
|
|
|
store.VolJournal = journal.NewCSIVolumeJournalWithNamespace(conf.InstanceID, fsutil.RadosNamespace)
|
2019-05-28 15:03:18 -04:00
|
|
|
|
2024-08-05 16:05:24 +02:00
|
|
|
store.SnapJournal = journal.NewCSISnapshotJournalWithNamespace(conf.InstanceID, fsutil.RadosNamespace)
|
2024-02-05 13:21:26 +01:00
|
|
|
|
|
|
|
store.VolumeGroupJournal = journal.NewCSIVolumeGroupJournalWithNamespace(
|
2024-08-05 16:05:24 +02:00
|
|
|
conf.InstanceID,
|
2024-02-05 13:21:26 +01:00
|
|
|
fsutil.RadosNamespace)
|
2018-03-05 12:59:47 +01:00
|
|
|
// Initialize default library driver
|
|
|
|
|
2024-08-05 16:05:24 +02:00
|
|
|
fs.cd = csicommon.NewCSIDriver(conf.DriverName, util.DriverVersion, conf.NodeID, conf.InstanceID)
|
2019-01-17 11:48:18 +05:30
|
|
|
if fs.cd == nil {
|
2021-08-24 17:03:25 +02:00
|
|
|
log.FatalLogMsg("failed to initialize CSI driver")
|
2018-03-05 12:59:47 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 12:12:17 +05:30
|
|
|
if conf.IsControllerServer || !conf.IsNodeServer {
|
|
|
|
fs.cd.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{
|
|
|
|
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
|
2020-08-04 09:20:13 +05:30
|
|
|
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
|
2019-10-07 12:11:33 +05:30
|
|
|
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
|
2020-08-04 09:20:13 +05:30
|
|
|
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
|
2021-08-17 11:57:01 +05:30
|
|
|
csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
|
2019-08-14 12:12:17 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
fs.cd.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{
|
|
|
|
csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
|
2021-08-17 11:57:01 +05:30
|
|
|
csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
|
|
|
|
csi.VolumeCapability_AccessMode_SINGLE_NODE_MULTI_WRITER,
|
|
|
|
csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER,
|
2019-08-14 12:12:17 +05:30
|
|
|
})
|
2024-02-05 10:05:32 +01:00
|
|
|
|
|
|
|
fs.cd.AddGroupControllerServiceCapabilities([]csi.GroupControllerServiceCapability_RPC_Type{
|
|
|
|
csi.GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT,
|
|
|
|
})
|
2019-08-14 12:12:17 +05:30
|
|
|
}
|
2018-03-05 12:59:47 +01:00
|
|
|
// Create gRPC servers
|
|
|
|
|
2019-01-17 11:48:18 +05:30
|
|
|
fs.is = NewIdentityServer(fs.cd)
|
2018-12-19 15:26:16 +01:00
|
|
|
|
2019-08-14 12:12:17 +05:30
|
|
|
if conf.IsNodeServer {
|
2020-01-24 11:26:56 -05:00
|
|
|
topology, err = util.GetTopologyFromDomainLabels(conf.DomainLabels, conf.NodeID, conf.DriverName)
|
|
|
|
if err != nil {
|
2024-12-20 18:23:59 +05:30
|
|
|
log.FatalLogMsg("%v", err.Error())
|
2020-01-24 11:26:56 -05:00
|
|
|
}
|
2023-11-17 11:59:00 +05:30
|
|
|
fs.ns = NewNodeServer(
|
|
|
|
fs.cd, conf.Vtype,
|
|
|
|
conf.KernelMountOptions, conf.FuseMountOptions,
|
|
|
|
nodeLabels, topology, crushLocationMap,
|
|
|
|
)
|
2019-08-14 12:12:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if conf.IsControllerServer {
|
2020-07-10 16:14:59 +05:30
|
|
|
fs.cs = NewControllerServer(fs.cd)
|
2022-06-14 18:53:29 +05:30
|
|
|
fs.cs.ClusterName = conf.ClusterName
|
2022-07-28 17:35:33 +05:30
|
|
|
fs.cs.SetMetadata = conf.SetMetadata
|
2019-08-14 12:12:17 +05:30
|
|
|
}
|
|
|
|
if !conf.IsControllerServer && !conf.IsNodeServer {
|
2020-01-24 11:26:56 -05:00
|
|
|
topology, err = util.GetTopologyFromDomainLabels(conf.DomainLabels, conf.NodeID, conf.DriverName)
|
|
|
|
if err != nil {
|
2024-12-20 18:23:59 +05:30
|
|
|
log.FatalLogMsg("%v", err.Error())
|
2020-01-24 11:26:56 -05:00
|
|
|
}
|
2023-11-17 11:59:00 +05:30
|
|
|
fs.ns = NewNodeServer(
|
|
|
|
fs.cd, conf.Vtype,
|
|
|
|
conf.KernelMountOptions, conf.FuseMountOptions,
|
|
|
|
nodeLabels, topology, crushLocationMap,
|
|
|
|
)
|
2020-07-10 16:14:59 +05:30
|
|
|
fs.cs = NewControllerServer(fs.cd)
|
2019-08-14 12:12:17 +05:30
|
|
|
}
|
2018-03-05 12:59:47 +01:00
|
|
|
|
2023-11-08 12:40:38 +01:00
|
|
|
// configure CSI-Addons server and components
|
2023-07-11 20:48:51 +05:30
|
|
|
err = fs.setupCSIAddonsServer(conf)
|
|
|
|
if err != nil {
|
2024-12-20 18:23:59 +05:30
|
|
|
log.FatalLogMsg("%v", err.Error())
|
2023-07-11 20:48:51 +05:30
|
|
|
}
|
|
|
|
|
2018-03-05 12:59:47 +01:00
|
|
|
server := csicommon.NewNonBlockingGRPCServer()
|
2021-02-08 17:55:18 +05:30
|
|
|
srv := csicommon.Servers{
|
|
|
|
IS: fs.is,
|
|
|
|
CS: fs.cs,
|
|
|
|
NS: fs.ns,
|
2024-02-06 14:54:38 +01:00
|
|
|
GS: fs.cs,
|
2021-02-08 17:55:18 +05:30
|
|
|
}
|
2024-09-17 15:52:30 +02:00
|
|
|
server.Start(conf.Endpoint, srv, csicommon.MiddlewareServerOptionConfig{
|
|
|
|
LogSlowOpInterval: conf.LogSlowOpInterval,
|
|
|
|
})
|
2023-11-02 13:00:55 +01:00
|
|
|
|
2021-03-25 16:44:46 +05:30
|
|
|
if conf.EnableProfiling {
|
2023-11-02 13:00:55 +01:00
|
|
|
go util.StartMetricsServer(conf)
|
2021-08-24 17:03:25 +02:00
|
|
|
log.DebugLogMsg("Registering profiling handler")
|
2021-03-25 16:44:46 +05:30
|
|
|
go util.EnableProfiling()
|
|
|
|
}
|
2018-03-05 12:59:47 +01:00
|
|
|
server.Wait()
|
|
|
|
}
|
2023-07-11 20:48:51 +05:30
|
|
|
|
|
|
|
// setupCSIAddonsServer creates a new CSI-Addons Server on the given (URL)
|
|
|
|
// endpoint. The supported CSI-Addons operations get registered as their own
|
|
|
|
// services.
|
|
|
|
func (fs *Driver) setupCSIAddonsServer(conf *util.Config) error {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
fs.cas, err = csiaddons.NewCSIAddonsServer(conf.CSIAddonsEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create CSI-Addons server: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// register services
|
|
|
|
is := casceph.NewIdentityServer(conf)
|
|
|
|
fs.cas.RegisterService(is)
|
|
|
|
|
2023-10-05 21:01:58 +05:30
|
|
|
if conf.IsControllerServer {
|
|
|
|
fcs := casceph.NewFenceControllerServer()
|
|
|
|
fs.cas.RegisterService(fcs)
|
|
|
|
}
|
|
|
|
|
2023-07-11 20:48:51 +05:30
|
|
|
// start the server, this does not block, it runs a new go-routine
|
2024-09-17 15:52:30 +02:00
|
|
|
err = fs.cas.Start(csicommon.MiddlewareServerOptionConfig{
|
|
|
|
LogSlowOpInterval: conf.LogSlowOpInterval,
|
|
|
|
})
|
2023-07-11 20:48:51 +05:30
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to start CSI-Addons server: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|