From 6c47a65170b92be954c73364df187bccd5ca73cf Mon Sep 17 00:00:00 2001 From: dxinyuan Date: Tue, 29 Aug 2023 14:52:27 +0800 Subject: [PATCH] lint: enable `-nolintlint` and fix findings --- .golangci.yml | 8 ++++++-- apis/v1alpha3/conversion.go | 4 ---- apis/v1alpha3/vspherecluster_conversion.go | 1 - apis/v1alpha3/vspheremachine_conversion.go | 1 - apis/v1alpha3/vspheremachinetemplate_conversion.go | 1 - apis/v1alpha3/vspherevm_conversion.go | 1 - apis/v1alpha4/conversion.go | 2 -- apis/v1alpha4/vspherecluster_conversion.go | 1 - apis/v1alpha4/vsphereclusteridentity_conversion.go | 4 ++-- apis/v1alpha4/vsphereclusteridentity_types.go | 1 - apis/v1alpha4/vsphereclustertemplate_conversion.go | 4 ++-- apis/v1alpha4/vspheredeploymentzone_conversion.go | 4 ++-- apis/v1alpha4/vspherefailuredomain_conversion.go | 4 ++-- apis/v1alpha4/vspheremachine_conversion.go | 1 - apis/v1alpha4/vspheremachinetemplate_conversion.go | 11 ++++------- apis/v1alpha4/vspherevm_conversion.go | 1 - apis/v1beta1/vsphereclustertemplate_webhook.go | 2 +- apis/v1beta1/vspheremachine_webhook.go | 2 -- apis/v1beta1/vspheremachine_webhook_test.go | 4 ---- apis/v1beta1/vspherevm_webhook.go | 2 -- controllers/vmware/test/controllers_suite_test.go | 3 ++- controllers/vmware/test/controllers_test.go | 4 ++-- controllers/vspherevm_controller.go | 2 -- packaging/flavorgen/flavors/util/helpers.go | 2 +- pkg/identity/identity_suite_test.go | 7 +++++-- pkg/services/govmomi/create_test.go | 1 - pkg/services/govmomi/service.go | 2 +- pkg/services/govmomi/vcenter/clone.go | 2 +- pkg/services/govmomi/vcenter/clone_test.go | 9 +++------ test/helpers/envtest.go | 5 ++++- test/helpers/vcsim/simulator.go | 5 +---- test/helpers/webhook.go | 5 ++++- 32 files changed, 43 insertions(+), 63 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d04a9c6456..25adf6f68e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -37,7 +37,7 @@ linters: - nakedret - nilerr - noctx - # - nolintlint + - nolintlint - nosprintfhostport - prealloc - predeclared @@ -55,7 +55,11 @@ linters: linters-settings: gci: - local-prefixes: "sigs.k8s.io/cluster-api-provider-vsphere" + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(sigs.k8s.io/cluster-api-provider-vsphere) # Custom section: groups all imports with the specified Prefix. + custom-order: true godot: # declarations - for top level declaration comments (default); # toplevel - for top level comments; diff --git a/apis/v1alpha3/conversion.go b/apis/v1alpha3/conversion.go index 5d4e2abd36..1dd265e51b 100644 --- a/apis/v1alpha3/conversion.go +++ b/apis/v1alpha3/conversion.go @@ -23,15 +23,11 @@ import ( ) // Convert_v1beta1_VirtualMachineCloneSpec_To_v1alpha3_VirtualMachineCloneSpec is an autogenerated conversion function. -// -//nolint:golint,revive,stylecheck func Convert_v1beta1_VirtualMachineCloneSpec_To_v1alpha3_VirtualMachineCloneSpec(in *v1beta1.VirtualMachineCloneSpec, out *VirtualMachineCloneSpec, s conversion.Scope) error { return autoConvert_v1beta1_VirtualMachineCloneSpec_To_v1alpha3_VirtualMachineCloneSpec(in, out, s) } // Convert_v1beta1_VSphereVMStatus_To_v1alpha3_VSphereVMStatus is an autogenerated conversion function. -// -//nolint:golint,revive,stylecheck func Convert_v1beta1_VSphereVMStatus_To_v1alpha3_VSphereVMStatus(in *v1beta1.VSphereVMStatus, out *VSphereVMStatus, s conversion.Scope) error { return autoConvert_v1beta1_VSphereVMStatus_To_v1alpha3_VSphereVMStatus(in, out, s) } diff --git a/apis/v1alpha3/vspherecluster_conversion.go b/apis/v1alpha3/vspherecluster_conversion.go index 94f3bcbd51..a3875f0c6f 100644 --- a/apis/v1alpha3/vspherecluster_conversion.go +++ b/apis/v1alpha3/vspherecluster_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:forcetypeassert,golint,revive,stylecheck package v1alpha3 import ( diff --git a/apis/v1alpha3/vspheremachine_conversion.go b/apis/v1alpha3/vspheremachine_conversion.go index 345d7fde12..c19bf2a35f 100644 --- a/apis/v1alpha3/vspheremachine_conversion.go +++ b/apis/v1alpha3/vspheremachine_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:forcetypeassert,golint,revive,stylecheck package v1alpha3 import ( diff --git a/apis/v1alpha3/vspheremachinetemplate_conversion.go b/apis/v1alpha3/vspheremachinetemplate_conversion.go index 14ced56475..521f8e641a 100644 --- a/apis/v1alpha3/vspheremachinetemplate_conversion.go +++ b/apis/v1alpha3/vspheremachinetemplate_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:forcetypeassert,golint,revive,stylecheck package v1alpha3 import ( diff --git a/apis/v1alpha3/vspherevm_conversion.go b/apis/v1alpha3/vspherevm_conversion.go index 2d62a93213..d84b8af6a9 100644 --- a/apis/v1alpha3/vspherevm_conversion.go +++ b/apis/v1alpha3/vspherevm_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:forcetypeassert,golint,revive,stylecheck package v1alpha3 import ( diff --git a/apis/v1alpha4/conversion.go b/apis/v1alpha4/conversion.go index 48239de1ef..289c7933a3 100644 --- a/apis/v1alpha4/conversion.go +++ b/apis/v1alpha4/conversion.go @@ -23,8 +23,6 @@ import ( ) // Convert_v1beta1_VirtualMachineCloneSpec_To_v1alpha4_VirtualMachineCloneSpec is an autogenerated conversion function. -// -//nolint:golint,revive,stylecheck func Convert_v1beta1_VirtualMachineCloneSpec_To_v1alpha4_VirtualMachineCloneSpec(in *infrav1.VirtualMachineCloneSpec, out *VirtualMachineCloneSpec, s conversion.Scope) error { return autoConvert_v1beta1_VirtualMachineCloneSpec_To_v1alpha4_VirtualMachineCloneSpec(in, out, s) } diff --git a/apis/v1alpha4/vspherecluster_conversion.go b/apis/v1alpha4/vspherecluster_conversion.go index 2f7546d717..e8ffaaf114 100644 --- a/apis/v1alpha4/vspherecluster_conversion.go +++ b/apis/v1alpha4/vspherecluster_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:forcetypeassert,golint,revive,stylecheck package v1alpha4 import ( diff --git a/apis/v1alpha4/vsphereclusteridentity_conversion.go b/apis/v1alpha4/vsphereclusteridentity_conversion.go index ccb227e7b4..b6499ddc7c 100644 --- a/apis/v1alpha4/vsphereclusteridentity_conversion.go +++ b/apis/v1alpha4/vsphereclusteridentity_conversion.go @@ -29,7 +29,7 @@ func (src *VSphereClusterIdentity) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts from the Hub version (v1beta1) to this VSphereClusterIdentity. -func (dst *VSphereClusterIdentity) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereClusterIdentity) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereClusterIdentity) return Convert_v1beta1_VSphereClusterIdentity_To_v1alpha4_VSphereClusterIdentity(src, dst, nil) } @@ -41,7 +41,7 @@ func (src *VSphereClusterIdentityList) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts this VSphereClusterIdentityList to the Hub version (v1beta1). -func (dst *VSphereClusterIdentityList) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereClusterIdentityList) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereClusterIdentityList) return Convert_v1beta1_VSphereClusterIdentityList_To_v1alpha4_VSphereClusterIdentityList(src, dst, nil) } diff --git a/apis/v1alpha4/vsphereclusteridentity_types.go b/apis/v1alpha4/vsphereclusteridentity_types.go index 223c95fc85..4217a78673 100644 --- a/apis/v1alpha4/vsphereclusteridentity_types.go +++ b/apis/v1alpha4/vsphereclusteridentity_types.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:godot package v1alpha4 import ( diff --git a/apis/v1alpha4/vsphereclustertemplate_conversion.go b/apis/v1alpha4/vsphereclustertemplate_conversion.go index 499cb90b15..7736da4d27 100644 --- a/apis/v1alpha4/vsphereclustertemplate_conversion.go +++ b/apis/v1alpha4/vsphereclustertemplate_conversion.go @@ -29,7 +29,7 @@ func (src *VSphereClusterTemplate) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts from the Hub version (v1beta1) to this VSphereClusterTemplate. -func (dst *VSphereClusterTemplate) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereClusterTemplate) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereClusterTemplate) return Convert_v1beta1_VSphereClusterTemplate_To_v1alpha4_VSphereClusterTemplate(src, dst, nil) } @@ -41,7 +41,7 @@ func (src *VSphereClusterTemplateList) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts this VSphereClusterIdentityList to the Hub version (v1beta1). -func (dst *VSphereClusterTemplateList) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereClusterTemplateList) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereClusterTemplateList) return Convert_v1beta1_VSphereClusterTemplateList_To_v1alpha4_VSphereClusterTemplateList(src, dst, nil) } diff --git a/apis/v1alpha4/vspheredeploymentzone_conversion.go b/apis/v1alpha4/vspheredeploymentzone_conversion.go index 85fe22028b..857fc6e741 100644 --- a/apis/v1alpha4/vspheredeploymentzone_conversion.go +++ b/apis/v1alpha4/vspheredeploymentzone_conversion.go @@ -29,7 +29,7 @@ func (src *VSphereDeploymentZone) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts from the Hub version (v1beta1) to this VSphereDeploymentZone. -func (dst *VSphereDeploymentZone) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereDeploymentZone) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereDeploymentZone) return Convert_v1beta1_VSphereDeploymentZone_To_v1alpha4_VSphereDeploymentZone(src, dst, nil) } @@ -41,7 +41,7 @@ func (src *VSphereDeploymentZoneList) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts this VSphereDeploymentZoneList to the Hub version (v1beta1). -func (dst *VSphereDeploymentZoneList) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereDeploymentZoneList) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereDeploymentZoneList) return Convert_v1beta1_VSphereDeploymentZoneList_To_v1alpha4_VSphereDeploymentZoneList(src, dst, nil) } diff --git a/apis/v1alpha4/vspherefailuredomain_conversion.go b/apis/v1alpha4/vspherefailuredomain_conversion.go index c1279e520b..006033f971 100644 --- a/apis/v1alpha4/vspherefailuredomain_conversion.go +++ b/apis/v1alpha4/vspherefailuredomain_conversion.go @@ -29,7 +29,7 @@ func (src *VSphereFailureDomain) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts from the Hub version (v1beta1) to this VSphereFailureDomain. -func (dst *VSphereFailureDomain) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereFailureDomain) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereFailureDomain) return Convert_v1beta1_VSphereFailureDomain_To_v1alpha4_VSphereFailureDomain(src, dst, nil) } @@ -41,7 +41,7 @@ func (src *VSphereFailureDomainList) ConvertTo(dstRaw conversion.Hub) error { } // ConvertFrom converts this VSphereFailureDomainList to the Hub version (v1beta1). -func (dst *VSphereFailureDomainList) ConvertFrom(srcRaw conversion.Hub) error { // nolint +func (dst *VSphereFailureDomainList) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*infrav1.VSphereFailureDomainList) return Convert_v1beta1_VSphereFailureDomainList_To_v1alpha4_VSphereFailureDomainList(src, dst, nil) } diff --git a/apis/v1alpha4/vspheremachine_conversion.go b/apis/v1alpha4/vspheremachine_conversion.go index 4320ccb997..be24354e57 100644 --- a/apis/v1alpha4/vspheremachine_conversion.go +++ b/apis/v1alpha4/vspheremachine_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:forcetypeassert,golint,revive,stylecheck package v1alpha4 import ( diff --git a/apis/v1alpha4/vspheremachinetemplate_conversion.go b/apis/v1alpha4/vspheremachinetemplate_conversion.go index 0061d79fc3..43fe4977ef 100644 --- a/apis/v1alpha4/vspheremachinetemplate_conversion.go +++ b/apis/v1alpha4/vspheremachinetemplate_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:golint,revive,stylecheck package v1alpha4 import ( @@ -29,7 +28,7 @@ import ( // ConvertTo. func (src *VSphereMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1.VSphereMachineTemplate) //nolint:forcetypeassert + dst := dstRaw.(*infrav1.VSphereMachineTemplate) if err := Convert_v1alpha4_VSphereMachineTemplate_To_v1beta1_VSphereMachineTemplate(src, dst, nil); err != nil { return err } @@ -53,7 +52,7 @@ func (src *VSphereMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { } func (dst *VSphereMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1.VSphereMachineTemplate) //nolint:forcetypeassert + src := srcRaw.(*infrav1.VSphereMachineTemplate) if err := Convert_v1beta1_VSphereMachineTemplate_To_v1alpha4_VSphereMachineTemplate(src, dst, nil); err != nil { return err } @@ -67,23 +66,21 @@ func (dst *VSphereMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error { } func (src *VSphereMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1.VSphereMachineTemplateList) //nolint:forcetypeassert + dst := dstRaw.(*infrav1.VSphereMachineTemplateList) return Convert_v1alpha4_VSphereMachineTemplateList_To_v1beta1_VSphereMachineTemplateList(src, dst, nil) } func (dst *VSphereMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1.VSphereMachineTemplateList) //nolint:forcetypeassert + src := srcRaw.(*infrav1.VSphereMachineTemplateList) return Convert_v1beta1_VSphereMachineTemplateList_To_v1alpha4_VSphereMachineTemplateList(src, dst, nil) } -// nolint func Convert_v1alpha4_ObjectMeta_To_v1beta1_ObjectMeta(in *clusterv1alpha4.ObjectMeta, out *clusterv1.ObjectMeta, s apiconversion.Scope) error { // wrapping the conversion func to avoid having compile errors due to compileErrorOnMissingConversion() // more details at https://github.com/kubernetes/kubernetes/issues/98380 return clusterv1alpha4.Convert_v1alpha4_ObjectMeta_To_v1beta1_ObjectMeta(in, out, s) } -// nolint func Convert_v1beta1_ObjectMeta_To_v1alpha4_ObjectMeta(in *clusterv1.ObjectMeta, out *clusterv1alpha4.ObjectMeta, s apiconversion.Scope) error { // wrapping the conversion func to avoid having compile errors due to compileErrorOnMissingConversion() // more details at https://github.com/kubernetes/kubernetes/issues/98380 diff --git a/apis/v1alpha4/vspherevm_conversion.go b/apis/v1alpha4/vspherevm_conversion.go index a2eece0b41..023c6a65fd 100644 --- a/apis/v1alpha4/vspherevm_conversion.go +++ b/apis/v1alpha4/vspherevm_conversion.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:forcetypeassert,golint,revive,stylecheck package v1alpha4 import ( diff --git a/apis/v1beta1/vsphereclustertemplate_webhook.go b/apis/v1beta1/vsphereclustertemplate_webhook.go index 2c617d0f61..828159f865 100644 --- a/apis/v1beta1/vsphereclustertemplate_webhook.go +++ b/apis/v1beta1/vsphereclustertemplate_webhook.go @@ -43,7 +43,7 @@ func (r *VSphereClusterTemplate) ValidateCreate() (admission.Warnings, error) { // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. func (r *VSphereClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) { - old := oldRaw.(*VSphereClusterTemplate) //nolint:forcetypeassert + old := oldRaw.(*VSphereClusterTemplate) if !reflect.DeepEqual(r.Spec.Template.Spec, old.Spec.Template.Spec) { return nil, field.Forbidden(field.NewPath("spec", "template", "spec"), "VSphereClusterTemplate spec is immutable") } diff --git a/apis/v1beta1/vspheremachine_webhook.go b/apis/v1beta1/vspheremachine_webhook.go index eec3324c59..dca4031c3b 100644 --- a/apis/v1beta1/vspheremachine_webhook.go +++ b/apis/v1beta1/vspheremachine_webhook.go @@ -79,8 +79,6 @@ func (m *VSphereMachine) ValidateCreate() (admission.Warnings, error) { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. -// -//nolint:forcetypeassert func (m *VSphereMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { var allErrs field.ErrorList if m.Spec.GuestSoftPowerOffTimeout != nil { diff --git a/apis/v1beta1/vspheremachine_webhook_test.go b/apis/v1beta1/vspheremachine_webhook_test.go index 5fcc2d3085..0d288c5518 100644 --- a/apis/v1beta1/vspheremachine_webhook_test.go +++ b/apis/v1beta1/vspheremachine_webhook_test.go @@ -35,9 +35,7 @@ func TestVsphereMachine_Default(t *testing.T) { g.Expect(m.Spec.Datacenter).To(Equal("*")) } -//nolint:all func TestVSphereMachine_ValidateCreate(t *testing.T) { - g := NewWithT(t) tests := []struct { name string @@ -107,9 +105,7 @@ func TestVSphereMachine_ValidateCreate(t *testing.T) { } } -//nolint:all func TestVSphereMachine_ValidateUpdate(t *testing.T) { - g := NewWithT(t) tests := []struct { diff --git a/apis/v1beta1/vspherevm_webhook.go b/apis/v1beta1/vspherevm_webhook.go index 95b2cb1fe2..11c110507a 100644 --- a/apis/v1beta1/vspherevm_webhook.go +++ b/apis/v1beta1/vspherevm_webhook.go @@ -78,8 +78,6 @@ func (r *VSphereVM) ValidateCreate() (admission.Warnings, error) { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. -// -//nolint:forcetypeassert func (r *VSphereVM) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { var allErrs field.ErrorList if r.Spec.GuestSoftPowerOffTimeout != nil { diff --git a/controllers/vmware/test/controllers_suite_test.go b/controllers/vmware/test/controllers_suite_test.go index a871506337..8bbc4e161b 100644 --- a/controllers/vmware/test/controllers_suite_test.go +++ b/controllers/vmware/test/controllers_suite_test.go @@ -65,7 +65,8 @@ func getTestEnv() (*envtest.Environment, *rest.Config) { utilruntime.Must(vmwarev1.AddToScheme(scheme.Scheme)) // Get the root of the current file to use in CRD paths. - _, filename, _, _ := goruntime.Caller(0) //nolint + _, filename, _, ok := goruntime.Caller(0) + Expect(ok).To(BeTrue(), "Failed to get information for current file from runtime") root := path.Join(path.Dir(filename), "..", "..", "..") localTestEnv := &envtest.Environment{ diff --git a/controllers/vmware/test/controllers_test.go b/controllers/vmware/test/controllers_test.go index 846e86ae51..0407a696e0 100644 --- a/controllers/vmware/test/controllers_test.go +++ b/controllers/vmware/test/controllers_test.go @@ -355,7 +355,7 @@ var _ = Describe("Reconciliation tests", func() { if err := k8sClient.Get(ctx, key, obj); err != nil { return "", err } - vSphereMachine := obj.(*vmwarev1.VSphereMachine) //nolint:forcetypeassert + vSphereMachine := obj.(*vmwarev1.VSphereMachine) return vSphereMachine.Status.VMStatus, nil }, time.Second*30).Should(Equal(expectedState)) } @@ -365,7 +365,7 @@ var _ = Describe("Reconciliation tests", func() { if err := k8sClient.Get(ctx, key, obj); err != nil { return "", err } - vsphereCluster := obj.(*vmwarev1.VSphereCluster) //nolint:forcetypeassert + vsphereCluster := obj.(*vmwarev1.VSphereCluster) return vsphereCluster.Spec.ControlPlaneEndpoint.Host, nil }, time.Second*30).Should(Equal(expectedIP)) } diff --git a/controllers/vspherevm_controller.go b/controllers/vspherevm_controller.go index 3fb789c244..9d3b0af907 100644 --- a/controllers/vspherevm_controller.go +++ b/controllers/vspherevm_controller.go @@ -70,8 +70,6 @@ import ( // +kubebuilder:rbac:groups=core,resources=nodes,verbs=get;list;delete // AddVMControllerToManager adds the VM controller to the provided manager. -// -//nolint:forcetypeassert func AddVMControllerToManager(ctx *context.ControllerManagerContext, mgr manager.Manager, tracker *remote.ClusterCacheTracker, options controller.Options) error { var ( controlledType = &infrav1.VSphereVM{} diff --git a/packaging/flavorgen/flavors/util/helpers.go b/packaging/flavorgen/flavors/util/helpers.go index 3a775044a2..3f3c71b45c 100644 --- a/packaging/flavorgen/flavors/util/helpers.go +++ b/packaging/flavorgen/flavors/util/helpers.go @@ -115,7 +115,7 @@ func deleteZeroValues(o map[string]interface{}) map[string]interface{} { continue } if val.Kind() == reflect.Map { - newMap := v.(map[string]interface{}) //nolint:forcetypeassert + newMap := v.(map[string]interface{}) newMap = deleteZeroValues(newMap) if isZeroValue(reflect.ValueOf(newMap)) { delete(o, k) diff --git a/pkg/identity/identity_suite_test.go b/pkg/identity/identity_suite_test.go index ed4b1709bf..6bcc26cf08 100644 --- a/pkg/identity/identity_suite_test.go +++ b/pkg/identity/identity_suite_test.go @@ -47,13 +47,14 @@ var ( ctx goctx.Context ) -func init() { +func getTestEnv() *envtest.Environment { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) utilruntime.Must(apiextensionsv1.AddToScheme(scheme)) utilruntime.Must(infrav1.AddToScheme(scheme)) utilruntime.Must(infrav1alpha3.AddToScheme(scheme)) - _, filename, _, _ := goruntime.Caller(0) //nolint + _, filename, _, ok := goruntime.Caller(0) + Expect(ok).To(BeTrue(), "Failed to get information for current file from runtime") root := path.Join(path.Dir(filename), "..", "..") crdPaths := []string{ @@ -64,6 +65,7 @@ func init() { ErrorIfCRDPathMissing: true, CRDDirectoryPaths: crdPaths, } + return env } func TestIdentity(t *testing.T) { @@ -74,6 +76,7 @@ func TestIdentity(t *testing.T) { var _ = SynchronizedBeforeSuite(func() []byte { By("Creating new test environment") ctx = goctx.Background() + env = getTestEnv() cfg, err := env.Start() Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/services/govmomi/create_test.go b/pkg/services/govmomi/create_test.go index faf85245ea..9cc55e04bc 100644 --- a/pkg/services/govmomi/create_test.go +++ b/pkg/services/govmomi/create_test.go @@ -29,7 +29,6 @@ import ( "sigs.k8s.io/cluster-api-provider-vsphere/test/helpers/vcsim" ) -//nolint:forcetypeassert func TestCreate(t *testing.T) { model := simulator.VPX() model.Host = 0 // ClusterHost only diff --git a/pkg/services/govmomi/service.go b/pkg/services/govmomi/service.go index 5860c63390..c78eeeee80 100644 --- a/pkg/services/govmomi/service.go +++ b/pkg/services/govmomi/service.go @@ -407,7 +407,7 @@ func (vms *VMService) reconcileStoragePolicy(ctx *virtualMachineContext) error { disks := devices.SelectByType((*types.VirtualDisk)(nil)) for _, d := range disks { - disk := d.(*types.VirtualDisk) //nolint:forcetypeassert + disk := d.(*types.VirtualDisk) found := false // entities associated with storage policy has key in the form : diskID := fmt.Sprintf("%s:%d", ctx.Obj.Reference().Value, disk.Key) diff --git a/pkg/services/govmomi/vcenter/clone.go b/pkg/services/govmomi/vcenter/clone.go index c6d1e1d188..68f29c363d 100644 --- a/pkg/services/govmomi/vcenter/clone.go +++ b/pkg/services/govmomi/vcenter/clone.go @@ -345,7 +345,7 @@ func getDiskSpec(ctx *context.VMContext, devices object.VirtualDeviceList) ([]ty // There is at least one disk var diskSpecs []types.BaseVirtualDeviceConfigSpec - primaryDisk := disks[0].(*types.VirtualDisk) //nolint:forcetypeassert + primaryDisk := disks[0].(*types.VirtualDisk) primaryCloneCapacityKB := int64(ctx.VSphereVM.Spec.DiskGiB) * 1024 * 1024 primaryDiskConfigSpec, err := getDiskConfigSpec(primaryDisk, primaryCloneCapacityKB) if err != nil { diff --git a/pkg/services/govmomi/vcenter/clone_test.go b/pkg/services/govmomi/vcenter/clone_test.go index cf1c3e9c10..e304c99486 100644 --- a/pkg/services/govmomi/vcenter/clone_test.go +++ b/pkg/services/govmomi/vcenter/clone_test.go @@ -16,7 +16,6 @@ limitations under the License. package vcenter -//nolint:all import ( ctx "context" "crypto/tls" @@ -24,9 +23,7 @@ import ( "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/simulator" - - // run init func to register the tagging API endpoints. - _ "github.com/vmware/govmomi/vapi/simulator" + _ "github.com/vmware/govmomi/vapi/simulator" // run init func to register the tagging API endpoints. "github.com/vmware/govmomi/vim25/types" infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1" @@ -40,7 +37,7 @@ func TestGetDiskSpec(t *testing.T) { model, session, server := initSimulator(t) t.Cleanup(model.Remove) t.Cleanup(server.Close) - vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine) //nolint:forcetypeassert + vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine) machine := object.NewVirtualMachine(session.Client.Client, vm.Reference()) devices, err := machine.Device(ctx.TODO()) @@ -51,7 +48,7 @@ func TestGetDiskSpec(t *testing.T) { if len(defaultDisks) < 1 { t.Fatal("Unable to find attached disk for resize") } - disk := defaultDisks[0].(*types.VirtualDisk) //nolint:forcetypeassert + disk := defaultDisks[0].(*types.VirtualDisk) disk.CapacityInKB = int64(defaultSizeGiB) * 1024 * 1024 // GiB if err := machine.EditDevice(ctx.TODO(), disk); err != nil { t.Fatalf("Can't resize disk for specified size") diff --git a/test/helpers/envtest.go b/test/helpers/envtest.go index 74dc145b2e..b4f11e832d 100644 --- a/test/helpers/envtest.go +++ b/test/helpers/envtest.go @@ -75,7 +75,10 @@ func init() { utilruntime.Must(infrav1.AddToScheme(scheme)) // Get the root of the current file to use in CRD paths. - _, filename, _, _ := goruntime.Caller(0) //nolint + _, filename, _, ok := goruntime.Caller(0) + if !ok { + klog.Fatalf("Failed to get information for current file from runtime") + } root := path.Join(path.Dir(filename), "..", "..") crdPaths := []string{ diff --git a/test/helpers/vcsim/simulator.go b/test/helpers/vcsim/simulator.go index 4ec3e41536..a382412546 100644 --- a/test/helpers/vcsim/simulator.go +++ b/test/helpers/vcsim/simulator.go @@ -16,16 +16,13 @@ limitations under the License. package vcsim -//nolint:all import ( "fmt" "net/url" "github.com/onsi/gomega/gbytes" "github.com/vmware/govmomi/simulator" - - // run init func to register the tagging API endpoints. - _ "github.com/vmware/govmomi/vapi/simulator" + _ "github.com/vmware/govmomi/vapi/simulator" // run init func to register the tagging API endpoints. ) type Simulator struct { diff --git a/test/helpers/webhook.go b/test/helpers/webhook.go index 1d1d0248bf..7bc1399645 100644 --- a/test/helpers/webhook.go +++ b/test/helpers/webhook.go @@ -79,7 +79,10 @@ func appendWebhookConfiguration(configyamlFile []byte, tag string) ([]*v1.Mutati func initializeWebhookInEnvironment() { // Get the root of the current file to use in CRD paths. - _, filename, _, _ := goruntime.Caller(0) //nolint + _, filename, _, ok := goruntime.Caller(0) + if !ok { + klog.Fatalf("Failed to get information for current file from runtime") + } root := path.Join(path.Dir(filename), "..", "..") configyamlFile, err := os.ReadFile(filepath.Join(root, "config", "webhook", "manifests.yaml")) if err != nil {