From 22e32fd2dcad191c718fb231c1cb3d809a52bd4d Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Feb 2024 09:29:56 +0100 Subject: [PATCH 1/5] util: add helper for group controller Added helper function to add the group controller capabilities which needs to be included by csi driver that wants to implement group controller. Signed-off-by: Madhu Rajanna --- internal/csi-common/driver.go | 20 +++++++++++++++++--- internal/csi-common/utils.go | 12 ++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/internal/csi-common/driver.go b/internal/csi-common/driver.go index 31c89070e08..87120ee6465 100644 --- a/internal/csi-common/driver.go +++ b/internal/csi-common/driver.go @@ -31,9 +31,10 @@ type CSIDriver struct { nodeID string version string // topology constraints that this nodeserver will advertise - topology map[string]string - capabilities []*csi.ControllerServiceCapability - vc []*csi.VolumeCapability_AccessMode + topology map[string]string + capabilities []*csi.ControllerServiceCapability + groupCapabilities []*csi.GroupControllerServiceCapability + vc []*csi.VolumeCapability_AccessMode } // NewCSIDriver Creates a NewCSIDriver object. Assumes vendor @@ -116,3 +117,16 @@ func (d *CSIDriver) AddVolumeCapabilityAccessModes( func (d *CSIDriver) GetVolumeCapabilityAccessModes() []*csi.VolumeCapability_AccessMode { return d.vc } + +// AddControllerServiceCapabilities stores the group controller capabilities +// in driver object. +func (d *CSIDriver) AddGroupControllerServiceCapabilities(cl []csi.GroupControllerServiceCapability_RPC_Type) { + csc := make([]*csi.GroupControllerServiceCapability, 0, len(cl)) + + for _, c := range cl { + log.DefaultLog("Enabling group controller service capability: %v", c.String()) + csc = append(csc, NewGroupControllerServiceCapability(c)) + } + + d.groupCapabilities = csc +} diff --git a/internal/csi-common/utils.go b/internal/csi-common/utils.go index 080f9df9347..aead6d64e00 100644 --- a/internal/csi-common/utils.go +++ b/internal/csi-common/utils.go @@ -95,6 +95,18 @@ func NewControllerServiceCapability(ctrlCap csi.ControllerServiceCapability_RPC_ } } +// NewGroupControllerServiceCapability returns group controller capabilities. +func NewGroupControllerServiceCapability(ctrlCap csi.GroupControllerServiceCapability_RPC_Type, +) *csi.GroupControllerServiceCapability { + return &csi.GroupControllerServiceCapability{ + Type: &csi.GroupControllerServiceCapability_Rpc{ + Rpc: &csi.GroupControllerServiceCapability_RPC{ + Type: ctrlCap, + }, + }, + } +} + // NewMiddlewareServerOption creates a new grpc.ServerOption that configures a // common format for log messages and other gRPC related handlers. func NewMiddlewareServerOption() grpc.ServerOption { From edc03740ac04221445f918226da03c705e431a6b Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Feb 2024 09:35:04 +0100 Subject: [PATCH 2/5] util: add GroupControllerGetCapabilities RPC added GroupControllerGetCapabilities RPC to the default controller server which returns the group capabilities which are already set. Signed-off-by: Madhu Rajanna --- internal/csi-common/controllerserver-default.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/csi-common/controllerserver-default.go b/internal/csi-common/controllerserver-default.go index fcc261d78a6..2ce290928b9 100644 --- a/internal/csi-common/controllerserver-default.go +++ b/internal/csi-common/controllerserver-default.go @@ -47,3 +47,19 @@ func (cs *DefaultControllerServer) ControllerGetCapabilities( Capabilities: cs.Driver.capabilities, }, nil } + +// GroupControllerGetCapabilities implements the default +// GroupControllerGetCapabilities GRPC callout. +func (cs *DefaultControllerServer) GroupControllerGetCapabilities( + ctx context.Context, + req *csi.GroupControllerGetCapabilitiesRequest, +) (*csi.GroupControllerGetCapabilitiesResponse, error) { + log.TraceLog(ctx, "Using default GroupControllerGetCapabilities") + if cs.Driver == nil { + return nil, status.Error(codes.Unimplemented, "Group controller server is not enabled") + } + + return &csi.GroupControllerGetCapabilitiesResponse{ + Capabilities: cs.Driver.groupCapabilities, + }, nil +} From c4dc7af9e91f7b97194d78630340d5cc8d5481e3 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Feb 2024 09:44:58 +0100 Subject: [PATCH 3/5] util: add groupSnapshot details to getReqID added CreateVolumeGroupSnapshotRequest and DeleteVolumeGroupSnapshotRequest to the getReqID so that we can get the ReqID for the logging. Signed-off-by: Madhu Rajanna --- internal/csi-common/utils.go | 7 +++++++ internal/csi-common/utils_test.go | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/internal/csi-common/utils.go b/internal/csi-common/utils.go index aead6d64e00..daf6170eeb6 100644 --- a/internal/csi-common/utils.go +++ b/internal/csi-common/utils.go @@ -145,6 +145,13 @@ func getReqID(req interface{}) string { case *csi.NodeExpandVolumeRequest: reqID = r.VolumeId + + case *csi.CreateVolumeGroupSnapshotRequest: + reqID = r.Name + case *csi.DeleteVolumeGroupSnapshotRequest: + reqID = r.GroupSnapshotId + case *csi.GetVolumeGroupSnapshotRequest: + reqID = r.GroupSnapshotId } return reqID diff --git a/internal/csi-common/utils_test.go b/internal/csi-common/utils_test.go index e5687986aba..ddb16648a34 100644 --- a/internal/csi-common/utils_test.go +++ b/internal/csi-common/utils_test.go @@ -65,6 +65,16 @@ func TestGetReqID(t *testing.T) { &csi.NodeExpandVolumeRequest{ VolumeId: fakeID, }, + + &csi.CreateVolumeGroupSnapshotRequest{ + Name: fakeID, + }, + &csi.DeleteVolumeGroupSnapshotRequest{ + GroupSnapshotId: fakeID, + }, + &csi.GetVolumeGroupSnapshotRequest{ + GroupSnapshotId: fakeID, + }, } for _, r := range req { if got := getReqID(r); got != fakeID { From 1bc5e8895042a03915c19fa71d27d6907d41172d Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Feb 2024 09:49:04 +0100 Subject: [PATCH 4/5] util: add ValidateGroupControllerServiceRequest helper added ValidateGroupControllerServiceRequest helper function which can be used to validate the group controller service request. Signed-off-by: Madhu Rajanna --- internal/csi-common/driver.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/csi-common/driver.go b/internal/csi-common/driver.go index 87120ee6465..4062845b4cb 100644 --- a/internal/csi-common/driver.go +++ b/internal/csi-common/driver.go @@ -130,3 +130,21 @@ func (d *CSIDriver) AddGroupControllerServiceCapabilities(cl []csi.GroupControll d.groupCapabilities = csc } + +// ValidateGroupControllerServiceRequest validates the group controller +// plugin capabilities. +// +//nolint:interfacer // c can be of type fmt.Stringer, but that does not make the API clearer +func (d *CSIDriver) ValidateGroupControllerServiceRequest(c csi.GroupControllerServiceCapability_RPC_Type) error { + if c == csi.GroupControllerServiceCapability_RPC_UNKNOWN { + return nil + } + + for _, capability := range d.groupCapabilities { + if c == capability.GetRpc().GetType() { + return nil + } + } + + return status.Error(codes.InvalidArgument, c.String()) +} From 1d073fe25497b182ae1efb4d9a533516126a7f9c Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 6 Feb 2024 14:45:30 +0100 Subject: [PATCH 5/5] util: register group controller server Register group controller server if its initialized. Signed-off-by: Madhu Rajanna --- internal/csi-common/server.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/csi-common/server.go b/internal/csi-common/server.go index 13157f222fa..727ef57f80f 100644 --- a/internal/csi-common/server.go +++ b/internal/csi-common/server.go @@ -45,6 +45,7 @@ type Servers struct { IS csi.IdentityServer CS csi.ControllerServer NS csi.NodeServer + GS csi.GroupControllerServer } // NewNonBlockingGRPCServer return non-blocking GRPC. @@ -109,6 +110,9 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, srv Servers) { if srv.NS != nil { csi.RegisterNodeServer(server, srv.NS) } + if srv.GS != nil { + csi.RegisterGroupControllerServer(server, srv.GS) + } log.DefaultLog("Listening for connections on address: %#v", listener.Addr()) err = server.Serve(listener)