From b784888a3d91fec5c312b0e15e1d80cb998526d4 Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Thu, 29 Aug 2024 11:25:20 -0500 Subject: [PATCH] Fix linting --- .golangci.yml | 3 ++- pkg/clusterlogging/clusterlogging.go | 4 ++-- pkg/hive/clusterimageset.go | 4 ++-- pkg/ibi/imageclusterinstall.go | 4 ++-- pkg/network/operator.go | 4 ++-- pkg/ocm/placementbinding_test.go | 4 +--- pkg/ocm/placementrule_test.go | 4 +--- pkg/ocm/policy_test.go | 4 +--- pkg/ocm/policyset_test.go | 1 + pkg/olm/catalogsource.go | 4 ++-- pkg/schemes/argocd/argocdtypes/v1alpha1/types.go | 2 -- pkg/servicemesh/controlplane.go | 4 ++-- pkg/sriov/networknodestate.go | 10 +++------- 13 files changed, 21 insertions(+), 31 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 13b544b5d..153c0bcd7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -83,6 +83,8 @@ linters-settings: checks: - all - ST1001 + - "-SA1006" + linters: enable: @@ -122,7 +124,6 @@ linters: - predeclared - promlinter - revive - - staticcheck - stylecheck - tenv - thelper diff --git a/pkg/clusterlogging/clusterlogging.go b/pkg/clusterlogging/clusterlogging.go index 6a2484214..dcdb49d8e 100644 --- a/pkg/clusterlogging/clusterlogging.go +++ b/pkg/clusterlogging/clusterlogging.go @@ -348,13 +348,13 @@ func (builder *Builder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" { diff --git a/pkg/hive/clusterimageset.go b/pkg/hive/clusterimageset.go index b47eb92f8..c158a9e30 100644 --- a/pkg/hive/clusterimageset.go +++ b/pkg/hive/clusterimageset.go @@ -293,13 +293,13 @@ func (builder *ClusterImageSetBuilder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" { diff --git a/pkg/ibi/imageclusterinstall.go b/pkg/ibi/imageclusterinstall.go index ef15dcdba..dd1c227f6 100644 --- a/pkg/ibi/imageclusterinstall.go +++ b/pkg/ibi/imageclusterinstall.go @@ -435,13 +435,13 @@ func (builder *ImageClusterInstallBuilder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" { diff --git a/pkg/network/operator.go b/pkg/network/operator.go index aef22db4b..4444dddec 100644 --- a/pkg/network/operator.go +++ b/pkg/network/operator.go @@ -238,13 +238,13 @@ func (builder *OperatorBuilder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" { diff --git a/pkg/ocm/placementbinding_test.go b/pkg/ocm/placementbinding_test.go index 0c48573c6..6d81a2b96 100644 --- a/pkg/ocm/placementbinding_test.go +++ b/pkg/ocm/placementbinding_test.go @@ -300,13 +300,11 @@ func TestPlacementBindingUpdate(t *testing.T) { } for _, testCase := range testCases { - testBuilder := buildValidPlacementBindingTestBuilder(buildTestClientWithPlacementBindingScheme()) - // Create the builder rather than just adding it to the client so that the proper metadata is added and // the update will not fail. var err error - testBuilder = buildValidPlacementBindingTestBuilder(buildTestClientWithPlacementBindingScheme()) + testBuilder := buildValidPlacementBindingTestBuilder(buildTestClientWithPlacementBindingScheme()) testBuilder, err = testBuilder.Create() assert.Nil(t, err) diff --git a/pkg/ocm/placementrule_test.go b/pkg/ocm/placementrule_test.go index 4c8501511..51bf089b5 100644 --- a/pkg/ocm/placementrule_test.go +++ b/pkg/ocm/placementrule_test.go @@ -268,13 +268,11 @@ func TestPlacementRuleUpdate(t *testing.T) { } for _, testCase := range testCases { - testBuilder := buildValidPlacementRuleTestBuilder(buildTestClientWithPlacementRuleScheme()) - // Create the builder rather than just adding it to the client so that the proper metadata is added and // the update will not fail. var err error - testBuilder = buildValidPlacementRuleTestBuilder(buildTestClientWithPlacementRuleScheme()) + testBuilder := buildValidPlacementRuleTestBuilder(buildTestClientWithPlacementRuleScheme()) testBuilder, err = testBuilder.Create() assert.Nil(t, err) diff --git a/pkg/ocm/policy_test.go b/pkg/ocm/policy_test.go index 618c97935..7e2009f79 100644 --- a/pkg/ocm/policy_test.go +++ b/pkg/ocm/policy_test.go @@ -286,11 +286,9 @@ func TestPolicyUpdate(t *testing.T) { } for _, testCase := range testCases { - testBuilder := buildValidPolicyTestBuilder(buildTestClientWithPolicyScheme()) - var err error - testBuilder = buildValidPolicyTestBuilder(buildTestClientWithPolicyScheme()) + testBuilder := buildValidPolicyTestBuilder(buildTestClientWithPolicyScheme()) testBuilder, err = testBuilder.Create() assert.Nil(t, err) diff --git a/pkg/ocm/policyset_test.go b/pkg/ocm/policyset_test.go index 55d8c09d7..396bb1fc9 100644 --- a/pkg/ocm/policyset_test.go +++ b/pkg/ocm/policyset_test.go @@ -286,6 +286,7 @@ func TestPolicySetUpdate(t *testing.T) { for _, testCase := range testCases { var err error + testBuilder := buildValidPolicySetTestBuilder(buildTestClientWithPolicySetScheme()) testBuilder, err = testBuilder.Create() assert.Nil(t, err) diff --git a/pkg/olm/catalogsource.go b/pkg/olm/catalogsource.go index c7209ff40..53068dc4e 100644 --- a/pkg/olm/catalogsource.go +++ b/pkg/olm/catalogsource.go @@ -265,13 +265,13 @@ func (builder *CatalogSourceBuilder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" { diff --git a/pkg/schemes/argocd/argocdtypes/v1alpha1/types.go b/pkg/schemes/argocd/argocdtypes/v1alpha1/types.go index dc03d9418..d522ecb9e 100644 --- a/pkg/schemes/argocd/argocdtypes/v1alpha1/types.go +++ b/pkg/schemes/argocd/argocdtypes/v1alpha1/types.go @@ -970,7 +970,6 @@ type ApplicationDestination struct { // Name is an alternate way of specifying the target cluster by its symbolic name. This must be set if Server is not set. Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"` - // nolint:govet isServerInferred bool `json:"-"` } @@ -1080,7 +1079,6 @@ type SyncOperationResource struct { Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"` Name string `json:"name" protobuf:"bytes,3,opt,name=name"` Namespace string `json:"namespace,omitempty" protobuf:"bytes,4,opt,name=namespace"` - // nolint:govet Exclude bool `json:"-"` } diff --git a/pkg/servicemesh/controlplane.go b/pkg/servicemesh/controlplane.go index 20b86246f..86db3675a 100644 --- a/pkg/servicemesh/controlplane.go +++ b/pkg/servicemesh/controlplane.go @@ -514,13 +514,13 @@ func (builder *ControlPlaneBuilder) validate() (bool, error) { if builder.Definition == nil { glog.V(100).Infof("The %s is undefined", resourceCRD) - builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD) + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) } if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" { diff --git a/pkg/sriov/networknodestate.go b/pkg/sriov/networknodestate.go index fbfd9e727..3e2738a2b 100644 --- a/pkg/sriov/networknodestate.go +++ b/pkg/sriov/networknodestate.go @@ -225,17 +225,13 @@ func (builder *NetworkNodeStateBuilder) findInterfaceByName(sriovInterfaceName s if err := builder.Discover(); err != nil { glog.V(100).Infof("Error to discover sriov network node state for node %s", builder.nodeName) - builder.errorMsg = "failed to discover sriov network node state" + return nil, fmt.Errorf("error to discover sriov network node state for node %s", builder.nodeName) } if sriovInterfaceName == "" { glog.V(100).Infof("The sriovInterface can not be empty string") - builder.errorMsg = "the sriovInterface is an empty sting" - } - - if builder.errorMsg != "" { - return nil, fmt.Errorf(builder.errorMsg) + return nil, fmt.Errorf("sriovInterfaceName cannot be empty") } for _, interf := range builder.Objects.Status.Interfaces { @@ -261,7 +257,7 @@ func (builder *NetworkNodeStateBuilder) validate() (bool, error) { if builder.apiClient == nil { glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD) - builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD) + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) } if builder.errorMsg != "" {