Repository: ceph/ceph-csi
Pull request #2382 (2021-08-09 11:05:31)

rbd: consider empty mirroring mode (backport #2375)
This is an automatic backport of pull request #2375 done by [Mergify](https://mergify.io).


---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the [documentation](https://docs.mergify.io/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.io/) you can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.io/
</details>


Madhu-1: @mergifyio rebase
mergify[bot]: **Command `rebase`: success**
> **Branch already up to date**
> 

Madhu-1: /retest ci/centos/mini-e2e/k8s-1.19
Madhu-1: > /retest ci/centos/mini-e2e/k8s-1.19

`

    Aug  9 15:53:01.964: failed to create vault psp failed to run kubectl: error running /usr/bin/kubectl --server=https://192.168.39.141:8443 --kubeconfig=/root/.kube/config --namespace=cephcsi-e2e-8d23ea80 create -f -:

    Command stdout:

    

    stderr:

    Warning: policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+

    Error from server (AlreadyExists): error when creating "STDIN": podsecuritypolicies.policy "rbd-csi-vault-token-review-psp" already exists

    Error from server (AlreadyExists): error when creating "STDIN": roles.rbac.authorization.k8s.io "rbd-csi-vault-token-review-psp" already exists

    Error from server (AlreadyExists): error when creating "STDIN": rolebindings.rbac.authorization.k8s.io "rbd-csi-vault-token-review-psp" already exists
    error:
`
Madhu-1: /retest ci/centos/upgrade-tests-rbd
Madhu-1: > /retest ci/centos/upgrade-tests-rbd

`Error from server (AlreadyExists): error when creating "STDIN": configmaps "ceph-csi-encryption-kms-config" already exists`
Madhu-1: /retest ci/centos/mini-e2e/k8s-1.20
Madhu-1: > /retest ci/centos/mini-e2e/k8s-1.20

`Error from server (AlreadyExists): error when creating "STDIN": configmaps "ceph-csi-encryption-kms-config" already exists
`
Rakshith-R: /retest ci/centos/mini-e2e/k8s-1.21
Rakshith-R: > /retest ci/centos/mini-e2e/k8s-1.21

```
ug 10 10:38:55.590: INFO: rc: 1
Aug 10 10:38:55.590: INFO: will run kubectl (create) again (18 seconds elapsed)
Aug 10 10:38:55.590: FAIL: failed to create vault statefulset failed to run kubectl: error running /usr/bin/kubectl --server=https://192.168.39.190:8443 --kubeconfig=/root/.kube/config --namespace=cephcsi-e2e-70dfb28b create -f -:
Command stdout:

stderr:
Error from server (AlreadyExists): error when creating "STDIN": serviceaccounts "rbd-csi-vault-token-review" already exists
Error from server (AlreadyExists): error when creating "STDIN": clusterroles.rbac.authorization.k8s.io "rbd-csi-vault-token-review" already exists
Error from server (AlreadyExists): error when creating "STDIN": clusterrolebindings.rbac.authorization.k8s.io "rbd-csi-vault-token-review" already exists
```
https://jenkins-ceph-csi.apps.ocp.ci.centos.org/blue/organizations/jenkins/mini-e2e_k8s-1.21/detail/mini-e2e_k8s-1.21/717/pipeline

Patch:
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")
 	}


Test patch:
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