Skip to content

Commit

Permalink
Enable golangci-lint on neonvm/ (#721)
Browse files Browse the repository at this point in the history
Lots of changes to .golangci.yml to add exemptions for exhaustruct.
Also lots of smaller changes in neonvm/ to resolve the lint issues.

This will probably have conflicts with other ongoing work.
  • Loading branch information
sharnoff committed Jan 4, 2024
1 parent bacdd39 commit 8a91e83
Show file tree
Hide file tree
Showing 21 changed files with 313 additions and 225 deletions.
34 changes: 24 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
run:
deadline: 5m
issues-exit-code: 1
# TODO: fix all the issues for neonvm and enable linter for it
skip-dirs:
- neonvm

issues:
exclude:
Expand Down Expand Up @@ -53,20 +50,37 @@ linters-settings:
# see: <https://golangci-lint.run/usage/linters/#exhaustruct>
exhaustruct:
exclude:
- '^crypto/tls\.Config$'
- '^net/http\.(Client|Server)'
- '^net\.TCPAddr$'
# metav1.{CreateOptions,GetOptions,ListOptions,WatchOptions,PatchOptions,DeleteOptions}
- '^k8s\.io/apimachinery/pkg/apis/meta/v1\.(Create|Get|List|Watch|Patch|Delete)Options$'
- '^k8s\.io/apimachinery/pkg/apis/meta/v1\.ObjectMeta$'
- '^net\.(Dialer|TCPAddr)$'
- '^archive/tar\.Header$'
- '^k8s\.io/api/core/v1\.\w+$'
- '^k8s\.io/apimachinery/pkg/api/resource\.Quantity$'
- '^github.com/prometheus/client_golang/prometheus(/.*)?\.\w+Opts$'
# metav1.{CreateOptions,GetOptions,ListOptions,WatchOptions,PatchOptions,UpdateOptions,DeleteOptions}
- '^k8s\.io/apimachinery/pkg/apis/meta/v1\.(Create|Get|List|Watch|Patch|Update|Delete)Options$'
- '^k8s\.io/apimachinery/pkg/apis/meta/v1\.(Condition|LabelSelector|ObjectMeta)$'
- '^k8s\.io/client-go/tools/leaderelection/resourcelock\.ResourceLockConfig$'
- '^k8s\.io/client-go/tools/leaderelection\.(LeaderCallbacks|LeaderElectionConfig)$'
- '^sigs\.k8s\.io/controller-runtime/pkg/client\.Options$'
- '^sigs\.k8s\.io/controller-runtime/pkg/controller\.Options$'
- '^sigs\.k8s\.io/controller-runtime/pkg/envtest\.(Environment|WebhookInstallOptions)$'
- '^sigs\.k8s\.io/controller-runtime/pkg/manager\.Options$'
- '^sigs\.k8s\.io/controller-runtime/pkg/reconcile\.Result$'
- '^sigs\.k8s\.io/controller-runtime/pkg/scheme\.Builder$'
- '^github\.com/containerd/cgroups/v3/cgroup2\.(Resources|Memory)'
- '^github\.com/containerd/cgroups/v3/cgroup2\.CPU$'
- '^github\.com/docker/docker/api/types/container\.Config$'
- '^github\.com/docker/docker/api/types\.\w+Options$'
- '^github\.com/opencontainers/runtime-spec/specs-go\.\w+$' # Exempt the entire package. Too many big structs.
- '^github\.com/prometheus/client_golang/prometheus(/.*)?\.\w+Opts$'
- '^github\.com/tychoish/fun/pubsub\.BrokerOptions$'
- '^github\.com/neondatabase/autoscaling/pkg/util/patch\.Operation$'
- '^github\.com/neondatabase/autoscaling/pkg/util/watch\.HandlerFuncs$'
- '^github\.com/vishvananda/netlink\.\w+$' # Exempt the entire package. Too many big structs.
# vmapi.{VirtualMachine,VirtualMachineSpec,VirtualMachineMigration,VirtualMachineMigrationSpec}
- '^github\.com/neondatabase/autoscaling/neonvm/apis/neonvm/v1\.VirtualMachine(Migration)?(Spec)?$'
- '^github\.com/neondatabase/autoscaling/neonvm/apis/neonvm/v1\.IPPool$'
- '^github\.com/neondatabase/autoscaling/pkg/agent/core\.ActionSet$'
- '^github\.com/neondatabase/autoscaling/pkg/util/patch\.Operation$'
- '^github\.com/neondatabase/autoscaling/pkg/util/watch\.HandlerFuncs$'

# see: <https://golangci-lint.run/usage/linters/#gci>
gci:
Expand Down
3 changes: 2 additions & 1 deletion neonvm/apis/neonvm/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ limitations under the License.
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"

"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion neonvm/apis/neonvm/v1/ippool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ type IPPoolList struct {
}

func init() {
SchemeBuilder.Register(&IPPool{}, &IPPoolList{})
SchemeBuilder.Register(&IPPool{}, &IPPoolList{}) //nolint:exhaustruct // just being used to provide the types
}
4 changes: 2 additions & 2 deletions neonvm/apis/neonvm/v1/virtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ const (
)

type Disk struct {
//Disk's name.
// Disk's name.
// Must be a DNS_LABEL and unique within the virtual machine.
Name string `json:"name"`
// Mounted read-only if true, read-write otherwise (false or unspecified).
Expand Down Expand Up @@ -466,5 +466,5 @@ type VirtualMachineList struct {
}

func init() {
SchemeBuilder.Register(&VirtualMachine{}, &VirtualMachineList{})
SchemeBuilder.Register(&VirtualMachine{}, &VirtualMachineList{}) //nolint:exhaustruct // just being used to provide the types
}
3 changes: 2 additions & 1 deletion neonvm/apis/neonvm/v1/virtualmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"fmt"
"reflect"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"k8s.io/apimachinery/pkg/runtime"
)

// log is for logging in this package.
Expand Down
2 changes: 1 addition & 1 deletion neonvm/apis/neonvm/v1/virtualmachinemigration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ type VirtualMachineMigrationList struct {
}

func init() {
SchemeBuilder.Register(&VirtualMachineMigration{}, &VirtualMachineMigrationList{})
SchemeBuilder.Register(&VirtualMachineMigration{}, &VirtualMachineMigrationList{}) //nolint:exhaustruct // just being used to provide the types
}
7 changes: 2 additions & 5 deletions neonvm/apis/neonvm/v1/virtualmachinemigration_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ limitations under the License.
package v1

import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// log is for logging in this package.
var virtualmachinemigrationlog = logf.Log.WithName("virtualmachinemigration-resource")
"k8s.io/apimachinery/pkg/runtime"
)

func (r *VirtualMachineMigration) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
Expand Down
10 changes: 5 additions & 5 deletions neonvm/apis/neonvm/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down
7 changes: 3 additions & 4 deletions neonvm/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"

vmv1 "github.com/neondatabase/autoscaling/neonvm/apis/neonvm/v1"
//+kubebuilder:scaffold:imports
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down
Loading

0 comments on commit 8a91e83

Please sign in to comment.