mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
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 <ndevos@redhat.com>
This commit is contained in:
parent
0f8bbaa217
commit
b3910f2b4a
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
45
internal/rbd/driver_test.go
Normal file
45
internal/rbd/driver_test.go
Normal file
@ -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()
|
||||
}
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user