Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 lint: enable nolintlint and fix findings #2294

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ linters:
- nakedret
- nilerr
- noctx
# - nolintlint
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions apis/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha3/vspherecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha3/vspheremachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha3/vspheremachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha3/vspherevm_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 0 additions & 2 deletions apis/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha4/vspherecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions apis/v1alpha4/vsphereclusteridentity_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
1 change: 0 additions & 1 deletion apis/v1alpha4/vsphereclusteridentity_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:godot
package v1alpha4

import (
Expand Down
4 changes: 2 additions & 2 deletions apis/v1alpha4/vsphereclustertemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions apis/v1alpha4/vspheredeploymentzone_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions apis/v1alpha4/vspherefailuredomain_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
1 change: 0 additions & 1 deletion apis/v1alpha4/vspheremachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
11 changes: 4 additions & 7 deletions apis/v1alpha4/vspheremachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha4/vspherevm_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion apis/v1beta1/vsphereclustertemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 0 additions & 2 deletions apis/v1beta1/vspheremachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions apis/v1beta1/vspheremachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,9 +105,7 @@ func TestVSphereMachine_ValidateCreate(t *testing.T) {
}
}

//nolint:all
func TestVSphereMachine_ValidateUpdate(t *testing.T) {

g := NewWithT(t)

tests := []struct {
Expand Down
2 changes: 0 additions & 2 deletions apis/v1beta1/vspherevm_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmware/test/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions controllers/vmware/test/controllers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/vspherevm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion packaging/flavorgen/flavors/util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions pkg/identity/identity_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -64,6 +65,7 @@ func init() {
ErrorIfCRDPathMissing: true,
CRDDirectoryPaths: crdPaths,
}
return env
}

func TestIdentity(t *testing.T) {
Expand All @@ -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())

Expand Down
1 change: 0 additions & 1 deletion pkg/services/govmomi/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/govmomi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vm-ID>:<disk>
diskID := fmt.Sprintf("%s:%d", ctx.Obj.Reference().Value, disk.Key)
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/govmomi/vcenter/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading
Loading