Merge pull request #81 from humblec/clean

Correct error variables and fix other golint errors.
This commit is contained in:
Kubernetes Prow Robot
2019-01-06 06:13:53 -08:00
committed by GitHub
5 changed files with 48 additions and 56 deletions

View File

@@ -104,7 +104,7 @@ func TestGetPluginInfo(t *testing.T) {
in := &csi.GetPluginInfoRequest{} in := &csi.GetPluginInfoRequest{}
out := test.output out := test.output
var injectedErr error = nil var injectedErr error
if test.injectError { if test.injectError {
injectedErr = fmt.Errorf("mock error") injectedErr = fmt.Errorf("mock error")
} }
@@ -214,7 +214,7 @@ func TestSupportsControllerCreateSnapshot(t *testing.T) {
in := &csi.ControllerGetCapabilitiesRequest{} in := &csi.ControllerGetCapabilitiesRequest{}
out := test.output out := test.output
var injectedErr error = nil var injectedErr error
if test.injectError { if test.injectError {
injectedErr = fmt.Errorf("mock error") injectedErr = fmt.Errorf("mock error")
} }
@@ -354,7 +354,7 @@ func TestSupportsControllerListSnapshots(t *testing.T) {
in := &csi.ControllerGetCapabilitiesRequest{} in := &csi.ControllerGetCapabilitiesRequest{}
out := test.output out := test.output
var injectedErr error = nil var injectedErr error
if test.injectError { if test.injectError {
injectedErr = fmt.Errorf("mock error") injectedErr = fmt.Errorf("mock error")
} }
@@ -524,7 +524,7 @@ func TestCreateSnapshot(t *testing.T) {
for _, test := range tests { for _, test := range tests {
in := test.input in := test.input
out := test.output out := test.output
var injectedErr error = nil var injectedErr error
if test.injectError != codes.OK { if test.injectError != codes.OK {
injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError)) injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError))
} }
@@ -632,7 +632,7 @@ func TestDeleteSnapshot(t *testing.T) {
for _, test := range tests { for _, test := range tests {
in := test.input in := test.input
out := test.output out := test.output
var injectedErr error = nil var injectedErr error
if test.injectError != codes.OK { if test.injectError != codes.OK {
injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError)) injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError))
} }
@@ -730,7 +730,7 @@ func TestGetSnapshotStatus(t *testing.T) {
for _, test := range tests { for _, test := range tests {
in := test.input in := test.input
out := test.output out := test.output
var injectedErr error = nil var injectedErr error
if test.injectError != codes.OK { if test.injectError != codes.OK {
injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError)) injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError))
} }

View File

@@ -119,7 +119,7 @@ type testCall func(ctrl *csiSnapshotController, reactor *snapshotReactor, test c
const testNamespace = "default" const testNamespace = "default"
const mockDriverName = "csi-mock-plugin" const mockDriverName = "csi-mock-plugin"
var versionConflictError = errors.New("VersionError") var errVersionConflict = errors.New("VersionError")
var nocontents []*crdv1.VolumeSnapshotContent var nocontents []*crdv1.VolumeSnapshotContent
var nosnapshots []*crdv1.VolumeSnapshot var nosnapshots []*crdv1.VolumeSnapshot
var noevents = []string{} var noevents = []string{}
@@ -228,7 +228,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
storedVer, _ := strconv.Atoi(storedVolume.ResourceVersion) storedVer, _ := strconv.Atoi(storedVolume.ResourceVersion)
requestedVer, _ := strconv.Atoi(content.ResourceVersion) requestedVer, _ := strconv.Atoi(content.ResourceVersion)
if storedVer != requestedVer { if storedVer != requestedVer {
return true, obj, versionConflictError return true, obj, errVersionConflict
} }
// Don't modify the existing object // Don't modify the existing object
content = content.DeepCopy() content = content.DeepCopy()
@@ -254,7 +254,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
storedVer, _ := strconv.Atoi(storedSnapshot.ResourceVersion) storedVer, _ := strconv.Atoi(storedSnapshot.ResourceVersion)
requestedVer, _ := strconv.Atoi(snapshot.ResourceVersion) requestedVer, _ := strconv.Atoi(snapshot.ResourceVersion)
if storedVer != requestedVer { if storedVer != requestedVer {
return true, obj, versionConflictError return true, obj, errVersionConflict
} }
// Don't modify the existing object // Don't modify the existing object
snapshot = snapshot.DeepCopy() snapshot = snapshot.DeepCopy()
@@ -276,10 +276,9 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
if found { if found {
glog.V(4).Infof("GetVolume: found %s", content.Name) glog.V(4).Infof("GetVolume: found %s", content.Name)
return true, content, nil return true, content, nil
} else {
glog.V(4).Infof("GetVolume: content %s not found", name)
return true, nil, fmt.Errorf("cannot find content %s", name)
} }
glog.V(4).Infof("GetVolume: content %s not found", name)
return true, nil, fmt.Errorf("cannot find content %s", name)
case action.Matches("get", "volumesnapshots"): case action.Matches("get", "volumesnapshots"):
name := action.(core.GetAction).GetName() name := action.(core.GetAction).GetName()
@@ -287,10 +286,9 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
if found { if found {
glog.V(4).Infof("GetSnapshot: found %s", snapshot.Name) glog.V(4).Infof("GetSnapshot: found %s", snapshot.Name)
return true, snapshot, nil return true, snapshot, nil
} else {
glog.V(4).Infof("GetSnapshot: content %s not found", name)
return true, nil, fmt.Errorf("cannot find snapshot %s", name)
} }
glog.V(4).Infof("GetSnapshot: content %s not found", name)
return true, nil, fmt.Errorf("cannot find snapshot %s", name)
case action.Matches("delete", "volumesnapshotcontents"): case action.Matches("delete", "volumesnapshotcontents"):
name := action.(core.DeleteAction).GetName() name := action.(core.DeleteAction).GetName()
@@ -300,9 +298,8 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
delete(r.contents, name) delete(r.contents, name)
r.changedSinceLastSync++ r.changedSinceLastSync++
return true, nil, nil return true, nil, nil
} else {
return true, nil, fmt.Errorf("cannot delete content %s: not found", name)
} }
return true, nil, fmt.Errorf("cannot delete content %s: not found", name)
case action.Matches("delete", "volumesnapshots"): case action.Matches("delete", "volumesnapshots"):
name := action.(core.DeleteAction).GetName() name := action.(core.DeleteAction).GetName()
@@ -312,9 +309,8 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
delete(r.snapshots, name) delete(r.snapshots, name)
r.changedSinceLastSync++ r.changedSinceLastSync++
return true, nil, nil return true, nil, nil
} else {
return true, nil, fmt.Errorf("cannot delete snapshot %s: not found", name)
} }
return true, nil, fmt.Errorf("cannot delete snapshot %s: not found", name)
case action.Matches("get", "persistentvolumes"): case action.Matches("get", "persistentvolumes"):
name := action.(core.GetAction).GetName() name := action.(core.GetAction).GetName()
@@ -322,10 +318,9 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
if found { if found {
glog.V(4).Infof("GetVolume: found %s", volume.Name) glog.V(4).Infof("GetVolume: found %s", volume.Name)
return true, volume, nil return true, volume, nil
} else {
glog.V(4).Infof("GetVolume: volume %s not found", name)
return true, nil, fmt.Errorf("cannot find volume %s", name)
} }
glog.V(4).Infof("GetVolume: volume %s not found", name)
return true, nil, fmt.Errorf("cannot find volume %s", name)
case action.Matches("get", "persistentvolumeclaims"): case action.Matches("get", "persistentvolumeclaims"):
name := action.(core.GetAction).GetName() name := action.(core.GetAction).GetName()
@@ -333,10 +328,9 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
if found { if found {
glog.V(4).Infof("GetClaim: found %s", claim.Name) glog.V(4).Infof("GetClaim: found %s", claim.Name)
return true, claim, nil return true, claim, nil
} else {
glog.V(4).Infof("GetClaim: claim %s not found", name)
return true, nil, fmt.Errorf("cannot find claim %s", name)
} }
glog.V(4).Infof("GetClaim: claim %s not found", name)
return true, nil, fmt.Errorf("cannot find claim %s", name)
case action.Matches("get", "storageclasses"): case action.Matches("get", "storageclasses"):
name := action.(core.GetAction).GetName() name := action.(core.GetAction).GetName()
@@ -344,10 +338,9 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
if found { if found {
glog.V(4).Infof("GetStorageClass: found %s", storageClass.Name) glog.V(4).Infof("GetStorageClass: found %s", storageClass.Name)
return true, storageClass, nil return true, storageClass, nil
} else {
glog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
return true, nil, fmt.Errorf("cannot find storageClass %s", name)
} }
glog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
return true, nil, fmt.Errorf("cannot find storageClass %s", name)
case action.Matches("get", "secrets"): case action.Matches("get", "secrets"):
name := action.(core.GetAction).GetName() name := action.(core.GetAction).GetName()
@@ -355,10 +348,10 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
if found { if found {
glog.V(4).Infof("GetSecret: found %s", secret.Name) glog.V(4).Infof("GetSecret: found %s", secret.Name)
return true, secret, nil return true, secret, nil
} else {
glog.V(4).Infof("GetSecret: secret %s not found", name)
return true, nil, fmt.Errorf("cannot find secret %s", name)
} }
glog.V(4).Infof("GetSecret: secret %s not found", name)
return true, nil, fmt.Errorf("cannot find secret %s", name)
} }
return false, nil, nil return false, nil, nil
@@ -966,16 +959,16 @@ func testSyncContent(ctrl *csiSnapshotController, reactor *snapshotReactor, test
} }
var ( var (
classEmpty string = "" classEmpty string
classGold string = "gold" classGold = "gold"
classSilver string = "silver" classSilver = "silver"
classNonExisting string = "non-existing" classNonExisting = "non-existing"
defaultClass string = "default-class" defaultClass = "default-class"
emptySecretClass string = "empty-secret-class" emptySecretClass = "empty-secret-class"
invalidSecretClass string = "invalid-secret-class" invalidSecretClass = "invalid-secret-class"
validSecretClass string = "valid-secret-class" validSecretClass = "valid-secret-class"
sameDriver string = "sameDriver" sameDriver = "sameDriver"
diffDriver string = "diffDriver" diffDriver = "diffDriver"
) )
// wrapTestWithInjectedOperation returns a testCall that: // wrapTestWithInjectedOperation returns a testCall that:

View File

@@ -194,9 +194,9 @@ func (ctrl *csiSnapshotController) syncSnapshot(snapshot *crdv1.VolumeSnapshot)
if !snapshot.Status.ReadyToUse { if !snapshot.Status.ReadyToUse {
return ctrl.syncUnreadySnapshot(snapshot) return ctrl.syncUnreadySnapshot(snapshot)
} else {
return ctrl.syncReadySnapshot(snapshot)
} }
return ctrl.syncReadySnapshot(snapshot)
} }
// syncReadySnapshot checks the snapshot which has been bound to snapshot content successfully before. // syncReadySnapshot checks the snapshot which has been bound to snapshot content successfully before.
@@ -557,9 +557,9 @@ func (ctrl *csiSnapshotController) getCreateSnapshotInput(snapshot *crdv1.Volume
func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent) (*crdv1.VolumeSnapshot, error) { func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent) (*crdv1.VolumeSnapshot, error) {
var err error var err error
var timestamp int64 = 0 var timestamp int64
var size int64 = 0 var size int64
var readyToUse bool = false var readyToUse = false
class, volume, _, snapshotterCredentials, err := ctrl.getCreateSnapshotInput(snapshot) class, volume, _, snapshotterCredentials, err := ctrl.getCreateSnapshotInput(snapshot)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get input parameters to create snapshot %s: %q", snapshot.Name, err) return nil, fmt.Errorf("failed to get input parameters to create snapshot %s: %q", snapshot.Name, err)
@@ -568,9 +568,8 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn
if err != nil { if err != nil {
glog.Errorf("checkandUpdateBoundSnapshotStatusOperation: failed to call create snapshot to check whether the snapshot is ready to use %q", err) glog.Errorf("checkandUpdateBoundSnapshotStatusOperation: failed to call create snapshot to check whether the snapshot is ready to use %q", err)
return nil, err return nil, err
} else {
glog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse)
} }
glog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse)
if timestamp == 0 { if timestamp == 0 {
timestamp = time.Now().UnixNano() timestamp = time.Now().UnixNano()
@@ -821,9 +820,9 @@ func (ctrl *csiSnapshotController) updateSnapshotStatus(snapshot *crdv1.VolumeSn
newSnapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone) newSnapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone)
if err != nil { if err != nil {
return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error()) return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error())
} else {
return newSnapshotObj, nil
} }
return newSnapshotObj, nil
} }
return snapshot, nil return snapshot, nil
} }

View File

@@ -168,21 +168,21 @@ func verifyAndGetSecretNameAndNamespaceTemplate(secret deprecatedSecretParamsMap
numNamespace := 0 numNamespace := 0
if t, ok := snapshotClassParams[secret.deprecatedSecretNameKey]; ok { if t, ok := snapshotClassParams[secret.deprecatedSecretNameKey]; ok {
nameTemplate = t nameTemplate = t
numName += 1 numName++
glog.Warning(deprecationWarning(secret.deprecatedSecretNameKey, secret.secretNameKey, "")) glog.Warning(deprecationWarning(secret.deprecatedSecretNameKey, secret.secretNameKey, ""))
} }
if t, ok := snapshotClassParams[secret.deprecatedSecretNamespaceKey]; ok { if t, ok := snapshotClassParams[secret.deprecatedSecretNamespaceKey]; ok {
namespaceTemplate = t namespaceTemplate = t
numNamespace += 1 numNamespace++
glog.Warning(deprecationWarning(secret.deprecatedSecretNamespaceKey, secret.secretNamespaceKey, "")) glog.Warning(deprecationWarning(secret.deprecatedSecretNamespaceKey, secret.secretNamespaceKey, ""))
} }
if t, ok := snapshotClassParams[secret.secretNameKey]; ok { if t, ok := snapshotClassParams[secret.secretNameKey]; ok {
nameTemplate = t nameTemplate = t
numName += 1 numName++
} }
if t, ok := snapshotClassParams[secret.secretNamespaceKey]; ok { if t, ok := snapshotClassParams[secret.secretNamespaceKey]; ok {
namespaceTemplate = t namespaceTemplate = t
numNamespace += 1 numNamespace++
} }
if numName > 1 || numNamespace > 1 { if numName > 1 || numNamespace > 1 {

View File

@@ -111,9 +111,9 @@ func TestGetSecretReference(t *testing.T) {
if err != nil { if err != nil {
if tc.expectErr { if tc.expectErr {
return return
} else {
t.Fatalf("Did not expect error but got: %v", err)
} }
t.Fatalf("Did not expect error but got: %v", err)
} else { } else {
if tc.expectErr { if tc.expectErr {
t.Fatalf("Expected error but got none") t.Fatalf("Expected error but got none")