From aa39b3dc1ffdac5bc8c17c7d288821faf18321d7 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Feb 2024 09:29:56 +0100 Subject: [PATCH] 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 31c89070e..87120ee64 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 080f9df93..aead6d64e 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 {