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

[CI Enhancement] Add gci linter check #694

Merged
merged 1 commit into from
Dec 24, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
version: ${{ env.GOLANGCI_VERSION }}
args: --disable-all -E deadcode -E gofmt -E goimports -E ineffassign -E misspell -E vet --timeout=15m
args: -v

markdownlint-misspell-shellcheck:
runs-on: ubuntu-18.04
Expand Down
47 changes: 47 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 15m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
# default is "colored-line-number"
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

# make issues output unique by line, default is true
uniq-by-line: true

# all available settings of specific linters
linters-settings:
gci:
local-prefixes: github.com/openyurtio

linters:
disable-all: true
enable:
- deadcode
- gofmt
- goimports
- gci
- ineffassign
- misspell
- vet
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ GOLINT_BIN=$(shell which golangci-lint)
endif

lint: install-golint ## Run go lint against code.
$(GOLINT_BIN) run --disable-all -E deadcode -E gofmt -E goimports -E ineffassign -E misspell -E vet --timeout=15m
$(GOLINT_BIN) run -v
2 changes: 2 additions & 0 deletions cmd/yurt-controller-manager/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import (
"time"

"k8s.io/component-base/logs"

// load all the prometheus client-go plugin
_ "k8s.io/component-base/metrics/prometheus/clientgo"

// for version metric registration
_ "k8s.io/component-base/metrics/prometheus/version"

Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-tunnel-agent/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package config
import (
"fmt"

"k8s.io/client-go/kubernetes"

"github.com/openyurtio/openyurt/pkg/projectinfo"
"github.com/openyurtio/openyurt/pkg/yurttunnel/constants"

"k8s.io/client-go/kubernetes"
)

// Config is the main context object for yurttunel-agent
Expand Down
6 changes: 3 additions & 3 deletions cmd/yurt-tunnel-server/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"fmt"
"net"

"github.com/openyurtio/openyurt/pkg/projectinfo"
"github.com/openyurtio/openyurt/pkg/yurttunnel/constants"

"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"

"github.com/openyurtio/openyurt/pkg/projectinfo"
"github.com/openyurtio/openyurt/pkg/yurttunnel/constants"
)

// Config is the main context object for yurttunel-server
Expand Down
8 changes: 4 additions & 4 deletions cmd/yurthub/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import (
"strings"
"time"

yurtcorev1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/apis/apps/v1alpha1"
yurtclientset "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned"
yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions"
yurtv1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions/apps/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand All @@ -51,6 +47,10 @@ import (
"github.com/openyurtio/openyurt/pkg/yurthub/kubernetes/serializer"
"github.com/openyurtio/openyurt/pkg/yurthub/storage/factory"
"github.com/openyurtio/openyurt/pkg/yurthub/util"
yurtcorev1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/apis/apps/v1alpha1"
yurtclientset "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/clientset/versioned"
yurtinformers "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions"
yurtv1alpha1 "github.com/openyurtio/yurt-app-manager-api/pkg/yurtappmanager/client/informers/externalversions/apps/v1alpha1"
)

// YurtHubConfiguration represents configuration of yurthub
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/certificates/csrapprover.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
certinformer "k8s.io/client-go/informers/certificates/v1beta1"
certv1beta1 "k8s.io/client-go/informers/certificates/v1beta1"
"k8s.io/client-go/kubernetes"
typev1beta1 "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
Expand Down Expand Up @@ -138,7 +137,7 @@ func enqueueObj(wq workqueue.RateLimitingInterface, obj interface{}) {
// NewCSRApprover creates a new YurtCSRApprover
func NewCSRApprover(
clientset kubernetes.Interface,
csrInformer certinformer.CertificateSigningRequestInformer) *YurtCSRApprover {
csrInformer certv1beta1.CertificateSigningRequestInformer) *YurtCSRApprover {

wq := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())
csrInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import (
"k8s.io/apiserver/pkg/server/routes"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/component-base/metrics/legacyregistry"
_ "k8s.io/component-base/metrics/prometheus/workqueue" // for workqueue metric registration

// for workqueue metric registration
_ "k8s.io/component-base/metrics/prometheus/workqueue"
)

var (
Expand Down
1 change: 0 additions & 1 deletion pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"

batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtctl/cmd/join/phases/join-edge-node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -45,7 +46,6 @@ import (
"github.com/openyurtio/openyurt/pkg/yurtctl/constants"
"github.com/openyurtio/openyurt/pkg/yurtctl/util/edgenode"
"github.com/openyurtio/openyurt/pkg/yurthub/util"
"github.com/pkg/errors"
)

// NewEdgeNodePhase creates a yurtctl workflow phase that start kubelet on a edge node.
Expand Down
7 changes: 3 additions & 4 deletions pkg/yurtctl/util/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -154,7 +153,7 @@ func CreateConfigMapFromYaml(cliSet *kubernetes.Clientset, ns, cmTmpl string) er
if err != nil {
return err
}
cm, ok := obj.(*v1.ConfigMap)
cm, ok := obj.(*corev1.ConfigMap)
if !ok {
return fmt.Errorf("fail to assert configmap: %v", err)
}
Expand Down Expand Up @@ -434,7 +433,7 @@ func YamlToObject(yamlContent []byte) (k8sruntime.Object, error) {
}

// LabelNode add a new label (<key>=<val>) to the given node
func LabelNode(cliSet *kubernetes.Clientset, node *v1.Node, key, val string) (*v1.Node, error) {
func LabelNode(cliSet *kubernetes.Clientset, node *corev1.Node, key, val string) (*corev1.Node, error) {
node.Labels[key] = val
newNode, err := cliSet.CoreV1().Nodes().Update(context.Background(), node, metav1.UpdateOptions{})
if err != nil {
Expand All @@ -444,7 +443,7 @@ func LabelNode(cliSet *kubernetes.Clientset, node *v1.Node, key, val string) (*v
}

// AnnotateNode add a new annotation (<key>=<val>) to the given node
func AnnotateNode(cliSet *kubernetes.Clientset, node *v1.Node, key, val string) (*v1.Node, error) {
func AnnotateNode(cliSet *kubernetes.Clientset, node *corev1.Node, key, val string) (*corev1.Node, error) {
node.Annotations[key] = val
newNode, err := cliSet.CoreV1().Nodes().Update(context.Background(), node, metav1.UpdateOptions{})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/yurthub/network/dummyif_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
"net"
"strings"

"k8s.io/klog/v2"

"github.com/vishvananda/netlink"
"k8s.io/klog/v2"
)

type DummyInterfaceController interface {
Expand Down
7 changes: 3 additions & 4 deletions pkg/yurttunnel/handlerwrapper/localhostproxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"time"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers"
Expand Down Expand Up @@ -125,15 +124,15 @@ func (plm *localHostProxyMiddleware) SetSharedInformerFactory(factory informers.
return err
}

plm.getNodesByIP = func(nodeIP string) ([]*v1.Node, error) {
plm.getNodesByIP = func(nodeIP string) ([]*corev1.Node, error) {
objs, err := nodeInformer.Informer().GetIndexer().ByIndex(constants.NodeIPKeyIndex, nodeIP)
if err != nil {
return nil, err
}

nodes := make([]*v1.Node, 0, len(objs))
nodes := make([]*corev1.Node, 0, len(objs))
for _, obj := range objs {
if node, ok := obj.(*v1.Node); ok {
if node, ok := obj.(*corev1.Node); ok {
nodes = append(nodes, node)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/yurttunnel/server/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"sync"
"time"

"github.com/openyurtio/openyurt/pkg/yurttunnel/constants"

"k8s.io/apimachinery/pkg/util/httpstream"
"k8s.io/apiserver/pkg/util/flushwriter"
"k8s.io/apiserver/pkg/util/wsstream"
"k8s.io/klog/v2"

"github.com/openyurtio/openyurt/pkg/yurttunnel/constants"
)

var (
Expand Down
21 changes: 10 additions & 11 deletions pkg/yurttunnel/server/serveraddr/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/informers"
Expand Down Expand Up @@ -51,7 +50,7 @@ func GetTunnelServerAddr(clientset kubernetes.Interface) (string, error) {
return "", err
}

dnsNames, ips, err := extractTunnelServerDNSandIPs(svc, []*v1.Endpoints{eps}, NodeListToNodes(nodeLst))
dnsNames, ips, err := extractTunnelServerDNSandIPs(svc, []*corev1.Endpoints{eps}, NodeListToNodes(nodeLst))
if err != nil {
return "", err
}
Expand Down Expand Up @@ -106,7 +105,7 @@ func GetYurttunelServerDNSandIP(
return []string{}, []net.IP{}, err
}

return extractTunnelServerDNSandIPs(svc, []*v1.Endpoints{eps}, NodeListToNodes(nodeLst))
return extractTunnelServerDNSandIPs(svc, []*corev1.Endpoints{eps}, NodeListToNodes(nodeLst))
}

// YurttunelServerAddrManager list the latest tunnel server resources, extract ips and dnsNames from them
Expand Down Expand Up @@ -165,11 +164,11 @@ func YurttunnelServerAddrManager(factory informers.SharedInformerFactory) ([]str
}

// getTunnelServerResources get service, endpoints, and cloud nodes of tunnel server
func getTunnelServerResources(clientset kubernetes.Interface) (*v1.Service, *v1.Endpoints, *v1.NodeList, error) {
func getTunnelServerResources(clientset kubernetes.Interface) (*corev1.Service, *corev1.Endpoints, *corev1.NodeList, error) {
var (
svc *v1.Service
eps *v1.Endpoints
nodeLst *v1.NodeList
svc *corev1.Service
eps *corev1.Endpoints
nodeLst *corev1.NodeList
err error
)
// get x-tunnel-server-svc service
Expand Down Expand Up @@ -202,7 +201,7 @@ func getTunnelServerResources(clientset kubernetes.Interface) (*v1.Service, *v1.
}

// extractTunnelServerDNSandIPs extract tunnel server dnsNames and ips from service and endpoints
func extractTunnelServerDNSandIPs(svc *v1.Service, eps []*v1.Endpoints, nodes []*v1.Node) ([]string, []net.IP, error) {
func extractTunnelServerDNSandIPs(svc *corev1.Service, eps []*corev1.Endpoints, nodes []*corev1.Node) ([]string, []net.IP, error) {
var (
dnsNames = make([]string, 0)
ips = make([]net.IP, 0)
Expand Down Expand Up @@ -304,7 +303,7 @@ func getDNSandIPFromAnnotations(svc *corev1.Service) ([]string, []net.IP, error)
}

// getClusterIPDNSandIP gets the DNS names and IPs from the NodePort service
func getNodePortDNSandIP(nodes []*v1.Node) ([]string, []net.IP, error) {
func getNodePortDNSandIP(nodes []*corev1.Node) ([]string, []net.IP, error) {
var (
dnsNames = make([]string, 0)
ips = make([]net.IP, 0)
Expand Down Expand Up @@ -350,8 +349,8 @@ func GetDefaultDomainsForSvc(ns, name string) []string {
return domains
}

func NodeListToNodes(nodeLst *v1.NodeList) []*v1.Node {
nodes := make([]*v1.Node, 0)
func NodeListToNodes(nodeLst *corev1.NodeList) []*corev1.Node {
nodes := make([]*corev1.Node, 0)
for _, node := range nodeLst.Items {
nodes = append(nodes, &node)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurttunnel/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"

"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus/promhttp"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -33,7 +34,6 @@ import (

"github.com/openyurtio/openyurt/pkg/profile"
"github.com/openyurtio/openyurt/pkg/projectinfo"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

const (
Expand Down