Skip to content

Commit

Permalink
Merge branch 'beta' of github.com:xing-yang/external-snapshotter into…
Browse files Browse the repository at this point in the history
… beta
  • Loading branch information
yuxiangqian committed Aug 30, 2019
2 parents df77c9a + 410d520 commit bc334e7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
28 changes: 26 additions & 2 deletions pkg/apis/volumesnapshot/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions pkg/controller/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
storagelisters "github.com/kubernetes-csi/external-snapshotter/pkg/client/listers/volumesnapshot/v1beta1"
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
storagev1beta1 "k8s.io/api/storage/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -465,7 +464,7 @@ func (r *snapshotReactor) checkSnapshots(expectedSnapshots []*crdv1.VolumeSnapsh
c = c.DeepCopy()
c.ResourceVersion = ""
if c.Status.Error != nil {
c.Status.Error.Time = metav1.Time{}
c.Status.Error.Time = &metav1.Time{}
}
expectedMap[c.Name] = c
}
Expand All @@ -475,7 +474,7 @@ func (r *snapshotReactor) checkSnapshots(expectedSnapshots []*crdv1.VolumeSnapsh
c = c.DeepCopy()
c.ResourceVersion = ""
if c.Status.Error != nil {
c.Status.Error.Time = metav1.Time{}
c.Status.Error.Time = &metav1.Time{}
}
gotMap[c.Name] = c
}
Expand Down Expand Up @@ -832,7 +831,7 @@ func newContentWithUnmatchDriverArray(name, snapshotHandle, boundToSnapshotUID,
}
}

func newSnapshot(name, className, boundToContent, snapshotUID, claimName string, ready bool, err *storagev1beta1.VolumeError, creationTime *metav1.Time, size *resource.Quantity) *crdv1.VolumeSnapshot {
func newSnapshot(name, className, boundToContent, snapshotUID, claimName string, ready bool, err *crdv1.VolumeSnapshotError, creationTime *metav1.Time, size *resource.Quantity) *crdv1.VolumeSnapshot {
snapshot := crdv1.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -862,7 +861,7 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
return withSnapshotFinalizer(&snapshot)
}

func newSnapshotArray(name, className, boundToContent, snapshotUID, claimName string, ready bool, err *storagev1beta1.VolumeError, creationTime *metav1.Time, size *resource.Quantity) []*crdv1.VolumeSnapshot {
func newSnapshotArray(name, className, boundToContent, snapshotUID, claimName string, ready bool, err *crdv1.VolumeSnapshotError, creationTime *metav1.Time, size *resource.Quantity) []*crdv1.VolumeSnapshot {
return []*crdv1.VolumeSnapshot{
newSnapshot(name, className, boundToContent, snapshotUID, claimName, ready, err, creationTime, size),
}
Expand Down Expand Up @@ -972,10 +971,10 @@ func newVolumeArray(name, volumeUID, volumeHandle, capacity, boundToClaimUID, bo
}
}

func newVolumeError(message string) *storagev1beta1.VolumeError {
return &storagev1beta1.VolumeError{
Time: metav1.Time{},
Message: message,
func newVolumeError(message string) *crdv1.VolumeSnapshotError {
return &crdv1.VolumeSnapshotError{
Time: &metav1.Time{},
Message: &message,
}
}

Expand Down
19 changes: 9 additions & 10 deletions pkg/controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
storage "k8s.io/api/storage/v1beta1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -408,16 +407,16 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatus(snapshot *c
func (ctrl *csiSnapshotController) updateSnapshotErrorStatusWithEvent(snapshot *crdv1.VolumeSnapshot, eventtype, reason, message string) error {
klog.V(5).Infof("updateSnapshotStatusWithEvent[%s]", snapshotKey(snapshot))

if snapshot.Status.Error != nil && snapshot.Status.Error.Message == message {
if snapshot.Status.Error != nil && snapshot.Status.Error.Message != nil && *snapshot.Status.Error.Message == message {
klog.V(4).Infof("updateSnapshotStatusWithEvent[%s]: the same error %v is already set", snapshot.Name, snapshot.Status.Error)
return nil
}
snapshotClone := snapshot.DeepCopy()
statusError := &storage.VolumeError{
Time: metav1.Time{
statusError := &crdv1.VolumeSnapshotError{
Time: &metav1.Time{
Time: time.Now(),
},
Message: message,
Message: &message,
}
snapshotClone.Status.Error = statusError
ready := false
Expand Down Expand Up @@ -611,8 +610,8 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn
func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshot, error) {
klog.Infof("createSnapshot: Creating snapshot %s through the plugin ...", snapshotKey(snapshot))

if snapshot.Status.Error != nil && !isControllerUpdateFailError(snapshot.Status.Error) {
klog.V(4).Infof("error is already set in snapshot, do not retry to create: %s", snapshot.Status.Error.Message)
if snapshot.Status.Error != nil && snapshot.Status.Error.Message != nil && !isControllerUpdateFailError(snapshot.Status.Error) {
klog.V(4).Infof("error is already set in snapshot, do not retry to create: %s", *snapshot.Status.Error.Message)
return snapshot, nil
}

Expand Down Expand Up @@ -994,9 +993,9 @@ func (e controllerUpdateError) Error() string {
return e.message
}

func isControllerUpdateFailError(err *storage.VolumeError) bool {
if err != nil {
if strings.Contains(err.Message, controllerUpdateFailMsg) {
func isControllerUpdateFailError(err *crdv1.VolumeSnapshotError) bool {
if err != nil && err.Message != nil {
if strings.Contains(*err.Message, controllerUpdateFailMsg) {
return true
}
}
Expand Down

0 comments on commit bc334e7

Please sign in to comment.