From a5c4f341d77a51f0019fe356f2ae33d0337e50a6 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Mon, 10 Sep 2018 21:22:15 +0000 Subject: [PATCH] fix golint issue for pkg/volume/util --- hack/.golint_failures | 1 - pkg/volume/util/atomic_writer.go | 6 +++--- pkg/volume/util/attach_limit.go | 2 +- pkg/volume/util/device_util.go | 4 ++-- pkg/volume/util/device_util_linux.go | 8 ++++---- pkg/volume/util/doc.go | 2 +- pkg/volume/util/error.go | 3 ++- pkg/volume/util/finalizer.go | 4 ++-- pkg/volume/util/util.go | 16 +++++++++------- pkg/volume/util/util_test.go | 2 +- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/hack/.golint_failures b/hack/.golint_failures index 45bdeeb9fc..d110a1350b 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -425,7 +425,6 @@ pkg/volume/scaleio pkg/volume/secret pkg/volume/storageos pkg/volume/testing -pkg/volume/util pkg/volume/util/fs pkg/volume/util/recyclerclient pkg/volume/util/volumepathhandler diff --git a/pkg/volume/util/atomic_writer.go b/pkg/volume/util/atomic_writer.go index 0613bef6d9..99cc0c15d8 100644 --- a/pkg/volume/util/atomic_writer.go +++ b/pkg/volume/util/atomic_writer.go @@ -61,6 +61,7 @@ type AtomicWriter struct { logContext string } +// FileProjection contains file Data and access Mode type FileProjection struct { Data []byte Mode int32 @@ -172,9 +173,8 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error { if err = w.writePayloadToDir(cleanPayload, tsDir); err != nil { glog.Errorf("%s: error writing payload to ts data directory %s: %v", w.logContext, tsDir, err) return err - } else { - glog.V(4).Infof("%s: performed write of new data to ts data directory: %s", w.logContext, tsDir) } + glog.V(4).Infof("%s: performed write of new data to ts data directory: %s", w.logContext, tsDir) // (7) if err = w.createUserVisibleFiles(cleanPayload); err != nil { @@ -222,7 +222,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error { return nil } -// validatePayload returns an error if any path in the payload returns a copy of the payload with the paths cleaned. +// validatePayload returns an error if any path in the payload returns a copy of the payload with the paths cleaned. func validatePayload(payload map[string]FileProjection) (map[string]FileProjection, error) { cleanPayload := make(map[string]FileProjection) for k, content := range payload { diff --git a/pkg/volume/util/attach_limit.go b/pkg/volume/util/attach_limit.go index 079a015006..8325dbf755 100644 --- a/pkg/volume/util/attach_limit.go +++ b/pkg/volume/util/attach_limit.go @@ -33,7 +33,7 @@ const ( // Amazon recommends no more than 40; the system root volume uses at least one. // See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/volume_limits.html#linux-specific-volume-limits DefaultMaxEBSVolumes = 39 - // DefaultMaxEBSM5VolumeLimit is default EBS volume limit on m5 and c5 instances + // DefaultMaxEBSNitroVolumeLimit is default EBS volume limit on m5 and c5 instances DefaultMaxEBSNitroVolumeLimit = 25 // AzureVolumeLimitKey stores resource name that will store volume limits for Azure AzureVolumeLimitKey = "attachable-volumes-azure-disk" diff --git a/pkg/volume/util/device_util.go b/pkg/volume/util/device_util.go index f508399b1a..1d0791ee05 100644 --- a/pkg/volume/util/device_util.go +++ b/pkg/volume/util/device_util.go @@ -25,10 +25,10 @@ type DeviceUtil interface { } type deviceHandler struct { - get_io IoUtil + getIo IoUtil } //NewDeviceHandler Create a new IoHandler implementation func NewDeviceHandler(io IoUtil) DeviceUtil { - return &deviceHandler{get_io: io} + return &deviceHandler{getIo: io} } diff --git a/pkg/volume/util/device_util_linux.go b/pkg/volume/util/device_util_linux.go index 2d1f43c83b..a3d292d0f9 100644 --- a/pkg/volume/util/device_util_linux.go +++ b/pkg/volume/util/device_util_linux.go @@ -29,7 +29,7 @@ import ( // FindMultipathDeviceForDevice given a device name like /dev/sdx, find the devicemapper parent func (handler *deviceHandler) FindMultipathDeviceForDevice(device string) string { - io := handler.get_io + io := handler.getIo disk, err := findDeviceForPath(device, io) if err != nil { return "" @@ -68,7 +68,7 @@ func findDeviceForPath(path string, io IoUtil) (string, error) { // which are managed by the devicemapper dm-1. func (handler *deviceHandler) FindSlaveDevicesOnMultipath(dm string) []string { var devices []string - io := handler.get_io + io := handler.getIo // Split path /dev/dm-1 into "", "dev", "dm-1" parts := strings.Split(dm, "/") if len(parts) != 3 || !strings.HasPrefix(parts[1], "dev") { @@ -92,7 +92,7 @@ func (handler *deviceHandler) FindSlaveDevicesOnMultipath(dm string) []string { // } func (handler *deviceHandler) GetISCSIPortalHostMapForTarget(targetIqn string) (map[string]int, error) { portalHostMap := make(map[string]int) - io := handler.get_io + io := handler.getIo // Iterate over all the iSCSI hosts in sysfs sysPath := "/sys/class/iscsi_host" @@ -205,7 +205,7 @@ func (handler *deviceHandler) GetISCSIPortalHostMapForTarget(targetIqn string) ( // corresponding to that LUN. func (handler *deviceHandler) FindDevicesForISCSILun(targetIqn string, lun int) ([]string, error) { devices := make([]string, 0) - io := handler.get_io + io := handler.getIo // Iterate over all the iSCSI hosts in sysfs sysPath := "/sys/class/iscsi_host" diff --git a/pkg/volume/util/doc.go b/pkg/volume/util/doc.go index 620add69df..b32dae216e 100644 --- a/pkg/volume/util/doc.go +++ b/pkg/volume/util/doc.go @@ -14,5 +14,5 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Contains utility code for use by volume plugins. +// Package util contains utility code for use by volume plugins. package util // import "k8s.io/kubernetes/pkg/volume/util" diff --git a/pkg/volume/util/error.go b/pkg/volume/util/error.go index 2c9655866b..a52a1b65ce 100644 --- a/pkg/volume/util/error.go +++ b/pkg/volume/util/error.go @@ -20,7 +20,7 @@ import ( k8stypes "k8s.io/apimachinery/pkg/types" ) -// This error on attach indicates volume is attached to a different node +// DanglingAttachError indicates volume is attached to a different node // than we expected. type DanglingAttachError struct { msg string @@ -32,6 +32,7 @@ func (err *DanglingAttachError) Error() string { return err.msg } +// NewDanglingError create a new dangling error func NewDanglingError(msg string, node k8stypes.NodeName, devicePath string) error { return &DanglingAttachError{ msg: msg, diff --git a/pkg/volume/util/finalizer.go b/pkg/volume/util/finalizer.go index 92d3c2bdd5..e1fdf5673c 100644 --- a/pkg/volume/util/finalizer.go +++ b/pkg/volume/util/finalizer.go @@ -17,9 +17,9 @@ limitations under the License. package util const ( - // Name of finalizer on PVCs that have a running pod. + // PVCProtectionFinalizer is the name of finalizer on PVCs that have a running pod. PVCProtectionFinalizer = "kubernetes.io/pvc-protection" - // Name of finalizer on PVs that are bound by PVCs + // PVProtectionFinalizer is the name of finalizer on PVs that are bound by PVCs PVProtectionFinalizer = "kubernetes.io/pv-protection" ) diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 72d9a781e7..fc8d0aa02c 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -261,6 +261,7 @@ func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeCl return secret, nil } +// GetClassForVolume locates storage class by persistent volume func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error) { if kubeClient == nil { return nil, fmt.Errorf("Cannot get kube client") @@ -379,11 +380,11 @@ func SelectZonesForVolume(zoneParameterPresent, zonesParameterPresent bool, zone } // scheduler will guarantee if node != null above, zoneFromNode is member of allowedZones. // so if zoneFromNode != "", we can safely assume it is part of allowedZones. - if zones, err := chooseZonesForVolumeIncludingZone(allowedZones, pvcName, zoneFromNode, numReplicas); err != nil { + zones, err := chooseZonesForVolumeIncludingZone(allowedZones, pvcName, zoneFromNode, numReplicas) + if err != nil { return nil, fmt.Errorf("cannot process zones in allowedTopologies: %v", err) - } else { - return zones, nil } + return zones, nil } // pick zone from parameters if present @@ -405,11 +406,11 @@ func SelectZonesForVolume(zoneParameterPresent, zonesParameterPresent bool, zone // pick zone from zones with nodes if zonesWithNodes.Len() > 0 { // If node != null (and thus zoneFromNode != ""), zoneFromNode will be member of zonesWithNodes - if zones, err := chooseZonesForVolumeIncludingZone(zonesWithNodes, pvcName, zoneFromNode, numReplicas); err != nil { + zones, err := chooseZonesForVolumeIncludingZone(zonesWithNodes, pvcName, zoneFromNode, numReplicas) + if err != nil { return nil, fmt.Errorf("cannot process zones where nodes exist in the cluster: %v", err) - } else { - return zones, nil } + return zones, nil } return nil, fmt.Errorf("cannot determine zones to provision volume in") } @@ -431,6 +432,7 @@ func ZonesFromAllowedTopologies(allowedTopologies []v1.TopologySelectorTerm) (se return zones, nil } +// ZonesSetToLabelValue converts zones set to label value func ZonesSetToLabelValue(strSet sets.String) string { return strings.Join(strSet.UnsortedList(), kubeletapis.LabelMultiZoneDelimiter) } @@ -511,7 +513,7 @@ func CalculateTimeoutForVolume(minimumTimeout, timeoutIncrement int, pv *v1.Pers func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 { roundedUp := volumeSizeBytes / allocationUnitBytes if volumeSizeBytes%allocationUnitBytes > 0 { - roundedUp += 1 + roundedUp++ } return roundedUp } diff --git a/pkg/volume/util/util_test.go b/pkg/volume/util/util_test.go index b1f83ac37c..30d980921e 100644 --- a/pkg/volume/util/util_test.go +++ b/pkg/volume/util/util_test.go @@ -44,7 +44,7 @@ import ( "k8s.io/kubernetes/pkg/volume" ) -var nodeLabels map[string]string = map[string]string{ +var nodeLabels = map[string]string{ "test-key1": "test-value1", "test-key2": "test-value2", }