From fc2f63f1338168c83e95122675f24a758586f059 Mon Sep 17 00:00:00 2001 From: Prateek Pandey Date: Wed, 14 Aug 2019 20:08:38 +0530 Subject: [PATCH] fix(snapshot-controller): add validation for cas-type (#100) Refer: https://github.com/openebs/openebs/issues/2687 changes adds the cas-type validation before triggering the snapshot operations, valid types are "jiva" and "cstor". any other cas-type will return a error which will raise as event via snapshot-controller. Signed-off-by: prateekpandey14 --- snapshot/pkg/volume/openebs/processor.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/snapshot/pkg/volume/openebs/processor.go b/snapshot/pkg/volume/openebs/processor.go index 7f7c9eea525..ad9ce9eb41e 100644 --- a/snapshot/pkg/volume/openebs/processor.go +++ b/snapshot/pkg/volume/openebs/processor.go @@ -29,7 +29,7 @@ import ( crdv1 "github.com/kubernetes-incubator/external-storage/snapshot/pkg/apis/crd/v1" "github.com/kubernetes-incubator/external-storage/snapshot/pkg/cloudprovider" "github.com/kubernetes-incubator/external-storage/snapshot/pkg/volume" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -37,6 +37,15 @@ const ( openEBSPersistentDiskPluginName = "openebs" ) +var ( + // SnapSupportedCASType is a map of supported volume type for snapshot + // operations. + SnapSupportedCASType = map[string]bool{ + "jiva": true, + "cstor": true, + } +) + type openEBSPlugin struct { mvol_v1alpha1.CASVolume } @@ -69,15 +78,22 @@ func (h *openEBSPlugin) SnapshotCreate(snapshot *crdv1.VolumeSnapshot, pv *v1.Pe snapObj := (*tags)["kubernetes.io/created-for/snapshot/name"] snapshotName := createSnapshotName(pv.Name, snapObj) + casType := pv.Annotations["openebs.io/cas-type"] if casType == "" { casType = "jiva" } + + ok := SnapSupportedCASType[casType] + if !ok { + return nil, nil, fmt.Errorf("aborting create snapshot operation as specified volume type (%s) does not support snapshots", casType) + } _, err := h.CreateSnapshot(casType, pv.Name, snapshotName, pv.Spec.ClaimRef.Namespace) if err != nil { glog.Errorf("failed to create snapshot for volume :%v, err: %v", pv.Name, err) return nil, nil, err } + glog.V(1).Info("snapshot %v created successfully", snapshotName) cond := []crdv1.VolumeSnapshotCondition{}