Skip to content

fix remaining gocritic issues #131475

Open
Open
@pohly

Description

@pohly

What would you like to be added?

We have only a few issues left. Let's fix them with individual PRs, one for each affected SIG (see OWNERS files).

ERROR: ../cluster/gce/gci/configure_helper_test.go:102:7: badCall: suspicious Join on 1 argument (gocritic)
ERROR: 	p := filepath.Join(filepath.Join(c.kubeHome, "etc", "kubernetes", "manifests"))
ERROR: 	     ^
ERROR: ../pkg/volume/csi/csi_mounter.go:85:27: badCall: suspicious Join on 1 argument (gocritic)
ERROR: 	dir := GetCSIMounterPath(filepath.Join(getTargetPath(c.podUID, c.specVolumeID, c.plugin.host)))
ERROR: 	                         ^
ERROR: ../pkg/volume/git_repo/git_repo.go:222:12: badCall: suspicious Join on 1 argument (gocritic)
ERROR: 		subdir = filepath.Join(dir)
ERROR: 		         ^
ERROR: ../pkg/volume/testing/testing.go:799:9: badCall: suspicious Join on 1 argument (gocritic)
ERROR: 	return filepath.Join(fv.Plugin.Host.GetPodVolumeDir(fv.PodUID, utilstrings.EscapeQualifiedName(fv.Plugin.PluginName), fv.VolName))
ERROR: 	       ^
ERROR: ../pkg/volume/testing/testing.go:903:9: badCall: suspicious Join on 1 argument (gocritic)
ERROR: 	return filepath.Join(fv.Plugin.Host.GetPodVolumeDeviceDir(fv.PodUID, utilstrings.EscapeQualifiedName(fv.Plugin.PluginName))), fv.VolName
ERROR: 	       ^
ERROR: ../staging/src/k8s.io/apiextensions-apiserver/test/integration/validation_test.go:1584:8: wrapperFunc: suggestion: strings.Contains(cond.Message, v) (gocritic)
ERROR: 				if strings.Index(cond.Message, v) != -1 {
ERROR: 				   ^
ERROR: ../staging/src/k8s.io/apimachinery/pkg/api/resource/quantity_test.go:1669:6: dupArg: suspicious method call with the same argument and receiver (gocritic)
ERROR: 		if q.Cmp(q) != 0 {
ERROR: 		   ^
ERROR: ../staging/src/k8s.io/apiserver/pkg/authentication/request/bearertoken/bearertoken.go:48:23: equalFold: consider replacing with !strings.EqualFold(parts[0], "bearer") (gocritic)
ERROR: 	if len(parts) < 2 || strings.ToLower(parts[0]) != "bearer" {
ERROR: 	                     ^
ERROR: ../staging/src/k8s.io/apiserver/pkg/cel/value_test.go:286:5: dupArg: suspicious method call with the same argument and receiver (gocritic)
ERROR: 	if mv.Equal(mv) != types.True {
ERROR: 	   ^
ERROR: ../staging/src/k8s.io/apiserver/pkg/cel/value_test.go:287:41: dupArg: suspicious method call with the same argument and receiver (gocritic)
ERROR: 		t.Fatalf("map.Equal(map) failed: %v", mv.Equal(mv))
ERROR: 		                                      ^
ERROR: ../staging/src/k8s.io/apiserver/pkg/cel/value_test.go:342:5: dupArg: suspicious method call with the same argument and receiver (gocritic)
ERROR: 	if obj1.Equal(obj1) != types.True {
ERROR: 	   ^
ERROR: ../staging/src/k8s.io/apiserver/pkg/cel/value_test.go:343:48: dupArg: suspicious method call with the same argument and receiver (gocritic)
ERROR: 		t.Errorf("obj1.Equal(obj1) failed, got: %v", obj1.Equal(obj1))
ERROR: 		                                             ^
ERROR: ../staging/src/k8s.io/apiserver/pkg/endpoints/filters/authn_audit.go:70:23: equalFold: consider replacing with strings.EqualFold(parts[0], "bearer") (gocritic)
ERROR: 	if len(parts) > 1 && strings.ToLower(parts[0]) == "bearer" {
ERROR: 	                     ^
ERROR: ../staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go:776:5: equalFold: consider replacing with strings.EqualFold(req.Method, "GET") (gocritic)
ERROR: 	if strings.ToUpper(req.Method) == "GET" || strings.ToUpper(req.Method) == "LIST" {
ERROR: 	   ^
ERROR: ../staging/src/k8s.io/component-base/metrics/desc.go:184:26: newDeref: replace `*new(sync.Once)` with `sync.Once{}` (gocritic)
ERROR: 	d.markDeprecationOnce = *new(sync.Once)
ERROR: 	                        ^
ERROR: ../staging/src/k8s.io/component-base/metrics/desc.go:185:17: newDeref: replace `*new(sync.Once)` with `sync.Once{}` (gocritic)
ERROR: 	d.createOnce = *new(sync.Once)
ERROR: 	               ^
ERROR: ../staging/src/k8s.io/component-base/metrics/desc.go:186:20: newDeref: replace `*new(sync.Once)` with `sync.Once{}` (gocritic)
ERROR: 	d.deprecateOnce = *new(sync.Once)
ERROR: 	                  ^
ERROR: ../staging/src/k8s.io/component-base/metrics/desc.go:187:15: newDeref: replace `*new(sync.Once)` with `sync.Once{}` (gocritic)
ERROR: 	d.hideOnce = *new(sync.Once)
ERROR: 	             ^
ERROR: ../staging/src/k8s.io/component-base/metrics/desc.go:188:19: newDeref: replace `*new(sync.Once)` with `sync.Once{}` (gocritic)
ERROR: 	d.annotateOnce = *new(sync.Once)
ERROR: 	                 ^
ERROR: ../staging/src/k8s.io/component-base/metrics/registry_test.go:378:22: newDeref: replace `*new(sync.Once)` with `sync.Once{}` (gocritic)
ERROR: 				showHiddenOnce = *new(sync.Once)
ERROR: 				                 ^
ERROR: ../staging/src/k8s.io/component-base/metrics/registry_test.go:460:22: newDeref: replace `*new(sync.Once)` with `sync.Once{}` (gocritic)
ERROR: 				showHiddenOnce = *new(sync.Once)
ERROR: 				                 ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:703:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:737:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:770:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:826:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:872:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:905:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:949:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:983:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:1230:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/endpointslice/reconciler_test.go:1280:12: boolExprSimplify: can simplify `!(i%3 == 0)` to `i%3 != 0` (gocritic)
ERROR: 		ready := !(i%3 == 0)
ERROR: 		         ^
ERROR: ../staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go:325:5: equalFold: consider replacing with strings.EqualFold(o.ForCondition, "create") (gocritic)
ERROR: 	if strings.ToLower(o.ForCondition) == "create" {
ERROR: 	   ^
ERROR: ../staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go:370:17: equalFold: consider replacing with strings.EqualFold(o.ForCondition, "delete") (gocritic)
ERROR: 	isForDelete := strings.ToLower(o.ForCondition) == "delete"
ERROR: 	               ^
ERROR: ../test/e2e/apps/deployment.go:1561:10: badCond: `*(d.Spec.Replicas) == d.Status.Replicas &&
ERROR: 	*(d.Spec.Replicas) == d.Status.UpdatedReplicas` condition is suspicious (gocritic)
ERROR: 		return *(d.Spec.Replicas) == d.Status.Replicas &&
ERROR: 		       ^
ERROR: ../test/e2e/autoscaling/cluster_size_autoscaling.go:178:33: boolExprSimplify: can simplify `size >= nodeCount+1` to `size > nodeCount` (gocritic)
ERROR: 			func(size int) bool { return size >= nodeCount+1 }, scaleUpTimeout, unready))
ERROR: 			                             ^
ERROR: ../test/e2e/framework/replicaset/wait.go:38:10: badCond: `*(rs.Spec.Replicas) == rs.Status.Replicas && *(rs.Spec.Replicas) == rs.Status.ReadyReplicas` condition is suspicious (gocritic)
ERROR: 		return *(rs.Spec.Replicas) == rs.Status.Replicas && *(rs.Spec.Replicas) == rs.Status.ReadyReplicas, nil
ERROR: 		       ^
ERROR: ../test/e2e_node/device_plugin_test.go:98:18: badCall: suspicious Join on 1 argument (gocritic)
ERROR: 	pluginSockDir = filepath.Join(pluginSockDir) + "/"
ERROR: 	                ^
ERROR: ../test/e2e_node/remote/gce/gce_runner.go:586:6: equalFold: consider replacing with !strings.EqualFold(instance.Status, "RUNNING") (gocritic)
ERROR: 		if strings.ToUpper(instance.Status) != "RUNNING" {
ERROR: 		   ^
ERROR: ../test/e2e_node/remote/gce/gce_runner.go:672:5: equalFold: consider replacing with !strings.EqualFold(instance.Status, "RUNNING") (gocritic)
ERROR: 	if strings.ToUpper(instance.Status) != "RUNNING" {
ERROR: 	   ^
ERROR: ../test/integration/apiserver/discovery/discovery_test.go:963:7: equalFold: consider replacing with !strings.EqualFold(r.SingularName, r.Kind) (gocritic)
ERROR: 			if r.SingularName != strings.ToLower(r.Kind) {
ERROR: 		

Why is this needed?

This finishes the work started in #113256 and allows removing:

# TODO(oscr) Remove these excluded directories and fix findings. Due to large amount of findings in different components
# with different owners it's hard to fix everything in a single pr. This will therefore be done in multiple prs.
- path: (pkg/volume/*|test/*|azure/*|pkg/cmd/wait*|request/bearertoken/*|metrics/*|filters/*)
linters:
- gocritic

The issues raised seem legitimate and worth fixing, at least at first glance.

Metadata

Metadata

Labels

kind/featureCategorizes issue or PR as related to a new feature.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.sig/nodeCategorizes an issue or PR as relevant to SIG Node.sig/storageCategorizes an issue or PR as relevant to SIG Storage.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions