Skip to content

Commit

Permalink
[testing] run go linters (#943)
Browse files Browse the repository at this point in the history
* run go linters for static code checking

* fix(lint): fix all goimports linting errors

* fix(lint): fix all golint errors

* fix(lint): fix all spelling errors

Co-authored-by: Aaron U'Ren <aauren@gmail.com>
  • Loading branch information
murali-reddy and aauren committed Jul 28, 2020
1 parent 3e33a9c commit a33089d
Show file tree
Hide file tree
Showing 17 changed files with 299 additions and 275 deletions.
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
run:
timeout: 5m
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gofmt
- goimports
- golint
- gosimple
- govet
- ineffassign
- misspell
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
output:
format: tab
print-issued-lines: true
print-linter-name: true
3 changes: 2 additions & 1 deletion pkg/cmd/kube-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (
"github.com/cloudnativelabs/kube-router/pkg/options"
"github.com/golang/glog"

"time"

"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"time"
)

// These get set at build time via -ldflags magic
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/netpol/namespace.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package netpol

import (
"reflect"

"github.com/golang/glog"
api "k8s.io/api/core/v1"
"k8s.io/client-go/tools/cache"
"reflect"
)

func (npc *NetworkPolicyController) newNamespaceEventHandler() cache.ResourceEventHandler {
Expand Down
217 changes: 109 additions & 108 deletions pkg/controllers/netpol/network_policy_controller.go

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions pkg/controllers/netpol/network_policy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package netpol

import (
"context"
netv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/tools/cache"
"net"
"strings"
"testing"
"time"

netv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/tools/cache"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -146,15 +147,15 @@ func tCreateFakePods(t *testing.T, podInformer cache.SharedIndexInformer, nsInfo
{name: "nsC", labels: labels.Set{"name": "c"}},
{name: "nsD", labels: labels.Set{"name": "d"}},
}
ips_used := make(map[string]bool)
ipsUsed := make(map[string]bool)
for _, pod := range pods {
podNamespaceMap.addPod(pod)
ipaddr := "1.1." + pod.ip
if ips_used[ipaddr] {
if ipsUsed[ipaddr] {
t.Fatalf("there is another pod with the same Ip address %s as this pod %s namespace %s",
ipaddr, pod.name, pod.name)
}
ips_used[ipaddr] = true
ipsUsed[ipaddr] = true
tAddToInformerStore(t, podInformer,
&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: pod.name, Labels: pod.labels, Namespace: pod.namespace},
Status: v1.PodStatus{PodIP: ipaddr}})
Expand Down
Loading

0 comments on commit a33089d

Please sign in to comment.