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

Add Build/Test/Lint/go mod/vendor consistency workflow #328

Merged
merged 16 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
94 changes: 94 additions & 0 deletions .github/workflows/build-test-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: build-test-lint
on: [push, pull_request]
jobs:
build:
name: build
strategy:
matrix:
go-version: [1.13.x, 1.14.x, 1.15.x, 1.16.x]
goarch: [amd64]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
env:
GOARCH: ${{ matrix.goarch }}
GOOS: ${{ matrix.goos }}
run: make build
test:
runs-on: ubuntu-latest
needs: build
name: test
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.16.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Install hwdata
run: sudo apt-get install hwdata -y

- name: Go test
run: make test

golangci:
name: Golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.37
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
ignore: vendor

hadolint:
runs-on: ubuntu-latest
name: Hadolint
steps:
- uses: actions/checkout@v2
- uses: brpaz/hadolint-action@v1.2.1
Copy link
Contributor

@adrianchiris adrianchiris Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just ignore DL3018 for now ?
alternative is to just fix the packages we install to whatever is being installed today.
(this has its downside though...)

Copy link
Member Author

@martinkennelly martinkennelly Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should ignore it because it will reduce the need for a discussion and outcome. I will create an issue following this PR to get consensus for this issue. We may just want to ignore it..

Pros for setting it to a version:
We get a version we know that works - more deterministic.
Cons for settings it to a version:
We need to update the version before its no longer available in the package managers repo or it will break our builds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes +1 on opening an issue and meanwhile ignore so check passes with current state of things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Ignored following community response on the issue.

name: Run Hadolint
with:
dockerfile: ./images/Dockerfile
- uses: brpaz/hadolint-action@v1.2.1
with:
dockerfile: Dockerfile.rhel7

go-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

# if this fails, run go mod tidy
- name: Check if module files are consistent with code
run: go mod tidy && git diff --exit-code

# if this fails, run go mod vendor
- name: Check if vendor directory is consistent with go modules
run: go mod vendor && git diff --exit-code
113 changes: 113 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Tested with golangci-lint ver. 1.37
linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- unnamedResult
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/k8snetworkplumbingwg/sriov-network-device-plugin
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
lll:
line-length: 140
misspell:
locale: US
prealloc:
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- funlen
#- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
#- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- rowserrcheck
#- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- gosec
- dupl
- lll
- stylecheck
- goconst

run:
skip-dirs:
- vendor/
- .github/
- deployments/
- docs/
- images/
9 changes: 4 additions & 5 deletions cmd/sriovdp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ func main() {
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

// Catch termination signals
select {
case sig := <-sigCh:
glog.Infof("Received signal \"%v\", shutting down.", sig)
rm.stopAllServers()
return
sig := <-sigCh
glog.Infof("Received signal \"%v\", shutting down.", sig)
if err := rm.stopAllServers(); err != nil {
glog.Errorf("stopping servers produced error: %s", err.Error())
}
}
19 changes: 7 additions & 12 deletions cmd/sriovdp/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ func newResourceManager(cp *cliParams) *resourceManager {
}
}

//readConfig reads and validate configurations from Config file
// readConfig reads and validate configurations from Config file
func (rm *resourceManager) readConfig() error {

resources := &types.ResourceConfList{}
rawBytes, err := ioutil.ReadFile(rm.configFile)

if err != nil {
return fmt.Errorf("error reading file %s, %v", rm.configFile, err)

}

glog.Infof("raw ResourceList: %s", rawBytes)
Expand All @@ -89,19 +87,15 @@ func (rm *resourceManager) readConfig() error {
// Validate deviceType
if conf.DeviceType == "" {
conf.DeviceType = types.NetDeviceType // Default to NetDeviceType
} else {
// Check if the DeviceType is supported
if _, ok := types.SupportedDevices[conf.DeviceType]; !ok {
return fmt.Errorf("unsupported deviceType: \"%s\"", conf.DeviceType)
}
} else if _, ok := types.SupportedDevices[conf.DeviceType]; !ok {
return fmt.Errorf("unsupported deviceType: \"%s\"", conf.DeviceType)
}
if conf.SelectorObj, err = rm.rFactory.GetDeviceFilter(conf); err == nil {
rm.configList = append(rm.configList, &resources.ResourceList[i])
} else {
glog.Warningf("unable to get SelectorObj from selectors list:'%s' for deviceType: %s error: %s",
*conf.Selectors, conf.DeviceType, err)
}

}
glog.Infof("unmarshalled ResourceList: %+v", resources.ResourceList)
return nil
Expand Down Expand Up @@ -182,7 +176,7 @@ func (rm *resourceManager) validConfigs() bool {
return false
}

// resourcePrefix might be overriden for a given resource pool
// resourcePrefix might be overridden for a given resource pool
resourcePrefix := rm.cliParams.resourcePrefix
if conf.ResourcePrefix != "" {
resourcePrefix = conf.ResourcePrefix
Expand Down Expand Up @@ -212,7 +206,6 @@ func (rm *resourceManager) validConfigs() bool {
}

func (rm *resourceManager) discoverHostDevices() error {

pci, err := ghw.PCI()
if err != nil {
return fmt.Errorf("discoverDevices(): error getting PCI info: %v", err)
Expand All @@ -225,7 +218,9 @@ func (rm *resourceManager) discoverHostDevices() error {

for k, v := range types.SupportedDevices {
if dp, ok := rm.deviceProviders[k]; ok {
dp.AddTargetDevices(devices, v)
if err := dp.AddTargetDevices(devices, v); err != nil {
glog.Errorf("adding supported device identifier '%d' to device provider failed: %s", v, err.Error())
}
}
}
return nil
Expand Down
24 changes: 9 additions & 15 deletions cmd/sriovdp/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ func TestSriovdp(t *testing.T) {
RunSpecs(t, "Sriovdp Suite")
}

func assertShouldFail(err error, shouldFail bool) {
if shouldFail {
Expect(err).To(HaveOccurred())
} else {
Expect(err).NotTo(HaveOccurred())
}
}

var _ = Describe("Resource manager", func() {
var (
cp *cliParams
Expand All @@ -60,7 +52,7 @@ var _ = Describe("Resource manager", func() {
})
Context("when there's an error reading file", func() {
BeforeEach(func() {
os.RemoveAll("/tmp/sriovdp")
_ = os.RemoveAll("/tmp/sriovdp")
})
It("should fail", func() {
err := rm.readConfig()
Expand All @@ -73,7 +65,7 @@ var _ = Describe("Resource manager", func() {
if err != nil {
panic(err)
}
ioutil.WriteFile("/tmp/sriovdp/test_config", []byte("junk"), 0644)
_ = ioutil.WriteFile("/tmp/sriovdp/test_config", []byte("junk"), 0644)
})
AfterEach(func() {
err := os.RemoveAll("/tmp/sriovdp")
Expand Down Expand Up @@ -181,7 +173,7 @@ var _ = Describe("Resource manager", func() {
if err != nil {
panic(err)
}
rm.readConfig()
_ = rm.readConfig()
})
It("should return false", func() {
defer fs.Use()()
Expand Down Expand Up @@ -215,7 +207,7 @@ var _ = Describe("Resource manager", func() {
if err != nil {
panic(err)
}
rm.readConfig()
_ = rm.readConfig()
})
It("should return false", func() {
defer fs.Use()()
Expand Down Expand Up @@ -292,15 +284,17 @@ var _ = Describe("Resource manager", func() {
DescribeTable("discovering devices",
func(fs *utils.FakeFilesystem) {
defer fs.Use()()
os.Setenv("GHW_CHROOT", fs.RootDir)
defer os.Unsetenv("GHW_CHROOT")
_ = os.Setenv("GHW_CHROOT", fs.RootDir)
defer func() {
_ = os.Unsetenv("GHW_CHROOT")
}()

rf := factory.NewResourceFactory("fake", "fake", true)

rm := &resourceManager{
rFactory: rf,
configList: []*types.ResourceConfig{
&types.ResourceConfig{
{
ResourceName: "fake",
DeviceType: types.NetDeviceType,
},
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.5.1
github.com/vishvananda/netlink v1.1.0
golang.org/x/net v0.0.0-20201021035429-f5854403a974
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
google.golang.org/grpc v1.28.1
k8s.io/kubelet v0.18.1
)
Expand Down
10 changes: 7 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
Expand All @@ -215,8 +216,11 @@ golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
Loading