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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-02-05 09:29:56 +01:00 committed by mergify[bot]
parent dd235d88e0
commit aa39b3dc1f
2 changed files with 29 additions and 3 deletions

View File

@ -31,9 +31,10 @@ type CSIDriver struct {
nodeID string nodeID string
version string version string
// topology constraints that this nodeserver will advertise // topology constraints that this nodeserver will advertise
topology map[string]string topology map[string]string
capabilities []*csi.ControllerServiceCapability capabilities []*csi.ControllerServiceCapability
vc []*csi.VolumeCapability_AccessMode groupCapabilities []*csi.GroupControllerServiceCapability
vc []*csi.VolumeCapability_AccessMode
} }
// NewCSIDriver Creates a NewCSIDriver object. Assumes vendor // NewCSIDriver Creates a NewCSIDriver object. Assumes vendor
@ -116,3 +117,16 @@ func (d *CSIDriver) AddVolumeCapabilityAccessModes(
func (d *CSIDriver) GetVolumeCapabilityAccessModes() []*csi.VolumeCapability_AccessMode { func (d *CSIDriver) GetVolumeCapabilityAccessModes() []*csi.VolumeCapability_AccessMode {
return d.vc 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
}

View File

@ -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 // NewMiddlewareServerOption creates a new grpc.ServerOption that configures a
// common format for log messages and other gRPC related handlers. // common format for log messages and other gRPC related handlers.
func NewMiddlewareServerOption() grpc.ServerOption { func NewMiddlewareServerOption() grpc.ServerOption {