Skip to content

Commit

Permalink
fix(snapshot): ignore snapshot delete request for CSI volumes
Browse files Browse the repository at this point in the history
Signed-off-by: prateekpandey14 <prateek.pandey@mayadata.io>
  • Loading branch information
prateekpandey14 committed Jun 8, 2020
1 parent 0edd1b8 commit 02dc0c1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/openebs.io/v1alpha1/cas_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const (

// PVCreatedByKey is key to fetch the details of pv creation in case of restore
PVCreatedByKey = "openebs.io/created-through"

// Name of the CSI driver
CSIDriverName = "cstor.csi.openebs.io"
)

// CASPlainKey represents a openebs key used either in resource annotation
Expand Down
9 changes: 9 additions & 0 deletions pkg/snapshot/v1alpha1/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ func (s *snapshot) Delete() (*v1alpha1.CASSnapshot, error) {
return nil, err
}

// Return success for delete snapshot request in case volume snapshot belongs to a
// migrated CSI based persistent volume. Later as part of migration snapshot
// can be migrated to CSI snapshots using a migration or manual steps
if pv.Spec.CSI.Driver != nil {
if string(pv.Spec.CSI.Driver) == string(v1alpha1.CSIDriverName) {
return nil, nil
}
}

storageEngine := pv.Labels[string(v1alpha1.CASTypeKey)]
scName := pv.Labels[string(v1alpha1.StorageClassKey)]
if len(scName) == 0 {
Expand Down
11 changes: 4 additions & 7 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ func admissionRequired(ignoredList []string, metadata *metav1.ObjectMeta) bool {
switch strings.ToLower(annotations[skipValidation]) {
default:
required = true
case "n", "no", "false", "off":
case "y", "yes", "true":
klog.Infof("Skipping validations for %s/%s due to PVC has skip validation", metadata.Namespace, metadata.Name)
required = false
}
return required
Expand Down Expand Up @@ -245,18 +246,14 @@ func (wh *webhook) validatePVCDeleteRequest(req *v1beta1.AdmissionRequest) *v1be
return response
}

// skip pvc validation if skip-validations annotation has been set
if _, ok := pvc.GetAnnotations()[skipValidation]; ok {
klog.Infof("Skipping validations for %s/%s due to PVC has skip validation", pvc.Namespace, pvc.Name)
return response
}

// If PVC is not yet bound to PV then don't even perform any checks
if pvc.Spec.VolumeName == "" {
klog.Infof("Skipping validations for %s/%s due to PVC is not yet bound", pvc.Namespace, pvc.Name)
return response
}

// skip pvc validation if skip-validations annotation has been set to true
// "openebs.io/skip-validations: true"
if !validationRequired(ignoredNamespaces, &pvc.ObjectMeta) {
klog.V(4).Infof("Skipping validation for %s/%s due to policy check", pvc.Namespace, pvc.Name)
return response
Expand Down
28 changes: 25 additions & 3 deletions pkg/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ func TestValidatePVCDeleteRequest(t *testing.T) {
isRequiresPVCCreation: true,
expectedResponse: true,
},
"Skip pvc validaion if skipValidation annotations set even snapshot exists": {
"validate pvc if skipValidation annotations set to false": {
pvc: &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "PVC8",
Namespace: "test",
Annotations: map[string]string{skipValidation: "true"},
Annotations: map[string]string{skipValidation: ""},
},
Spec: corev1.PersistentVolumeClaimSpec{
VolumeName: "PV1",
Expand All @@ -325,7 +325,29 @@ func TestValidatePVCDeleteRequest(t *testing.T) {
},
},
isRequiresPVCCreation: true,
expectedResponse: true,
expectedResponse: false,
},

"validate pvc if skipValidation annotations not properly set": {
pvc: &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "PVC8",
Namespace: "test",
Annotations: map[string]string{skipValidation: ""},
},
Spec: corev1.PersistentVolumeClaimSpec{
VolumeName: "PV1",
},
},
snapshot: &snapshotapi.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: "Snap1",
Namespace: "test",
Labels: map[string]string{snapshotMetadataPVName: "PV1"},
},
},
isRequiresPVCCreation: true,
expectedResponse: false,
},
}
for name, test := range tests {
Expand Down

0 comments on commit 02dc0c1

Please sign in to comment.