Skip to content

Commit

Permalink
Fix a log msg and gofmt errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xing-yang committed Aug 6, 2018
1 parent 8ed395b commit 0573211
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (ctrl *CSISnapshotController) syncUnboundSnapshot(snapshot *crdv1.VolumeSna
if !ok {
return fmt.Errorf("expected volume snapshot content, got %+v", contentObj)
}

if err := ctrl.BindSnapshotContent(snapshot, content); err != nil {
// snapshot is bound but content is not bound to snapshot correctly
return fmt.Errorf("snapshot %s is bound, but VolumeSnapshotContent %s is not bound to the VolumeSnapshot correctly, %v", uniqueSnapshotName, content.Name, err)
Expand Down Expand Up @@ -721,7 +721,7 @@ func (ctrl *CSISnapshotController) updateSnapshotErrorStatusWithEvent(snapshot *
Time: time.Now(),
},
Message: message,
}
}
snapshotClone.Status.Error = statusError
}
snapshotClone.Status.Bound = false
Expand All @@ -746,7 +746,7 @@ func (ctrl *CSISnapshotController) updateSnapshotBoundWithEvent(snapshot *crdv1.
glog.V(4).Infof("updateSnapshotBoundWithEvent[%s]", snapshotKey(snapshot))
if snapshot.Status.Bound && snapshot.Status.Error == nil {
// Nothing to do.
glog.V(4).Infof("updateSnapshotBoundWithEvent[%s]: Bound %v already set", snapshot.Status.Bound)
glog.V(4).Infof("updateSnapshotBoundWithEvent[%s]: Bound %v already set", snapshotKey(snapshot), snapshot.Status.Bound)
return snapshot, nil
}

Expand All @@ -770,32 +770,28 @@ func (ctrl *CSISnapshotController) updateSnapshotBoundWithEvent(snapshot *crdv1.
return newSnapshot, err
}


return newSnapshot, nil
}


// Stateless functions
func getSnapshotStatusForLogging(snapshot *crdv1.VolumeSnapshot) string {
return fmt.Sprintf("bound to: %q, Completed: %v", snapshot.Spec.SnapshotContentName, snapshot.Status.Bound)
}


func IsSnapshotBound(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent) bool {
if content.Spec.VolumeSnapshotRef != nil && content.Spec.VolumeSnapshotRef.Name == snapshot.Name &&
content.Spec.VolumeSnapshotRef.UID == snapshot.UID {
return true
}
}
return false
}


func (ctrl *CSISnapshotController) BindSnapshotContent(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent) error {
if content.Spec.VolumeSnapshotRef == nil || content.Spec.VolumeSnapshotRef.Name != snapshot.Name {
return fmt.Errorf("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match", snapshot.Name, content.Name)
} else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotRef.UID != snapshot.UID {
return fmt.Errorf("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match", snapshot.Name, content.Name)
} else if content.Spec.VolumeSnapshotRef.UID == "" {
} else if content.Spec.VolumeSnapshotRef.UID == "" {
content.Spec.VolumeSnapshotRef.UID = snapshot.UID
newContent, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotContents().Update(content)
if err != nil {
Expand All @@ -809,4 +805,4 @@ func (ctrl *CSISnapshotController) BindSnapshotContent(snapshot *crdv1.VolumeSna
}
}
return nil
}
}
2 changes: 1 addition & 1 deletion pkg/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ func storeObjectUpdate(store cache.Store, obj interface{}, className string) (bo
// The name must be unique.
func GetSnapshotContentNameForSnapshot(snapshot *crdv1.VolumeSnapshot) string {
return "snapdata-" + string(snapshot.UID)
}
}

0 comments on commit 0573211

Please sign in to comment.