rbd: implement CSI-Addons Identity Service

Depending on the way Ceph-CSI is deployed, the capabilities will be
configured for the GetCapabilities procedure. The other procedures are
more straight-forward.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-11-30 18:02:35 +01:00 committed by mergify[bot]
parent 20727bd41a
commit ab76459e87
3 changed files with 72 additions and 9 deletions

View File

@ -21,12 +21,25 @@ import (
"github.com/csi-addons/spec/lib/go/identity"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/wrapperspb"
"github.com/ceph/ceph-csi/internal/util"
)
// IdentityServer struct of rbd CSI driver with supported methods of CSI
// identity server spec.
type IdentityServer struct {
*identity.UnimplementedIdentityServer
config *util.Config
}
// NewIdentityServer creates a new IdentityServer which handles the Identity
// Service requests from the CSI-Addons specification.
func NewIdentityServer(config *util.Config) *IdentityServer {
return &IdentityServer{
config: config,
}
}
func (is *IdentityServer) RegisterService(server grpc.ServiceRegistrar) {
@ -37,19 +50,62 @@ func (is *IdentityServer) RegisterService(server grpc.ServiceRegistrar) {
func (is *IdentityServer) GetIdentity(
ctx context.Context,
req *identity.GetIdentityRequest) (*identity.GetIdentityResponse, error) {
return nil, nil
// only include Name and VendorVersion, Manifest is optional
res := &identity.GetIdentityResponse{
Name: is.config.DriverName,
VendorVersion: util.DriverVersion,
}
return res, nil
}
// GetCapabilities returns available capabilities of the rbd driver.
func (is *IdentityServer) GetCapabilities(
ctx context.Context,
req *identity.GetCapabilitiesRequest) (*identity.GetCapabilitiesResponse, error) {
return nil, nil
// build the list of capabilities, depending on the config
caps := make([]*identity.Capability, 0)
if is.config.IsControllerServer {
// we're running as a CSI Controller service
caps = append(caps,
&identity.Capability{
Type: &identity.Capability_Service_{
Service: &identity.Capability_Service{
Type: identity.Capability_Service_CONTROLLER_SERVICE,
},
},
})
}
if is.config.IsNodeServer {
// we're running as a CSI node-plugin service
caps = append(caps,
&identity.Capability{
Type: &identity.Capability_Service_{
Service: &identity.Capability_Service{
Type: identity.Capability_Service_NODE_SERVICE,
},
},
})
}
res := &identity.GetCapabilitiesResponse{
Capabilities: caps,
}
return res, nil
}
// GetCapabilities returns available capabilities of the rbd driver.
// Probe is called by the CO plugin to validate that the CSI-Addons Node is
// still healthy.
func (is *IdentityServer) Probe(
ctx context.Context,
req *identity.ProbeRequest) (*identity.ProbeResponse, error) {
return nil, nil
// there is nothing that would cause a delay in getting ready
res := &identity.ProbeResponse{
Ready: &wrapperspb.BoolValue{Value: true},
}
return res, nil
}

View File

@ -132,7 +132,7 @@ func (r *Driver) Run(conf *util.Config) {
snapJournal = journal.NewCSISnapshotJournal(CSIInstanceID)
// configre CSI-Addons server and components
err = r.setupCSIAddonsServer(conf.CSIAddonsEndpoint)
err = r.setupCSIAddonsServer(conf)
if err != nil {
log.FatalLogMsg(err.Error())
}
@ -232,16 +232,17 @@ func (r *Driver) Run(conf *util.Config) {
// 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 {
func (r *Driver) setupCSIAddonsServer(conf *util.Config) error {
var err error
r.cas, err = csiaddons.NewCSIAddonsServer(endpoint)
r.cas, err = csiaddons.NewCSIAddonsServer(conf.CSIAddonsEndpoint)
if err != nil {
return fmt.Errorf("failed to create CSI-Addons server: %w", err)
}
// register services
r.cas.RegisterService(&casrbd.IdentityServer{})
is := casrbd.NewIdentityServer(conf)
r.cas.RegisterService(is)
// start the server, this does not block, it runs a new go-routine
err = r.cas.Start()

View File

@ -22,6 +22,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ceph/ceph-csi/internal/util"
)
func TestSetupCSIAddonsServer(t *testing.T) {
@ -31,8 +33,12 @@ func TestSetupCSIAddonsServer(t *testing.T) {
tmpDir := t.TempDir()
endpoint := "unix://" + tmpDir + "/csi-addons.sock"
config := &util.Config{
CSIAddonsEndpoint: endpoint,
}
drv := &Driver{}
err := drv.setupCSIAddonsServer(endpoint)
err := drv.setupCSIAddonsServer(config)
require.NoError(t, err)
require.NotNil(t, drv.cas)