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

🌱 Add sub-modules in go lint and fix reported issues #897

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,18 @@ issues:
- linters:
- staticcheck
text: "^SA1019: [^.]+.WaitForResult is deprecated: Please use WaitForResultEx instead."
- linters:
- staticcheck
text: "^SA1019: .*TCPSocket is deprecated"
- linters:
- revive
text: ".*should have (a package )?comment.*"
- linters:
- revive
text: "^exported: comment on exported const"
- linters:
- staticcheck
text: "^SA1019: .*TCPSocket is deprecated"
- revive
text: "unused-parameter: parameter"
- linters:
- govet
text: "printf: non-constant format string in call"
Expand All @@ -254,6 +257,12 @@ issues:
linters:
- gosec
- depguard
- linters:
- revive
text: "unused-parameter: parameter"
# Ignore underscores in conversion function names as required by K8s API.
- path: "_conversion.go"
text: ".*use underscores in Go names"
# Ignore unsafe.Pointer() calls used in conversion functions.
- path: "_conversion.go"
text: "G103: Use of unsafe calls should be audited"
# Ignore different receiver names in conversion functions (e.g. src vs dst).
- path: "_conversion.go"
text: ".*receiver name"
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ PROJECT_SLUG := github.com/vmware-tanzu/vm-operator
# ROOT_DIR_IN_GOPATH is non-empty if ROOT_DIR is in the GOPATH.
ROOT_DIR_IN_GOPATH := $(findstring $(GOPATH)/src/$(PROJECT_SLUG),$(ROOT_DIR))

# R_WILDCARD recursively searches for a file that matches $1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches $2 in $1 no?

R_WILDCARD=$(wildcard $(1)$(2)) $(foreach DIR,$(wildcard $(1)*),$(call R_WILDCARD,$(DIR)/,$(2)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think $(foreach DIR,$(wildcard $(1)*) also lists files in $1, so you should change it to $(foreach DIR,$(wildcard $(1)*/)?


# Find all the go.mod files in the project.
GO_MOD_FILES := $(filter-out ./go.mod,$(strip $(call R_WILDCARD,./,go.mod)))
GO_MOD_DIRS := $(dir $(GO_MOD_FILES))

# CONVERSION_GEN_FALLBACK_MODE determines how to run the conversion-gen tool if
# this project is not in the GOPATH at the expected location. Possible values
# include "symlink" and "docker|podman".
Expand Down Expand Up @@ -276,10 +283,18 @@ lint: ## Run all the lint targets
$(MAKE) lint-shell

GOLANGCI_LINT_FLAGS ?= --fast=true
GOLANGCI_LINT_ABS_PATH := $(abspath $(GOLANGCI_LINT))
.PHONY: lint-go
lint-go: $(GOLANGCI_LINT)
lint-go: ## Lint codebase
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_FLAGS)
@for dir in $(GO_MOD_DIRS); do \
if [[ "$$dir" == ./external* || "$$dir" == ./hack/tools* ]]; then \
echo "Skipping $$dir"; \
continue; \
fi; \
echo "Running golangci-lint in $$dir"; \
(cd $$dir && $(GOLANGCI_LINT_ABS_PATH) run -v $(GOLANGCI_LINT_FLAGS)); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are GO_MOD_DIRS relative paths? If so I am curious how cd $$dir is working here since you pasted the output of running this target in your Testing Done section.

done

.PHONY: lint-go-full
lint-go-full: GOLANGCI_LINT_FLAGS = --fast=false
Expand Down
1 change: 1 addition & 0 deletions api/utilconversion/conversion_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package utilconversion
import (
"math/rand"

//nolint:depguard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious why we are hitting this. Is this now included in the allowed imports? Or this is because of deprecation etc?

"github.com/onsi/gomega"

"github.com/google/go-cmp/cmp"
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ func overrideVirtualMachineImageFieldsFuncs(codecs runtimeserializer.CodecFactor
overrideConditionsSeverity(imageStatus.Conditions)

// Do not exist in nextver.
//imageStatus.ContentLibraryRef = nil
imageStatus.ImageSupported = nil

// These are deprecated.
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/virtualmachineimage_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Convert_v1alpha4_VirtualMachineImageOSInfo_To_v1alpha1_VirtualMachineImageO
}

func convert_v1alpha1_VirtualMachineImageOSInfo_To_v1alpha4_VirtualMachineImageOSInfo(
in *VirtualMachineImageOSInfo, out *vmopv1.VirtualMachineImageOSInfo, s apiconversion.Scope) error {
in *VirtualMachineImageOSInfo, out *vmopv1.VirtualMachineImageOSInfo, _ apiconversion.Scope) error {

out.Type = in.Type
out.Version = in.Version
Expand All @@ -37,7 +37,7 @@ func convert_v1alpha1_VirtualMachineImageOSInfo_To_v1alpha4_VirtualMachineImageO
}

func convert_v1alpha4_VirtualMachineImage_OVFProperties_To_v1alpha1_VirtualMachineImage_OVFEnv(
in []vmopv1.OVFProperty, out *map[string]OvfProperty, s apiconversion.Scope) error {
in []vmopv1.OVFProperty, out *map[string]OvfProperty, _ apiconversion.Scope) error {

if in != nil {
*out = map[string]OvfProperty{}
Expand All @@ -56,7 +56,7 @@ func convert_v1alpha4_VirtualMachineImage_OVFProperties_To_v1alpha1_VirtualMachi
}

func convert_v1alpha1_VirtualMachineImage_OVFEnv_To_v1alpha4_VirtualMachineImage_OVFProperties(
in map[string]OvfProperty, out *[]vmopv1.OVFProperty, s apiconversion.Scope) error {
in map[string]OvfProperty, out *[]vmopv1.OVFProperty, _ apiconversion.Scope) error {

if in != nil {
*out = make([]vmopv1.OVFProperty, 0, len(in))
Expand Down Expand Up @@ -365,7 +365,7 @@ func convert_v1alpha1_VirtualMachineImageAnnotations_To_v1alpha4_VirtualMachineI

// remove any system annotations in nextver object
if *dstAnnotations != nil {
for k, _ := range *dstAnnotations {
for k := range *dstAnnotations {
if strings.HasPrefix(k, "vmware-system") {
delete(*dstAnnotations, k)
}
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha2/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
// +kubebuilder:object:generate=true
// +groupName=vmoperator.vmware.com
// +k8s:conversion-gen=github.com/vmware-tanzu/vm-operator/api/v1alpha4

package v1alpha2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
vmopv1sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha4/sysprep"
)

// Convert_sysprep_Sysprep_To_sysprep_Sysprep converts the Sysprep from v1alpha2
// to v1alpha4.
// Please see https://github.com/kubernetes/code-generator/issues/172 for why
// this function exists in this directory structure.
func Convert_sysprep_Sysprep_To_sysprep_Sysprep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
vmopv1sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha4/sysprep"
)

// Convert_sysprep_Sysprep_To_sysprep_Sysprep converts the Sysprep from v1alpha4
// to v1alpha2.
// Please see https://github.com/kubernetes/code-generator/issues/172 for why
// this function exists in this directory structure.
func Convert_sysprep_Sysprep_To_sysprep_Sysprep(
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha2/sysprep/sysprep.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type GUIUnattended struct {
TimeZone int32 `json:"timeZone,omitempty"`
}

// PasswordSecretKeySelector references the password value from a Secret resource
// PasswordSecretKeySelector references the password value from a Secret resource.
type PasswordSecretKeySelector struct {
// Name is the name of the secret.
Name string `json:"name"`
Expand Down Expand Up @@ -148,7 +148,7 @@ type Identification struct {
JoinWorkgroup string `json:"joinWorkgroup,omitempty"`
}

// DomainPasswordSecretKeySelector references the password value from a Secret resource
// DomainPasswordSecretKeySelector references the password value from a Secret resource.
type DomainPasswordSecretKeySelector struct {
// Name is the name of the secret.
Name string `json:"name"`
Expand Down Expand Up @@ -214,7 +214,7 @@ type UserData struct {
ProductID *ProductIDSecretKeySelector `json:"productID,omitempty"`
}

// ProductIDSecretKeySelector references the ProductID value from a Secret resource
// ProductIDSecretKeySelector references the ProductID value from a Secret resource.
type ProductIDSecretKeySelector struct {
// Name is the name of the secret.
Name string `json:"name"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha2/virtualmachine_readiness_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type TCPSocketAction struct {
// GuestHeartbeatStatus is the guest heartbeat status.
type GuestHeartbeatStatus string

// See govmomi.vim25.types.ManagedEntityStatus
// See govmomi.vim25.types.ManagedEntityStatus.
const (
// GrayHeartbeatStatus means VMware Tools are not installed or not running.
GrayHeartbeatStatus GuestHeartbeatStatus = "gray"
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha3/cloudinit/cloudconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package cloudinit
import (
"encoding/json"

vmopv1common "github.com/vmware-tanzu/vm-operator/api/v1alpha3/common"
vmopv1a3common "github.com/vmware-tanzu/vm-operator/api/v1alpha3/common"
)

// CloudConfig is the VM Operator API subset of a Cloud-Init CloudConfig and
Expand Down Expand Up @@ -101,7 +101,7 @@ type User struct {

// HashedPasswd is a hash of the user's password that will be applied even
// if the specified user already exists.
HashedPasswd *vmopv1common.SecretKeySelector `json:"hashed_passwd,omitempty"`
HashedPasswd *vmopv1a3common.SecretKeySelector `json:"hashed_passwd,omitempty"`

// +optional

Expand Down Expand Up @@ -157,7 +157,7 @@ type User struct {
// Passwd is a hash of the user's password that will be applied only to
// a newly created user. To apply a new, hashed password to an existing user
// please use HashedPasswd instead.
Passwd *vmopv1common.SecretKeySelector `json:"passwd,omitempty"`
Passwd *vmopv1a3common.SecretKeySelector `json:"passwd,omitempty"`

// +optional

Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha3/common/conversion/v1alpha3/common_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package v1alpha2
package v1alpha3

import (
"maps"
Expand All @@ -13,6 +13,8 @@ import (
vmopv1common "github.com/vmware-tanzu/vm-operator/api/v1alpha4/common"
)

// Convert_common_ObjectMeta_To_common_ObjectMeta converts the ObjectMeta from
// v1alpha3 to v1alpha4.
// Please see https://github.com/kubernetes/code-generator/issues/172 for why
// this function exists in this directory structure.
func Convert_common_ObjectMeta_To_common_ObjectMeta(
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha3/common/conversion/v1alpha4/common_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package v1alpha2
package v1alpha4

import (
"maps"
Expand All @@ -13,6 +13,8 @@ import (
vmopv1common "github.com/vmware-tanzu/vm-operator/api/v1alpha4/common"
)

// Convert_common_ObjectMeta_To_common_ObjectMeta converts the ObjectMeta from
// v1alpha4 to v1alpha3.
// Please see https://github.com/kubernetes/code-generator/issues/172 for why
// this function exists in this directory structure.
func Convert_common_ObjectMeta_To_common_ObjectMeta(
Expand Down
4 changes: 0 additions & 4 deletions api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,3 @@ func overrideVirtualMachineImageFieldsFuncs(codecs runtimeserializer.CodecFactor
},
}
}

func ptrOf[T any](v T) *T {
return &v
}
6 changes: 3 additions & 3 deletions api/v1alpha3/sysprep/sysprep.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type GUIUnattended struct {
TimeZone int32 `json:"timeZone"`
}

// PasswordSecretKeySelector references the password value from a Secret resource
// PasswordSecretKeySelector references the password value from a Secret resource.
type PasswordSecretKeySelector struct {
// Name is the name of the secret.
Name string `json:"name"`
Expand Down Expand Up @@ -150,7 +150,7 @@ type Identification struct {
JoinWorkgroup string `json:"joinWorkgroup,omitempty"`
}

// DomainPasswordSecretKeySelector references the password value from a Secret resource
// DomainPasswordSecretKeySelector references the password value from a Secret resource.
type DomainPasswordSecretKeySelector struct {
// Name is the name of the secret.
Name string `json:"name"`
Expand Down Expand Up @@ -217,7 +217,7 @@ type UserData struct {
ProductID *ProductIDSecretKeySelector `json:"productID,omitempty"`
}

// ProductIDSecretKeySelector references the ProductID value from a Secret resource
// ProductIDSecretKeySelector references the ProductID value from a Secret resource.
type ProductIDSecretKeySelector struct {
// Name is the name of the secret.
Name string `json:"name"`
Expand Down
16 changes: 8 additions & 8 deletions api/v1alpha3/virtualmachine_bootstrap_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package v1alpha3

import (
vmopv1cloudinit "github.com/vmware-tanzu/vm-operator/api/v1alpha3/cloudinit"
vmopv1common "github.com/vmware-tanzu/vm-operator/api/v1alpha3/common"
vmopv1sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha3/sysprep"
vmopv1a3cloudinit "github.com/vmware-tanzu/vm-operator/api/v1alpha3/cloudinit"
vmopv1a3common "github.com/vmware-tanzu/vm-operator/api/v1alpha3/common"
vmopv1a3sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha3/sysprep"
)

// VirtualMachineBootstrapSpec defines the desired state of a VM's bootstrap
Expand Down Expand Up @@ -98,7 +98,7 @@ type VirtualMachineBootstrapCloudInitSpec struct {
// bootstrap the VM.
//
// Please note this field and RawCloudConfig are mutually exclusive.
CloudConfig *vmopv1cloudinit.CloudConfig `json:"cloudConfig,omitempty"`
CloudConfig *vmopv1a3cloudinit.CloudConfig `json:"cloudConfig,omitempty"`

// +optional

Expand All @@ -109,7 +109,7 @@ type VirtualMachineBootstrapCloudInitSpec struct {
// base64-encoded, or gzipped and base64-encoded.
//
// Please note this field and CloudConfig are mutually exclusive.
RawCloudConfig *vmopv1common.SecretKeySelector `json:"rawCloudConfig,omitempty"`
RawCloudConfig *vmopv1a3common.SecretKeySelector `json:"rawCloudConfig,omitempty"`

// +optional

Expand Down Expand Up @@ -174,7 +174,7 @@ type VirtualMachineBootstrapSysprepSpec struct {
// https://technet.microsoft.com/en-us/library/cc771830(v=ws.10).aspx.
//
// Please note this field and RawSysprep are mutually exclusive.
Sysprep *vmopv1sysprep.Sysprep `json:"sysprep,omitempty"`
Sysprep *vmopv1a3sysprep.Sysprep `json:"sysprep,omitempty"`

// +optional

Expand All @@ -185,7 +185,7 @@ type VirtualMachineBootstrapSysprepSpec struct {
// or gzipped and base64-encoded.
//
// Please note this field and Sysprep are mutually exclusive.
RawSysprep *vmopv1common.SecretKeySelector `json:"rawSysprep,omitempty"`
RawSysprep *vmopv1a3common.SecretKeySelector `json:"rawSysprep,omitempty"`
}

// VirtualMachineBootstrapVAppConfigSpec describes the vApp configuration
Expand All @@ -198,7 +198,7 @@ type VirtualMachineBootstrapVAppConfigSpec struct {
// Properties is a list of vApp/OVF property key/value pairs.
//
// Please note this field and RawProperties are mutually exclusive.
Properties []vmopv1common.KeyValueOrSecretKeySelectorPair `json:"properties,omitempty"`
Properties []vmopv1a3common.KeyValueOrSecretKeySelectorPair `json:"properties,omitempty"`

// +optional

Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha3/virtualmachine_network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package v1alpha3
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

vmopv1common "github.com/vmware-tanzu/vm-operator/api/v1alpha3/common"
vmopv1a3common "github.com/vmware-tanzu/vm-operator/api/v1alpha3/common"
)

// VirtualMachineNetworkRouteSpec defines a static route for a guest.
Expand Down Expand Up @@ -43,7 +43,7 @@ type VirtualMachineNetworkInterfaceSpec struct {
//
// If no network is provided, then this interface will be connected to the
// Namespace's default network.
Network *vmopv1common.PartialObjectRef `json:"network,omitempty"`
Network *vmopv1a3common.PartialObjectRef `json:"network,omitempty"`

// +optional
// +kubebuilder:validation:Pattern=^\w\w+$
Expand Down Expand Up @@ -383,7 +383,7 @@ type VirtualMachineNetworkDHCPOptionsStatus struct {
// reported per interface would be:
// key='1', value='prepend domain-name-servers 192.0.2.1;'
// key='2', value='require subnet-mask, domain-name-servers;'.
Config []vmopv1common.KeyValuePair `json:"config,omitempty"`
Config []vmopv1a3common.KeyValuePair `json:"config,omitempty"`

// +optional

Expand Down Expand Up @@ -655,7 +655,7 @@ type VirtualMachineNetworkIPStackStatus struct {
// 'key=value' as provided by the underlying provider. For example, on
// Linux and/or BSD, the systcl -a output would be reported as:
// key='5', value='net.ipv4.tcp_keepalive_time = 7200'.
KernelConfig []vmopv1common.KeyValuePair `json:"kernelConfig,omitempty"`
KernelConfig []vmopv1a3common.KeyValuePair `json:"kernelConfig,omitempty"`
}

// VirtualMachineNetworkStatus defines the observed state of a VM's
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha3/virtualmachine_readiness_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type TCPSocketAction struct {
// GuestHeartbeatStatus is the guest heartbeat status.
type GuestHeartbeatStatus string

// See govmomi.vim25.types.ManagedEntityStatus
// See govmomi.vim25.types.ManagedEntityStatus.
const (
// GrayHeartbeatStatus means VMware Tools are not installed or not running.
GrayHeartbeatStatus GuestHeartbeatStatus = "gray"
Expand Down
Loading
Loading