Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csiaddons: update csi-addons spec #4692

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .commitlintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rules:
- - build
- cephfs
- ci
- csi-addons
- csiaddons
- cleanup
- deploy
- doc
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/ceph/ceph-csi/api v0.0.0-00010101000000-000000000000
github.com/ceph/go-ceph v0.28.0
github.com/container-storage-interface/spec v1.9.0
github.com/csi-addons/spec v0.2.1-0.20230606140122-d20966d2e444
github.com/csi-addons/spec v0.2.1-0.20240619103729-12c61f25a2a5
github.com/gemalto/kmip-go v0.0.10
github.com/golang/protobuf v1.5.4
github.com/google/fscrypt v0.3.6-0.20240502174735-068b9f8f5dec
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/csi-addons/spec v0.2.1-0.20230606140122-d20966d2e444 h1:hWVCrZWVHctpWt6cQxV1I6dW3wpBDMg3Vrvu9uAuUxw=
github.com/csi-addons/spec v0.2.1-0.20230606140122-d20966d2e444/go.mod h1:Mwq4iLiUV4s+K1bszcWU6aMsR5KPsbIYzzszJ6+56vI=
github.com/csi-addons/spec v0.2.1-0.20240619103729-12c61f25a2a5 h1:/pXa+X+YKDPRI2JG8WEnxGKk6PcVZRhcLqdPks+bQa8=
github.com/csi-addons/spec v0.2.1-0.20240619103729-12c61f25a2a5/go.mod h1:Mwq4iLiUV4s+K1bszcWU6aMsR5KPsbIYzzszJ6+56vI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down
13 changes: 7 additions & 6 deletions internal/csi-addons/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"
"time"

csicommon "github.com/ceph/ceph-csi/internal/csi-common"
corerbd "github.com/ceph/ceph-csi/internal/rbd"
"github.com/ceph/ceph-csi/internal/util"
"github.com/ceph/ceph-csi/internal/util/log"
Expand Down Expand Up @@ -247,7 +248,7 @@ func validateSchedulingInterval(interval string) error {
func (rs *ReplicationServer) EnableVolumeReplication(ctx context.Context,
req *replication.EnableVolumeReplicationRequest,
) (*replication.EnableVolumeReplicationResponse, error) {
volumeID := req.GetVolumeId()
volumeID := csicommon.GetIDFromReplication(req)
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}
Expand Down Expand Up @@ -329,7 +330,7 @@ func (rs *ReplicationServer) EnableVolumeReplication(ctx context.Context,
func (rs *ReplicationServer) DisableVolumeReplication(ctx context.Context,
req *replication.DisableVolumeReplicationRequest,
) (*replication.DisableVolumeReplicationResponse, error) {
volumeID := req.GetVolumeId()
volumeID := csicommon.GetIDFromReplication(req)
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}
Expand Down Expand Up @@ -404,7 +405,7 @@ func (rs *ReplicationServer) DisableVolumeReplication(ctx context.Context,
func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
req *replication.PromoteVolumeRequest,
) (*replication.PromoteVolumeResponse, error) {
volumeID := req.GetVolumeId()
volumeID := csicommon.GetIDFromReplication(req)
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}
Expand Down Expand Up @@ -504,7 +505,7 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
req *replication.DemoteVolumeRequest,
) (*replication.DemoteVolumeResponse, error) {
volumeID := req.GetVolumeId()
volumeID := csicommon.GetIDFromReplication(req)
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}
Expand Down Expand Up @@ -622,7 +623,7 @@ func checkRemoteSiteStatus(ctx context.Context, mirrorStatus *librbd.GlobalMirro
func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
req *replication.ResyncVolumeRequest,
) (*replication.ResyncVolumeResponse, error) {
volumeID := req.GetVolumeId()
volumeID := csicommon.GetIDFromReplication(req)
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}
Expand Down Expand Up @@ -836,7 +837,7 @@ func getGRPCError(err error) error {
func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
req *replication.GetVolumeReplicationInfoRequest,
) (*replication.GetVolumeReplicationInfoResponse, error) {
volumeID := req.GetVolumeId()
volumeID := csicommon.GetIDFromReplication(req)
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
}
Expand Down
49 changes: 43 additions & 6 deletions internal/csi-common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions internal/csi-common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,62 @@ func TestGetReqID(t *testing.T) {
&replication.GetVolumeReplicationInfoRequest{
VolumeId: fakeID,
},

// volumeId is set in ReplicationSource
&replication.EnableVolumeReplicationRequest{
ReplicationSource: &replication.ReplicationSource{
Type: &replication.ReplicationSource_Volume{
Volume: &replication.ReplicationSource_VolumeSource{
VolumeId: fakeID,
},
},
},
},
&replication.DisableVolumeReplicationRequest{
ReplicationSource: &replication.ReplicationSource{
Type: &replication.ReplicationSource_Volume{
Volume: &replication.ReplicationSource_VolumeSource{
VolumeId: fakeID,
},
},
},
},
&replication.PromoteVolumeRequest{
ReplicationSource: &replication.ReplicationSource{
Type: &replication.ReplicationSource_Volume{
Volume: &replication.ReplicationSource_VolumeSource{
VolumeId: fakeID,
},
},
},
},
&replication.DemoteVolumeRequest{
ReplicationSource: &replication.ReplicationSource{
Type: &replication.ReplicationSource_Volume{
Volume: &replication.ReplicationSource_VolumeSource{
VolumeId: fakeID,
},
},
},
},
&replication.ResyncVolumeRequest{
ReplicationSource: &replication.ReplicationSource{
Type: &replication.ReplicationSource_Volume{
Volume: &replication.ReplicationSource_VolumeSource{
VolumeId: fakeID,
},
},
},
},
&replication.GetVolumeReplicationInfoRequest{
ReplicationSource: &replication.ReplicationSource{
Type: &replication.ReplicationSource_Volume{
Volume: &replication.ReplicationSource_VolumeSource{
VolumeId: fakeID,
},
},
},
},
}
for _, r := range req {
if got := getReqID(r); got != fakeID {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading