Skip to content

Commit a61fdc5

Browse files
committed
Added linting step in makefile using gometalinter and fixed linting errors.
1 parent afd53d2 commit a61fdc5

14 files changed

Lines changed: 52 additions & 23 deletions

File tree

build/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ build-images: build-controller-image build-agones-sdk-image
9898
build-sdks: build-sdk-cpp
9999

100100
# Run all tests
101-
test: ensure-build-image test-go test-install-yaml
101+
test: ensure-build-image lint test-go test-install-yaml
102102

103103
# Run go tests
104104
test-go:
@@ -131,6 +131,11 @@ build-controller-binary: ensure-build-image
131131
docker run --rm -e "CGO_ENABLED=0" $(common_mounts) $(build_tag) go build \
132132
-o $(mount_path)/cmd/controller/bin/controller -a $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/controller
133133

134+
# Lint the go source code.
135+
lint: ensure-build-image
136+
docker run --rm $(common_mounts) -w $(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) bash -c \
137+
"/root/gen-lint-exclude.sh && gometalinter --config .exclude.gometalinter.json --deadline 100s -t --skip vendor ./..."
138+
134139
# Build the image for the gameserver controller
135140
build-controller-image: ensure-build-image build-controller-binary
136141
docker build $(agones_path)/cmd/controller/ --tag=$(controller_tag) $(DOCKER_BUILD_ARGS)

build/build-image/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# ForceUpdate 2 -- change here if you need to force a rebuild
15+
# ForceUpdate 3 -- change here if you need to force a rebuild
1616

1717
# compiling proto + grpc takes an exceptionally long time
1818
# so we'll use that as the base.
1919
FROM grpc/cxx:1.8
2020

2121
RUN apt-get update && \
22-
apt-get install -y wget rsync make python bash-completion zip && \
22+
apt-get install -y wget rsync make python bash-completion zip jq && \
2323
apt-get clean
2424

2525
# install go
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
excluded=$(find . -name "*.go" | grep -v vendor | xargs grep autogenerated | cut -d ':' -f 1 | uniq | sed 's#\./##g')
18+
jq -n --arg inarjq -n --arg inarr "${excluded}" '{ Exclude: ($inarr | split("\n")) }' > .exclude.gometalinter.json

cmd/controller/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var (
5656
)
5757

5858
// main starts the operator for the gameserver CRD
59-
func main() {
59+
func main() { // nolint: gocyclo
6060
exec, err := os.Executable()
6161
if err != nil {
6262
logger.WithError(err).Fatal("Could not get executable path")

examples/simple-udp/server/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// main starts a UDP server that received 1024 byte sized packets at at time
3131
// converts the bytes to a string, and logs the output
32-
func main() {
32+
func main() { // nolint: gocyclo
3333
port := flag.String("port", "7654", "The port to listen to udp traffic on")
3434
flag.Parse()
3535
if ep := os.Getenv("PORT"); ep != "" {
@@ -41,7 +41,7 @@ func main() {
4141
if err != nil {
4242
log.Fatalf("Could not start udp server: %v", err)
4343
}
44-
defer conn.Close()
44+
defer conn.Close() // nolint: errcheck
4545

4646
log.Print("Creating SDK instance")
4747
s, err := sdk.NewSDK()
@@ -79,12 +79,10 @@ func main() {
7979
log.Printf("Could not shutdown")
8080
}
8181
os.Exit(0)
82-
break
8382

8483
// turns off the health pings
8584
case "UNHEALTHY":
8685
close(stop)
87-
break
8886
}
8987

9088
// echo it back

pkg/apis/stable/v1alpha1/fleet.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
)
2121

2222
const (
23+
// FleetGameServerSetLabel is the label that the name of the Fleet
24+
// is set to on the GameServerSet the Fleet controls
2325
FleetGameServerSetLabel = stable.GroupName + "/fleet"
2426
)
2527

@@ -62,7 +64,7 @@ type FleetStatus struct {
6264
ReadyReplicas int32 `json:"readyReplicas"`
6365
}
6466

65-
// Fleet returns a single GameServerSet for this Fleet definition
67+
// GameServerSet returns a single GameServerSet for this Fleet definition
6668
func (f *Fleet) GameServerSet() *GameServerSet {
6769
gsSet := &GameServerSet{
6870
ObjectMeta: *f.Spec.Template.ObjectMeta.DeepCopy(),

pkg/gameservers/helper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func testHTTPHealth(t *testing.T, url string, expectedResponse string, expectedS
100100

101101
assert.NotNil(t, resp)
102102
if resp != nil {
103-
defer resp.Body.Close()
103+
defer resp.Body.Close() // nolint: errcheck
104104
body, err := ioutil.ReadAll(resp.Body)
105105
assert.Nil(t, err, "(%s) read response error should be nil: %v", url, err)
106106
assert.Equal(t, expectedStatus, resp.StatusCode, "url: %s", url)

pkg/gameservers/sdkserver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ func TestSidecarRun(t *testing.T) {
4141
"ready": {
4242
state: v1alpha1.RequestReady,
4343
f: func(sc *SDKServer, ctx context.Context) {
44-
sc.Ready(ctx, &sdk.Empty{})
44+
sc.Ready(ctx, &sdk.Empty{}) // nolint: errcheck
4545
},
4646
},
4747
"shutdown": {
4848
state: v1alpha1.Shutdown,
4949
f: func(sc *SDKServer, ctx context.Context) {
50-
sc.Shutdown(ctx, &sdk.Empty{})
50+
sc.Shutdown(ctx, &sdk.Empty{}) // nolint: errcheck
5151
},
5252
},
5353
"unhealthy": {

pkg/gameserversets/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestSyncGameServerSet(t *testing.T) {
159159
_, cancel := agtesting.StartInformers(m, c.gameServerSetSynced, c.gameServerSynced)
160160
defer cancel()
161161

162-
c.syncGameServerSet(gsSet.ObjectMeta.Namespace + "/" + gsSet.ObjectMeta.Name)
162+
c.syncGameServerSet(gsSet.ObjectMeta.Namespace + "/" + gsSet.ObjectMeta.Name) // nolint: errcheck
163163

164164
assert.Equal(t, 5, count)
165165
assert.True(t, deleted, "A game servers should have been deleted")
@@ -185,7 +185,7 @@ func TestSyncGameServerSet(t *testing.T) {
185185
_, cancel := agtesting.StartInformers(m, c.gameServerSetSynced, c.gameServerSynced)
186186
defer cancel()
187187

188-
c.syncGameServerSet(gsSet.ObjectMeta.Namespace + "/" + gsSet.ObjectMeta.Name)
188+
c.syncGameServerSet(gsSet.ObjectMeta.Namespace + "/" + gsSet.ObjectMeta.Name) // nolint: errcheck
189189

190190
assert.Equal(t, 5, count)
191191
})

pkg/gameserversets/helper_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ import (
2828
)
2929

3030
// holder for all my fakes and mocks
31-
type mocks struct {
31+
type mocks struct { // nolint: megacheck
3232
kubeClient *kubefake.Clientset
3333
extClient *extfake.Clientset
3434
agonesClient *agonesfake.Clientset
3535
agonesInformerFactory externalversions.SharedInformerFactory
3636
fakeRecorder *record.FakeRecorder
3737
}
3838

39-
func newMocks() mocks {
39+
func newMocks() mocks { // nolint: megacheck
4040
kubeClient := &kubefake.Clientset{}
4141
extClient := &extfake.Clientset{}
4242
agonesClient := &agonesfake.Clientset{}
@@ -51,7 +51,7 @@ func newMocks() mocks {
5151
return m
5252
}
5353

54-
func startInformers(mocks mocks, sync ...cache.InformerSynced) (<-chan struct{}, context.CancelFunc) {
54+
func startInformers(mocks mocks, sync ...cache.InformerSynced) (<-chan struct{}, context.CancelFunc) { // nolint: megacheck
5555
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
5656
stop := ctx.Done()
5757

0 commit comments

Comments
 (0)