From e52e5e486c8a3cdf7082aacf9c21f117adde4d22 Mon Sep 17 00:00:00 2001 From: Supriya Premkumar Date: Sun, 21 Feb 2021 15:07:06 -0800 Subject: [PATCH] Adds ineffassign to GO linter script. Changes: - Enables ineffassign check in the verify scripts. - Fixes lint errs. --- hack/verify-golangci-lint.sh | 3 ++- pkg/apis/autoscaling/v1/conversion.go | 1 + pkg/apis/autoscaling/v2beta1/conversion.go | 1 + pkg/controller/replicaset/replica_set_test.go | 6 +++++- pkg/registry/core/service/storage/storage.go | 4 ++-- pkg/util/taints/taints.go | 2 +- pkg/volume/azuredd/azure_mounter.go | 1 - test/images/agnhost/netexec/netexec.go | 3 --- test/integration/apiserver/apiserver_test.go | 5 ----- test/integration/deployment/deployment_test.go | 3 +-- 10 files changed, 13 insertions(+), 16 deletions(-) diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index 8ddb9b28510..1e0bc1192ed 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -49,4 +49,5 @@ golangci-lint run \ --disable-all \ -E deadcode \ -E unused \ - -E varcheck + -E varcheck \ + -E ineffassign diff --git a/pkg/apis/autoscaling/v1/conversion.go b/pkg/apis/autoscaling/v1/conversion.go index 31187d6c501..bf94d48ae17 100644 --- a/pkg/apis/autoscaling/v1/conversion.go +++ b/pkg/apis/autoscaling/v1/conversion.go @@ -362,6 +362,7 @@ func Convert_autoscaling_HorizontalPodAutoscaler_To_v1_HorizontalPodAutoscaler(i } // copy before mutating if !copiedAnnotations { + //nolint:ineffassign copiedAnnotations = true out.Annotations = autoscaling.DeepCopyStringMap(out.Annotations) } diff --git a/pkg/apis/autoscaling/v2beta1/conversion.go b/pkg/apis/autoscaling/v2beta1/conversion.go index 171b2af4248..513b41a2a3e 100644 --- a/pkg/apis/autoscaling/v2beta1/conversion.go +++ b/pkg/apis/autoscaling/v2beta1/conversion.go @@ -299,6 +299,7 @@ func Convert_autoscaling_HorizontalPodAutoscaler_To_v2beta1_HorizontalPodAutosca } // copy before mutating if !copiedAnnotations { + //nolint:ineffassign copiedAnnotations = true out.Annotations = autoscaling.DeepCopyStringMap(out.Annotations) } diff --git a/pkg/controller/replicaset/replica_set_test.go b/pkg/controller/replicaset/replica_set_test.go index 23913348d02..a7faf14f365 100644 --- a/pkg/controller/replicaset/replica_set_test.go +++ b/pkg/controller/replicaset/replica_set_test.go @@ -1125,7 +1125,11 @@ func TestDeleteControllerAndExpectations(t *testing.T) { manager.deleteRS(rs) manager.syncReplicaSet(GetKey(rs, t)) - if _, exists, err = manager.expectations.GetExpectations(rsKey); exists { + _, exists, err = manager.expectations.GetExpectations(rsKey) + if err != nil { + t.Errorf("Failed to get controllee expectations: %v", err) + } + if exists { t.Errorf("Found expectations, expected none since the ReplicaSet has been deleted.") } diff --git a/pkg/registry/core/service/storage/storage.go b/pkg/registry/core/service/storage/storage.go index a704239fe23..da44e8b2356 100644 --- a/pkg/registry/core/service/storage/storage.go +++ b/pkg/registry/core/service/storage/storage.go @@ -70,8 +70,8 @@ func NewGenericREST(optsGetter generic.RESTOptionsGetter, serviceCIDR net.IPNet, ipv4 := api.IPv4Protocol ipv6 := api.IPv6Protocol - var primaryIPFamily *api.IPFamily = nil - var secondaryFamily *api.IPFamily = nil + var primaryIPFamily *api.IPFamily + var secondaryFamily *api.IPFamily if netutil.IsIPv6CIDR(&serviceCIDR) { primaryIPFamily = &ipv6 if hasSecondary { diff --git a/pkg/util/taints/taints.go b/pkg/util/taints/taints.go index a3eaca37036..3d7d560506f 100644 --- a/pkg/util/taints/taints.go +++ b/pkg/util/taints/taints.go @@ -192,7 +192,7 @@ func deleteTaints(taintsToRemove []v1.Taint, newTaints *[]v1.Taint) ([]error, bo allErrs := []error{} var removed bool for _, taintToRemove := range taintsToRemove { - removed = false + removed = false // nolint:ineffassign if len(taintToRemove.Effect) > 0 { *newTaints, removed = DeleteTaint(*newTaints, &taintToRemove) } else { diff --git a/pkg/volume/azuredd/azure_mounter.go b/pkg/volume/azuredd/azure_mounter.go index d197d2b11ac..84bfb019f36 100644 --- a/pkg/volume/azuredd/azure_mounter.go +++ b/pkg/volume/azuredd/azure_mounter.go @@ -102,7 +102,6 @@ func (m *azureDiskMounter) SetUpAt(dir string, mounterArgs volume.MounterArgs) e klog.Errorf("azureDisk - Unmount directory %s failed with %v", dir, err) return err } - mountPoint = true } if runtime.GOOS != "windows" { diff --git a/test/images/agnhost/netexec/netexec.go b/test/images/agnhost/netexec/netexec.go index 68cb8009f79..564a3c79b3d 100644 --- a/test/images/agnhost/netexec/netexec.go +++ b/test/images/agnhost/netexec/netexec.go @@ -321,15 +321,12 @@ func dialHandler(w http.ResponseWriter, r *http.Request) { var dialer func(string, net.Addr) (string, error) switch strings.ToLower(protocol) { case "", "http": - protocol = "http" dialer = dialHTTP addr, err = net.ResolveTCPAddr("tcp", hostPort) case "udp": - protocol = "udp" dialer = dialUDP addr, err = net.ResolveUDPAddr("udp", hostPort) case "sctp": - protocol = "sctp" dialer = dialSCTP addr, err = sctp.ResolveSCTPAddr("sctp", hostPort) default: diff --git a/test/integration/apiserver/apiserver_test.go b/test/integration/apiserver/apiserver_test.go index 267e8bb0ef6..795e80aa30d 100644 --- a/test/integration/apiserver/apiserver_test.go +++ b/test/integration/apiserver/apiserver_test.go @@ -1285,11 +1285,6 @@ func TestAPICRDProtobuf(t *testing.T) { t.Fatal(err) } - rv, _ := strconv.Atoi(obj.GetResourceVersion()) - if rv < 1 { - rv = 1 - } - w, err := client.Get(). Resource(resource).NamespaceIfScoped(obj.GetNamespace(), len(obj.GetNamespace()) > 0).Name(obj.GetName()).SubResource(tc.subresource). SetHeader("Accept", tc.accept). diff --git a/test/integration/deployment/deployment_test.go b/test/integration/deployment/deployment_test.go index 77601450e51..711b3b03274 100644 --- a/test/integration/deployment/deployment_test.go +++ b/test/integration/deployment/deployment_test.go @@ -224,12 +224,11 @@ func TestDeploymentSelectorImmutability(t *testing.T) { } // test to ensure apps/v1 selector is immutable - newSelectorLabels := map[string]string{"name_apps_v1beta1": "test_apps_v1beta1"} deploymentAppsV1, err := c.AppsV1().Deployments(ns.Name).Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { t.Fatalf("failed to get apps/v1 deployment %s: %v", name, err) } - newSelectorLabels = map[string]string{"name_apps_v1": "test_apps_v1"} + newSelectorLabels := map[string]string{"name_apps_v1": "test_apps_v1"} deploymentAppsV1.Spec.Selector.MatchLabels = newSelectorLabels deploymentAppsV1.Spec.Template.Labels = newSelectorLabels _, err = c.AppsV1().Deployments(ns.Name).Update(context.TODO(), deploymentAppsV1, metav1.UpdateOptions{})