From a36c5f08f4217988c6e28cc9abeacaf5a15972bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E6=8C=AF=E5=85=B410069964?= Date: Mon, 12 Apr 2021 09:00:36 +0800 Subject: [PATCH] code cleanup: Omit redundant nil check on slices --- pkg/volume/csi/nodeinfomanager/nodeinfomanager.go | 2 +- pkg/volume/iscsi/iscsi_util.go | 2 +- pkg/volume/testing/testing.go | 4 ++-- .../k8s.io/apimachinery/pkg/util/validation/field/errors.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/volume/csi/nodeinfomanager/nodeinfomanager.go b/pkg/volume/csi/nodeinfomanager/nodeinfomanager.go index 5168bdbd4e4..d7c709eb5ba 100644 --- a/pkg/volume/csi/nodeinfomanager/nodeinfomanager.go +++ b/pkg/volume/csi/nodeinfomanager/nodeinfomanager.go @@ -326,7 +326,7 @@ func removeNodeIDFromNode(csiDriverName string) nodeUpdateFunc { // topology information. func updateTopologyLabels(topology map[string]string) nodeUpdateFunc { return func(node *v1.Node) (*v1.Node, bool, error) { - if topology == nil || len(topology) == 0 { + if len(topology) == 0 { return node, false, nil } diff --git a/pkg/volume/iscsi/iscsi_util.go b/pkg/volume/iscsi/iscsi_util.go index b47a2318c91..7f1e0daf504 100644 --- a/pkg/volume/iscsi/iscsi_util.go +++ b/pkg/volume/iscsi/iscsi_util.go @@ -791,7 +791,7 @@ func extractDeviceAndPrefix(mntPath string) (string, string, error) { func extractIface(mntPath string) (string, bool) { reOutput := ifaceRe.FindStringSubmatch(mntPath) - if reOutput != nil && len(reOutput) > 1 { + if len(reOutput) > 1 { return reOutput[1], true } diff --git a/pkg/volume/testing/testing.go b/pkg/volume/testing/testing.go index 67247c22e6c..9370cfa8750 100644 --- a/pkg/volume/testing/testing.go +++ b/pkg/volume/testing/testing.go @@ -380,9 +380,9 @@ func (plugin *FakeVolumePlugin) NewDetacher() (Detacher, error) { plugin.NewDetacherCallCount = plugin.NewDetacherCallCount + 1 detacher := plugin.getFakeVolume(&plugin.Detachers) attacherList := plugin.Attachers - if attacherList != nil && len(attacherList) > 0 { + if len(attacherList) > 0 { detacherList := plugin.Detachers - if detacherList != nil && len(detacherList) > 0 { + if len(detacherList) > 0 { detacherList[0].VolumesAttached = attacherList[0].VolumesAttached } diff --git a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go index 0cd5d65775a..c283ad189a0 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go @@ -181,7 +181,7 @@ func Invalid(field *Path, value interface{}, detail string) *Error { // valid values). func NotSupported(field *Path, value interface{}, validValues []string) *Error { detail := "" - if validValues != nil && len(validValues) > 0 { + if len(validValues) > 0 { quotedValues := make([]string, len(validValues)) for i, v := range validValues { quotedValues[i] = strconv.Quote(v)