mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
csiaddons: read volumeId from source
read the volumeID from replication source if the ID is missing read it from req VolumeId as a fallback. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
a160bf1359
commit
c03152bcaf
@ -116,6 +116,43 @@ func NewMiddlewareServerOption() grpc.ServerOption {
|
||||
return grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(middleWare...))
|
||||
}
|
||||
|
||||
// GetIDFromReplication returns the volumeID for Replication.
|
||||
func GetIDFromReplication(req interface{}) string {
|
||||
getID := func(r interface {
|
||||
GetVolumeId() string
|
||||
GetReplicationSource() *replication.ReplicationSource
|
||||
},
|
||||
) string {
|
||||
reqID := ""
|
||||
src := r.GetReplicationSource()
|
||||
if src != nil && src.GetVolume() != nil {
|
||||
reqID = src.GetVolume().GetVolumeId()
|
||||
}
|
||||
if reqID == "" {
|
||||
reqID = r.GetVolumeId() //nolint:nolintlint,staticcheck // req.VolumeId is deprecated
|
||||
}
|
||||
|
||||
return reqID
|
||||
}
|
||||
|
||||
switch r := req.(type) {
|
||||
case *replication.EnableVolumeReplicationRequest:
|
||||
return getID(r)
|
||||
case *replication.DisableVolumeReplicationRequest:
|
||||
return getID(r)
|
||||
case *replication.PromoteVolumeRequest:
|
||||
return getID(r)
|
||||
case *replication.DemoteVolumeRequest:
|
||||
return getID(r)
|
||||
case *replication.ResyncVolumeRequest:
|
||||
return getID(r)
|
||||
case *replication.GetVolumeReplicationInfoRequest:
|
||||
return getID(r)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func getReqID(req interface{}) string {
|
||||
// if req is nil empty string will be returned
|
||||
reqID := ""
|
||||
@ -156,17 +193,17 @@ func getReqID(req interface{}) string {
|
||||
|
||||
// Replication
|
||||
case *replication.EnableVolumeReplicationRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.DisableVolumeReplicationRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.PromoteVolumeRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.DemoteVolumeRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.ResyncVolumeRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.GetVolumeReplicationInfoRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
}
|
||||
|
||||
return reqID
|
||||
|
Reference in New Issue
Block a user