From b3910f2b4ad70cab395b7de7ad392c368af08f4d Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 26 Nov 2021 20:20:03 +0100 Subject: [PATCH] rbd: enable CSI-Addons Server and Identity Service Add a new endpoint for the CSI-Addons Service and enable the Identity Service for the RBD plugin. Signed-off-by: Niels de Vos --- cmd/cephcsi.go | 3 +++ internal/rbd/driver.go | 39 ++++++++++++++++++++++++++++++++ internal/rbd/driver_test.go | 45 +++++++++++++++++++++++++++++++++++++ internal/util/util.go | 3 +++ 4 files changed, 90 insertions(+) create mode 100644 internal/rbd/driver_test.go diff --git a/cmd/cephcsi.go b/cmd/cephcsi.go index 248a50c12..2d1606c2a 100644 --- a/cmd/cephcsi.go +++ b/cmd/cephcsi.go @@ -128,6 +128,9 @@ func init() { flag.BoolVar(&conf.Version, "version", false, "Print cephcsi version information") flag.BoolVar(&conf.EnableProfiling, "enableprofiling", false, "enable go profiling") + // CSI-Addons configuration + flag.StringVar(&conf.CSIAddonsEndpoint, "csi-addons-endpoint", "unix://tmp/csi-addons.sock", "CSI-Addons endpoint") + klog.InitFlags(nil) if err := flag.Set("logtostderr", "true"); err != nil { klog.Exitf("failed to set logtostderr flag: %v", err) diff --git a/internal/rbd/driver.go b/internal/rbd/driver.go index cdb2ba1e4..09db97164 100644 --- a/internal/rbd/driver.go +++ b/internal/rbd/driver.go @@ -17,6 +17,10 @@ limitations under the License. package rbd import ( + "fmt" + + casrbd "github.com/ceph/ceph-csi/internal/csi-addons/rbd" + csiaddons "github.com/ceph/ceph-csi/internal/csi-addons/server" csicommon "github.com/ceph/ceph-csi/internal/csi-common" "github.com/ceph/ceph-csi/internal/journal" "github.com/ceph/ceph-csi/internal/util" @@ -39,6 +43,9 @@ type Driver struct { ns *NodeServer cs *ControllerServer rs *ReplicationServer + + // cas is the CSIAddonsServer where CSI-Addons services are handled + cas *csiaddons.CSIAddonsServer } var ( @@ -102,6 +109,9 @@ func NewNodeServer(d *csicommon.CSIDriver, t string, topology map[string]string) // Run start a non-blocking grpc controller,node and identityserver for // rbd CSI driver which can serve multiple parallel requests. +// +// This also configures and starts a new CSI-Addons service, by calling +// setupCSIAddonsServer(). func (r *Driver) Run(conf *util.Config) { var err error var topology map[string]string @@ -121,6 +131,12 @@ func (r *Driver) Run(conf *util.Config) { volJournal = journal.NewCSIVolumeJournal(CSIInstanceID) snapJournal = journal.NewCSISnapshotJournal(CSIInstanceID) + // configre CSI-Addons server and components + err = r.setupCSIAddonsServer(conf.CSIAddonsEndpoint) + if err != nil { + log.FatalLogMsg(err.Error()) + } + // Initialize default library driver r.cd = csicommon.NewCSIDriver(conf.DriverName, util.DriverVersion, conf.NodeID) if r.cd == nil { @@ -216,3 +232,26 @@ func (r *Driver) Run(conf *util.Config) { } s.Wait() } + +// setupCSIAddonsServer creates a new CSI-Addons Server on the given (URL) +// endpoint. The supported CSI-Addons operations get registered as their own +// services. +func (r *Driver) setupCSIAddonsServer(endpoint string) error { + var err error + + r.cas, err = csiaddons.NewCSIAddonsServer(endpoint) + if err != nil { + return fmt.Errorf("failed to create CSI-Addons server: %w", err) + } + + // register services + r.cas.RegisterService(&casrbd.IdentityServer{}) + + // start the server, this does not block, it runs a new go-routine + err = r.cas.Start() + if err != nil { + return fmt.Errorf("failed to start CSI-Addons server: %w", err) + } + + return nil +} diff --git a/internal/rbd/driver_test.go b/internal/rbd/driver_test.go new file mode 100644 index 000000000..302c26fa3 --- /dev/null +++ b/internal/rbd/driver_test.go @@ -0,0 +1,45 @@ +/* +Copyright 2021 The Ceph-CSI 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 rbd + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestSetupCSIAddonsServer(t *testing.T) { + t.Parallel() + + // endpoint in a temporary directory + tmpDir := t.TempDir() + endpoint := "unix://" + tmpDir + "/csi-addons.sock" + + drv := &Driver{} + err := drv.setupCSIAddonsServer(endpoint) + require.NoError(t, err) + require.NotNil(t, drv.cas) + + // verify the socket file has been created + _, err = os.Stat(tmpDir + "/csi-addons.sock") + assert.NoError(t, err) + + // stop the gRPC server + drv.cas.Stop() +} diff --git a/internal/util/util.go b/internal/util/util.go index 18550c6bc..33dd04872 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -118,6 +118,9 @@ type Config struct { // snapshots allowed on rbd image without flattening, once the soft limit is // reached cephcsi will start flattening the older rbd images. MinSnapshotsOnImage uint + + // CSI-Addons endpoint + CSIAddonsEndpoint string } // ValidateDriverName validates the driver name.