Skip to content

Commit

Permalink
Modify controller to check APIGroup in DataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
xing-yang committed Aug 30, 2018
1 parent 8cf1fe2 commit fe52529
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import (
// In the future version, a retry policy will be added.

const pvcKind = "PersistentVolumeClaim"
const apiGroup = ""
const controllerUpdateFailMsg = "snapshot controller failed to update"

const IsDefaultSnapshotClassAnnotation = "snapshot.storage.kubernetes.io/is-default-class"
Expand Down Expand Up @@ -813,13 +814,19 @@ func (ctrl *csiSnapshotController) SetDefaultSnapshotClass(snapshot *crdv1.Volum

// getClaimFromVolumeSnapshot is a helper function to get PVC from VolumeSnapshot.
func (ctrl *csiSnapshotController) getClaimFromVolumeSnapshot(snapshot *crdv1.VolumeSnapshot) (*v1.PersistentVolumeClaim, error) {
if snapshot.Spec.Source == nil || snapshot.Spec.Source.Kind != pvcKind {
return nil, fmt.Errorf("The snapshot source is not the right type. Expected %s, Got %v", pvcKind, snapshot.Spec.Source)
if snapshot.Spec.Source == nil {
return nil, fmt.Errorf("the snapshot source is not specified.")
}
if snapshot.Spec.Source.Kind != pvcKind {
return nil, fmt.Errorf("the snapshot source is not the right type. Expected %s, Got %v", pvcKind, snapshot.Spec.Source.Kind)
}
pvcName := snapshot.Spec.Source.Name
if pvcName == "" {
return nil, fmt.Errorf("the PVC name is not specified in snapshot %s", snapshotKey(snapshot))
}
if snapshot.Spec.Source.APIGroup != apiGroup {
return nil, fmt.Errorf("the snapshot source does not have the right APIGroup. Expected %s, Got %v", apiGroup, snapshot.Spec.Source.APIGroup)
}

pvc, err := ctrl.client.CoreV1().PersistentVolumeClaims(snapshot.Namespace).Get(pvcName, metav1.GetOptions{})
if err != nil {
Expand Down

0 comments on commit fe52529

Please sign in to comment.