Skip to content

Commit

Permalink
Fix linter issues, add Makefile targets, add CI jobs (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas authored Aug 3, 2021
1 parent 692753c commit fc668b9
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 78 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Go
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
# test:
# runs-on: [ubuntu-latest]
# steps:
# - name: Set up Go 1.15
# uses: actions/setup-go@v1
# with:
# go-version: 1.15
# - name: Check-out code
# uses: actions/checkout@v2
# - name: Run unit tests
# run: |
# make test

tidy:
runs-on: [ubuntu-latest]
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.15
- name: Check-out code
uses: actions/checkout@v2
- name: Check tidiness
run: |
./ci/check-tidy.sh
golangci:
runs-on: [ubuntu-latest]
steps:
- name: Check-out code
uses: actions/checkout@v2
- name: Run code linters
run: |
make golangci
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release
on:
push:
branches:
- main
paths:
- 'VERSION'

jobs:
release:
runs-on: [ubuntu-latest]
steps:
- name: Check-out code
uses: actions/checkout@v2
- name: Read version
run: |
echo "version=$(head VERSION)" >> $GITHUB_ENV
- name: Create release
uses: ncipollo/release-action@v1
with:
omitBody: true
token: "${{ secrets.GITHUB_TOKEN }}"
tag: "${{ env.version }}"
commit: "${{ env.GITHUB_SHA }}"
16 changes: 13 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# vagrant
.vagrant
cscope*
.cache
.golangci-bin

.DS_Store

# VIM
.*.swp

# Emacs
*~

.idea/
.vscode/
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
run:
tests: true
timeout: 5m
skip-files:
- ".*\\.pb\\.go"
skip-dirs-use-default: true

linters-settings:
goimports:
local-prefixes: antrea.io/ofnet

linters:
disable-all: true
enable: # see https://golangci-lint.run/usage/linters/
- deadcode
- staticcheck
- govet
- gofmt
- goimports
- gosec
- misspell

run:
deadline: 5m
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# TODO
GO ?= go

all: test

.PHONY: test
test:
$(GO) test -v ./...

# code linting
.golangci-bin:
@echo "===> Installing Golangci-lint <==="
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.41.1

.PHONY: golangci
golangci: .golangci-bin
@echo "===> Running golangci <==="
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci.yml

.PHONY: golangci-fix
golangci-fix: .golangci-bin
@echo "===> Running golangci-fix <==="
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci.yml --fix
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.0
22 changes: 22 additions & 0 deletions ci/check-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

: "${GO:=go}"

goversion=$($GO version)

$GO mod tidy

rc=0
diff=$(git diff --exit-code -- go.mod go.sum) || rc=$?

if [ $rc -ne 0 ]; then
echo "Found some differences when running 'go mod tidy'"
echo "**********"
echo "$diff"
echo "**********"
echo "Please ensure you are using the correct version of go ($goversion), run 'go mod tidy', and commit the changes"
fi

exit $rc
2 changes: 1 addition & 1 deletion ofctrl/fgraphFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"encoding/json"
"errors"
"fmt"
"antrea.io/libOpenflow/util"
"net"
"sync"

"antrea.io/libOpenflow/openflow13"
"antrea.io/libOpenflow/util"
log "github.com/sirupsen/logrus"
)

Expand Down
1 change: 1 addition & 0 deletions ofctrl/ofErrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ofctrl

import (
"fmt"

"antrea.io/libOpenflow/openflow13"
"antrea.io/libOpenflow/util"
)
Expand Down
7 changes: 4 additions & 3 deletions ofctrl/ofMatchFields.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/binary"
"errors"
"fmt"
"net"

"antrea.io/libOpenflow/openflow13"
"antrea.io/libOpenflow/util"
"net"
)

type Uint32WithMask struct {
Expand Down Expand Up @@ -749,7 +750,7 @@ func GetUint32ValueWithRangeFromBytes(data []byte, rng *openflow13.NXRange) (uin
}
startByte := int(rng.GetOfs() / 8)
startDiff := startByte * 8
endByte := int(rng.GetNbits() + 7/8)
endByte := int((rng.GetNbits() + 7) / 8)
if endByte > len(data) {
return 0, errors.New("range is larger than data length")
}
Expand All @@ -765,7 +766,7 @@ func GetUint64ValueWithRangeFromBytes(data []byte, rng *openflow13.NXRange) (uin
}
startByte := int(rng.GetOfs() / 8)
startDiff := startByte * 8
endByte := int(rng.GetNbits() + 7/8)
endByte := int((rng.GetNbits() + 7) / 8)
if endByte > len(data) {
return 0, errors.New("range is larger than data length")
}
Expand Down
13 changes: 7 additions & 6 deletions ofctrl/ofPacket.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// #nosec G404: random number generator not used for security purposes
package ofctrl

import (
Expand Down Expand Up @@ -103,12 +104,12 @@ func GenerateTCPPacket(srcMAC, dstMAC net.HardwareAddr, srcIP, dstIP net.IP, dst
var pktOut *PacketOut
if srcIP.To4() == nil {
ipv6Header := &protocol.IPv6{
Version: 6,
Length: tcpHeader.Len(),
HopLimit: 64,
NextHeader: protocol.Type_TCP,
NWSrc: srcIP,
NWDst: dstIP,
Version: 6,
Length: tcpHeader.Len(),
HopLimit: 64,
NextHeader: protocol.Type_TCP,
NWSrc: srcIP,
NWDst: dstIP,
}
pktOut = &PacketOut{
SrcMAC: srcMAC,
Expand Down
5 changes: 3 additions & 2 deletions ofctrl/ofctrl.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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.
*/

package ofctrl

// This library implements a simple openflow 1.3 controller
Expand Down Expand Up @@ -91,7 +92,7 @@ type Controller struct {
func NewController(app AppInterface) *Controller {
c := new(Controller)
c.connectMode = ServerMode
c.id = uint16(rand.Uint32())
c.id = uint16(rand.Uint32()) // #nosec G404: random number generator not used for security purposes

// for debug logs
// log.SetLevel(log.DebugLevel)
Expand Down Expand Up @@ -261,7 +262,7 @@ func (c *Controller) handleConnection(conn net.Conn) {
switch m := msg.(type) {
// A Hello message of the appropriate type
// completes version negotiation. If version
// types are incompatable, it is possible the
// types are incompatible, it is possible the
// connection may be servered without error.
case *common.Hello:
if m.Version == openflow13.VERSION {
Expand Down
Loading

0 comments on commit fc668b9

Please sign in to comment.