Skip to content

Commit

Permalink
Update linter and add gimps (#54)
Browse files Browse the repository at this point in the history
* Add golangci-lint configuration

Signed-off-by: Waleed Malik <[email protected]>

* Add gimps configuration

Signed-off-by: Waleed Malik <[email protected]>

* Add pipeline to run gimps

Signed-off-by: Waleed Malik <[email protected]>

* Add .golangci.yml to YAML ignore list

Signed-off-by: Waleed Malik <[email protected]>

* Update dependencies

Signed-off-by: Waleed Malik <[email protected]>

* Add target for verify-imports

Signed-off-by: Waleed Malik <[email protected]>

* Linting and formatting fixes

Signed-off-by: Waleed Malik <[email protected]>

* Fix incorrect script name

Signed-off-by: Waleed Malik <[email protected]>

* Organize imports

Signed-off-by: Waleed Malik <[email protected]>

---------

Signed-off-by: Waleed Malik <[email protected]>
  • Loading branch information
ahmedwaleedmalik authored Sep 25, 2023
1 parent 569ebf9 commit 8eb4100
Show file tree
Hide file tree
Showing 23 changed files with 500 additions and 690 deletions.
26 changes: 26 additions & 0 deletions .gimps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 The KubeLB Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is the configuration for https://github.com/xrstf/gimps.

importOrder: [std, external, kubermatic, envoy, kubernetes]
sets:
- name: kubermatic
patterns:
- "k8c.io/**"
- "github.com/kubermatic/**"
- name: kubernetes
patterns:
- "k8s.io/**"
- "*.k8s.io/**"
77 changes: 77 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2023 The KubeLB Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

run:
deadline: 20m
issues-exit-code: 1
skip-dirs:
- hack
- vendor
skip-files:
- zz_generated.*.go

linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- deadcode
- depguard
- durationcheck
- errcheck
- errname
- errorlint
- exportloopref
- goconst
- gocritic
- gocyclo
- gofmt
- gosimple
- govet
- importas
- ineffassign
- loggercheck
- misspell
- nakedret
- noctx
- nolintlint
- nosprintfhostport
- predeclared
- promlinter
- revive
- staticcheck
- structcheck
- tenv
- typecheck
- unconvert
- unused
- varcheck
- wastedassign
- whitespace
disable-all: true

linters-settings:
goimports:
local-prefixes: k8c.io/kubelb
tagliatelle:
case:
rules:
json: goCamel
yaml: goCamel
depguard:
rules:
main:
deny:
- { pkg: io/ioutil, desc: https://go.dev/doc/go1.16#ioutil }
12 changes: 12 additions & 0 deletions .prow/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ presubmits:
args:
- verify-boilerplate

- name: pull-kubelb-verify-imports
always_run: true
decorate: true
clone_uri: "ssh://[email protected]/kubermatic/kubelb.git"
spec:
containers:
- image: quay.io/kubermatic/build:go-1.21-node-18-kind-0.20-1
command:
- make
args:
- verify-imports

- name: pull-kubelb-build
always_run: true
decorate: true
Expand Down
3 changes: 2 additions & 1 deletion .yamllint.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ rules:
ignore: |
config
dev
vendor
vendor
.golangci.yml
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SHELL = /bin/bash -eu -o pipefail
KUBELB_IMG ?= quay.io/kubermatic/kubelb
KUBELB_CCM_IMG ?= quay.io/kubermatic/kubelb-ccm
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
ENVTEST_K8S_VERSION = 1.28.2

export GOPATH?=$(shell go env GOPATH)
export CGO_ENABLED=0
Expand Down Expand Up @@ -84,6 +84,9 @@ check-dependencies: ## Verify go.mod.
verify-boilerplate: ## Run verify-boilerplate code.
./hack/verify-boilerplate.sh

verify-imports: ## Run verify-imports code.
./hack/verify-import-order.sh

clean: ## Clean binaries
rm -rf bin/*

Expand Down
21 changes: 14 additions & 7 deletions cmd/ccm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"syscall"

"go.uber.org/zap/zapcore"

kubelbk8ciov1alpha1 "k8c.io/kubelb/pkg/api/kubelb.k8c.io/v1alpha1"
"k8c.io/kubelb/pkg/controllers/ccm"
"k8c.io/kubelb/pkg/kubelb"
Expand All @@ -36,8 +37,10 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/tools/clientcmd"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

var (
Expand Down Expand Up @@ -87,11 +90,12 @@ func main() {
setupLog.V(1).Info("cluster", "name", clusterName)

var endpointAddressType corev1.NodeAddressType
if endpointAddressTypeString == string(corev1.NodeInternalIP) {
switch endpointAddressTypeString {
case string(corev1.NodeInternalIP):
endpointAddressType = corev1.NodeInternalIP
} else if endpointAddressTypeString == string(corev1.NodeExternalIP) {
case string(corev1.NodeExternalIP):
endpointAddressType = corev1.NodeExternalIP
} else {
default:
setupLog.Error(errors.New("invalid node address type"), fmt.Sprintf("Expected: %s or %s, got: %s", corev1.NodeInternalIP, corev1.NodeExternalIP, endpointAddressTypeString))
os.Exit(1)
}
Expand Down Expand Up @@ -120,8 +124,12 @@ func main() {
}

kubeLBMgr, err := ctrl.NewManager(kubeLBRestConfig, ctrl.Options{
Scheme: scheme,
Namespace: clusterName,
Scheme: scheme,
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{
clusterName: {},
},
},
})
if err != nil {
setupLog.Error(err, "failed to create manager for kubelb cluster")
Expand All @@ -130,8 +138,7 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Metrics: metricsserver.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "19f32e7b.ccm.kubelb.k8c.io",
Expand Down
7 changes: 4 additions & 3 deletions cmd/kubelb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"go.uber.org/zap/zapcore"

kubelbk8ciov1alpha1 "k8c.io/kubelb/pkg/api/kubelb.k8c.io/v1alpha1"
"k8c.io/kubelb/pkg/controllers/kubelb"
"k8c.io/kubelb/pkg/envoy"
Expand All @@ -33,6 +34,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

type options struct {
Expand Down Expand Up @@ -98,8 +100,7 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: opt.metricsAddr,
Port: 9443,
Metrics: metricsserver.Options{BindAddress: opt.metricsAddr},
HealthProbeBindAddress: opt.probeAddr,
LeaderElection: opt.enableLeaderElection,
LeaderElectionID: "19f32e7b.kubelb.k8c.io",
Expand Down Expand Up @@ -145,7 +146,7 @@ func main() {
EnvoyProxyReplicas: opt.envoyProxyReplicas,
Namespace: opt.namespace,
PortAllocator: portAllocator,
}).SetupWithManager(mgr, ctx); err != nil {
}).SetupWithManager(ctx, mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "LoadBalancer")
os.Exit(1)
}
Expand Down
104 changes: 50 additions & 54 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,81 @@ go 1.21
require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/envoyproxy/go-control-plane v0.11.1
github.com/go-logr/logr v1.2.3
github.com/go-logr/logr v1.2.4
github.com/golang/protobuf v1.5.3
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.19.0
github.com/onsi/gomega v1.27.10
github.com/pkg/errors v0.9.1
google.golang.org/grpc v1.55.0
google.golang.org/protobuf v1.30.0
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/client-go v0.25.0
k8s.io/code-generator v0.25.0
k8s.io/klog/v2 v2.70.1
sigs.k8s.io/controller-runtime v0.13.1
google.golang.org/grpc v1.58.2
google.golang.org/protobuf v1.31.0
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
k8s.io/code-generator v0.28.2
k8s.io/klog/v2 v2.100.1
sigs.k8s.io/controller-runtime v0.16.2
)

require (
cloud.google.com/go/compute v1.19.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cncf/xds/go v0.0.0-20230428030218-4003588d1b74 // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.1 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.8.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e // indirect
golang.org/x/tools v0.13.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
k8s.io/apiextensions-apiserver v0.28.2 // indirect
k8s.io/component-base v0.28.2 // indirect
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect
k8s.io/kube-openapi v0.0.0-20230918164632-68afd615200d // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 8eb4100

Please sign in to comment.