Skip to content

Commit

Permalink
Fix linter issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh Mohan committed Aug 1, 2018
1 parent 40800ea commit 9bf1c3e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static-checks: vendor
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-v $(CURDIR):/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
$(CALICO_BUILD) gometalinter --deadline=300s --disable-all --enable=goimports --vendor pkg/...
$(CALICO_BUILD) gometalinter --deadline=300s --disable-all --enable=vet --enable=errcheck --enable=goimports --vendor pkg/...

.PHONY: fix
## Fix static checks
Expand Down
20 changes: 14 additions & 6 deletions pkg/readiness/bird/bird.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func GRInProgress(ipv string) (bool, error) {
return false, fmt.Errorf("Error querying BIRD: unable to connect to BIRDv%s socket: %v", ipv, err)
}
}
defer c.Close()
defer c.Close() // nolint: errcheck

// To query the current state of the BGP peers, we connect to the BIRD
// socket and send a "show protocols" message. BIRD responds with
Expand All @@ -74,7 +74,9 @@ func GRInProgress(ipv string) (bool, error) {
scanner := bufio.NewScanner(c)

// Set a time-out for reading from the socket connection.
c.SetReadDeadline(time.Now().Add(birdTimeOut))
if e := c.SetReadDeadline(time.Now().Add(birdTimeOut)); e != nil {
return false, e
}

for scanner.Scan() {
// Process the next line that has been read by the scanner.
Expand Down Expand Up @@ -102,7 +104,9 @@ func GRInProgress(ipv string) (bool, error) {

// Before reading the next line, adjust the time-out for
// reading from the socket connection.
c.SetReadDeadline(time.Now().Add(birdTimeOut))
if e := c.SetReadDeadline(time.Now().Add(birdTimeOut)); e != nil {
return false, e
}
}

return false, scanner.Err()
Expand Down Expand Up @@ -136,7 +140,7 @@ func GetPeers(ipv string) ([]bgpPeer, error) {
return nil, fmt.Errorf("Error querying BIRD: unable to connect to BIRDv%s socket: %v", ipv, err)
}
}
defer c.Close()
defer c.Close() // nolint: errcheck

// To query the current state of the BGP peers, we connect to the BIRD
// socket and send a "show protocols" message. BIRD responds with
Expand Down Expand Up @@ -184,7 +188,9 @@ func scanBIRDPeers(ipv string, conn net.Conn) ([]bgpPeer, error) {
peers := []bgpPeer{}

// Set a time-out for reading from the socket connection.
conn.SetReadDeadline(time.Now().Add(birdTimeOut))
if e := conn.SetReadDeadline(time.Now().Add(birdTimeOut)); e != nil {
return nil, e
}

for scanner.Scan() {
// Process the next line that has been read by the scanner.
Expand Down Expand Up @@ -221,7 +227,9 @@ func scanBIRDPeers(ipv string, conn net.Conn) ([]bgpPeer, error) {

// Before reading the next line, adjust the time-out for
// reading from the socket connection.
conn.SetReadDeadline(time.Now().Add(birdTimeOut))
if e := conn.SetReadDeadline(time.Now().Add(birdTimeOut)); e != nil {
return nil, e
}
}

return peers, scanner.Err()
Expand Down
8 changes: 6 additions & 2 deletions pkg/readiness/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ func checkBIRDReady(ipv string) error {

// checkFelixReady checks if felix is ready by making an http request to
// Felix's readiness endpoint.
func checkFelixReady() error {
func checkFelixReady() (err error) {
c := &http.Client{Timeout: 5 * time.Second}
resp, err := c.Get(felixReadinessEp)
if err != nil {
return err
}
defer resp.Body.Close()
defer func() {
if e := resp.Body.Close(); e != nil {
err = e
}
}()

if resp.StatusCode < 200 || resp.StatusCode >= 400 {
return fmt.Errorf("readiness probe reporting %d", resp.StatusCode)
Expand Down
2 changes: 1 addition & 1 deletion pkg/startup/autodetection/reachaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ReachDestination(dest string, version int) (*net.IPNet, error) {
if err != nil {
return nil, err
}
defer conn.Close()
defer conn.Close() // nolint: errcheck

// Get the local address as a golang IP and use that to find the matching
// interface CIDR.
Expand Down
4 changes: 3 additions & 1 deletion pkg/startup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ func ensureDefaultConfig(ctx context.Context, cfg *apiconfig.CalicoAPIConfig, c
// Ensure the ClusterInformation is populated.
// Get the ClusterType from ENV var. This is set from the manifest.
clusterType := os.Getenv("CLUSTER_TYPE")
c.EnsureInitialized(ctx, VERSION, clusterType)
if err := c.EnsureInitialized(ctx, VERSION, clusterType); err != nil {
return nil
}

// By default we set the global reporting interval to 0 - this is
// different from the defaults defined in Felix.
Expand Down
10 changes: 5 additions & 5 deletions pkg/startup/startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ var _ = Describe("FV tests against a real etcd", func() {
}
},

Entry("valid single k8s env var", []EnvItem{{"CALICO_K8S_NODE_REF", "node1"}}, api.OrchRef{"node1", "k8s"}, true),
Entry("valid single k8s env var", []EnvItem{{"CALICO_K8S_NODE_REF", "node1"}}, api.OrchRef{"node1", "k8s"}, true), // nolint: vet
)

It("Should not configure any OrchRefs when no valid env vars are passed", func() {
Expand All @@ -769,7 +769,7 @@ var _ = Describe("FV tests against a real etcd", func() {
os.Setenv("CALICO_K8S_NODE_REF", "node1")

node := &api.Node{}
node.Spec.OrchRefs = append(node.Spec.OrchRefs, api.OrchRef{"node1", "k8s"})
node.Spec.OrchRefs = append(node.Spec.OrchRefs, api.OrchRef{"node1", "k8s"}) // nolint: vet
configureNodeRef(node)

Expect(node.Spec.OrchRefs).To(HaveLen(1))
Expand Down Expand Up @@ -868,13 +868,13 @@ var _ = Describe("FV tests against K8s API server.", func() {
errors := []error{}
for _, node := range nodes.Items {
wg.Add(1)
go func() {
go func(n api.Node) {
defer wg.Done()
err = ensureDefaultConfig(ctx, cfg, c, &node)
err = ensureDefaultConfig(ctx, cfg, c, &n)
if err != nil {
errors = append(errors, err)
}
}()
}(node)
}

wg.Wait()
Expand Down

0 comments on commit 9bf1c3e

Please sign in to comment.