From 72a2b97be291dfdfab370663d2d56252467bb6f5 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 9 Aug 2021 10:18:32 +0530 Subject: [PATCH] rbd: consider empty mirroring mode consider the empty mirroring mode when validating the snapshot interval and the scheduling time. Even if the mirroring Mode is not set validate the snapshot scheduling details as cephcsi sets the mirroring mode to default snapshot. Signed-off-by: Madhu Rajanna (cherry picked from commit 3c852199625333c8ccf8db18e592bb5627270d6b) --- internal/rbd/replicationcontrollerserver.go | 6 +++++- .../rbd/replicationcontrollerserver_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index 940ee245b..5a177ad4f 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -130,7 +130,7 @@ func getMirroringMode(ctx context.Context, parameters map[string]string) (librbd // getSchedulingDetails gets the mirroring mode and scheduling details from the // input GRPC request parameters and validates the scheduling is only supported -// for mirroring mode. +// for snapshot mirroring mode. func getSchedulingDetails(parameters map[string]string) (admin.Interval, admin.StartTime, error) { admInt := admin.NoInterval adminStartTime := admin.NoStartTime @@ -140,6 +140,10 @@ func getSchedulingDetails(parameters map[string]string) (admin.Interval, admin.S switch imageMirroringMode(val) { case imageMirrorModeSnapshot: + // If mirroring mode is not set in parameters, we are defaulting mirroring + // mode to snapshot. Discard empty mirroring mode from validation as it is + // an optional parameter. + case "": default: return admInt, adminStartTime, status.Error(codes.InvalidArgument, "scheduling is only supported for snapshot mode") } diff --git a/internal/rbd/replicationcontrollerserver_test.go b/internal/rbd/replicationcontrollerserver_test.go index 33a4b81d6..eb7de989f 100644 --- a/internal/rbd/replicationcontrollerserver_test.go +++ b/internal/rbd/replicationcontrollerserver_test.go @@ -138,6 +138,23 @@ func TestGetSchedulingDetails(t *testing.T) { admin.NoStartTime, false, }, + { + "when no parameters and scheduling details are specified", + map[string]string{}, + admin.NoInterval, + admin.NoStartTime, + false, + }, + { + "when no mirroring mode is specified", + map[string]string{ + schedulingIntervalKey: "1h", + schedulingStartTimeKey: "14:00:00-05:00", + }, + admin.Interval("1h"), + admin.StartTime("14:00:00-05:00"), + false, + }, } for _, tt := range tests { tt := tt