Skip to content

Commit

Permalink
Merge pull request #176 from EricFortin/feature/gometalinter
Browse files Browse the repository at this point in the history
Feature/gometalinter
  • Loading branch information
markmandel authored Apr 15, 2018
2 parents afd53d2 + a61fdc5 commit 14f8329
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 23 deletions.
7 changes: 6 additions & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ build-images: build-controller-image build-agones-sdk-image
build-sdks: build-sdk-cpp

# Run all tests
test: ensure-build-image test-go test-install-yaml
test: ensure-build-image lint test-go test-install-yaml

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

# Lint the go source code.
lint: ensure-build-image
docker run --rm $(common_mounts) -w $(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) bash -c \
"/root/gen-lint-exclude.sh && gometalinter --config .exclude.gometalinter.json --deadline 100s -t --skip vendor ./..."

# Build the image for the gameserver controller
build-controller-image: ensure-build-image build-controller-binary
docker build $(agones_path)/cmd/controller/ --tag=$(controller_tag) $(DOCKER_BUILD_ARGS)
Expand Down
4 changes: 2 additions & 2 deletions build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

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

RUN apt-get update && \
apt-get install -y wget rsync make python bash-completion zip && \
apt-get install -y wget rsync make python bash-completion zip jq && \
apt-get clean

# install go
Expand Down
18 changes: 18 additions & 0 deletions build/build-image/gen-lint-exclude.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

excluded=$(find . -name "*.go" | grep -v vendor | xargs grep autogenerated | cut -d ':' -f 1 | uniq | sed 's#\./##g')
jq -n --arg inarjq -n --arg inarr "${excluded}" '{ Exclude: ($inarr | split("\n")) }' > .exclude.gometalinter.json
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var (
)

// main starts the operator for the gameserver CRD
func main() {
func main() { // nolint: gocyclo
exec, err := os.Executable()
if err != nil {
logger.WithError(err).Fatal("Could not get executable path")
Expand Down
6 changes: 2 additions & 4 deletions examples/simple-udp/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

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

log.Print("Creating SDK instance")
s, err := sdk.NewSDK()
Expand Down Expand Up @@ -79,12 +79,10 @@ func main() {
log.Printf("Could not shutdown")
}
os.Exit(0)
break

// turns off the health pings
case "UNHEALTHY":
close(stop)
break
}

// echo it back
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/stable/v1alpha1/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
)

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

Expand Down Expand Up @@ -62,7 +64,7 @@ type FleetStatus struct {
ReadyReplicas int32 `json:"readyReplicas"`
}

// Fleet returns a single GameServerSet for this Fleet definition
// GameServerSet returns a single GameServerSet for this Fleet definition
func (f *Fleet) GameServerSet() *GameServerSet {
gsSet := &GameServerSet{
ObjectMeta: *f.Spec.Template.ObjectMeta.DeepCopy(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/gameservers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func testHTTPHealth(t *testing.T, url string, expectedResponse string, expectedS

assert.NotNil(t, resp)
if resp != nil {
defer resp.Body.Close()
defer resp.Body.Close() // nolint: errcheck
body, err := ioutil.ReadAll(resp.Body)
assert.Nil(t, err, "(%s) read response error should be nil: %v", url, err)
assert.Equal(t, expectedStatus, resp.StatusCode, "url: %s", url)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gameservers/sdkserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func TestSidecarRun(t *testing.T) {
"ready": {
state: v1alpha1.RequestReady,
f: func(sc *SDKServer, ctx context.Context) {
sc.Ready(ctx, &sdk.Empty{})
sc.Ready(ctx, &sdk.Empty{}) // nolint: errcheck
},
},
"shutdown": {
state: v1alpha1.Shutdown,
f: func(sc *SDKServer, ctx context.Context) {
sc.Shutdown(ctx, &sdk.Empty{})
sc.Shutdown(ctx, &sdk.Empty{}) // nolint: errcheck
},
},
"unhealthy": {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gameserversets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestSyncGameServerSet(t *testing.T) {
_, cancel := agtesting.StartInformers(m, c.gameServerSetSynced, c.gameServerSynced)
defer cancel()

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

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

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

assert.Equal(t, 5, count)
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/gameserversets/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import (
)

// holder for all my fakes and mocks
type mocks struct {
type mocks struct { // nolint: megacheck
kubeClient *kubefake.Clientset
extClient *extfake.Clientset
agonesClient *agonesfake.Clientset
agonesInformerFactory externalversions.SharedInformerFactory
fakeRecorder *record.FakeRecorder
}

func newMocks() mocks {
func newMocks() mocks { // nolint: megacheck
kubeClient := &kubefake.Clientset{}
extClient := &extfake.Clientset{}
agonesClient := &agonesfake.Clientset{}
Expand All @@ -51,7 +51,7 @@ func newMocks() mocks {
return m
}

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

Expand Down
5 changes: 4 additions & 1 deletion pkg/testing/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// Handy tools for testing controllers

// holder for all my fakes and Mocks
// Mocks is a holder for all my fakes and Mocks
type Mocks struct {
KubeClient *kubefake.Clientset
KubeInformationFactory informers.SharedInformerFactory
Expand All @@ -41,6 +41,7 @@ type Mocks struct {
FakeRecorder *record.FakeRecorder
}

// NewMocks creates a new set of fakes and mocks.
func NewMocks() Mocks {
kubeClient := &kubefake.Clientset{}
agonesClient := &agonesfake.Clientset{}
Expand All @@ -56,6 +57,7 @@ func NewMocks() Mocks {
return m
}

// StartInformers starts new fake informers
func StartInformers(mocks Mocks, sync ...cache.InformerSynced) (<-chan struct{}, context.CancelFunc) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
stop := ctx.Done()
Expand All @@ -71,6 +73,7 @@ func StartInformers(mocks Mocks, sync ...cache.InformerSynced) (<-chan struct{},
return stop, cancel
}

// NewEstablishedCRD fakes CRD installation success.
func NewEstablishedCRD() *v1beta1.CustomResourceDefinition {
return &v1beta1.CustomResourceDefinition{
Status: v1beta1.CustomResourceDefinitionStatus{
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (wh *WebHook) AddHandler(path string, gk schema.GroupKind, op v1beta1.Opera
}

// handle Handles http requests for webhooks
func (wh *WebHook) handle(path string, w http.ResponseWriter, r *http.Request) error {
func (wh *WebHook) handle(path string, w http.ResponseWriter, r *http.Request) error { // nolint: interfacer
wh.logger.WithField("path", path).Info("running webhook")

var review v1beta1.AdmissionReview
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/workerqueue/workerqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestWorkQueueHealthCheck(t *testing.T) {
f := func(t *testing.T, url string, status int) {
resp, err := http.Get(url)
assert.Nil(t, err)
defer resp.Body.Close()
defer resp.Body.Close() // nolint: errcheck

body, err := ioutil.ReadAll(resp.Body)
assert.Nil(t, err)
Expand Down
9 changes: 6 additions & 3 deletions sdks/go/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ func TestSDK(t *testing.T) {
assert.False(t, sm.shutdown)
assert.False(t, sm.hm.healthy)

s.Ready()
err := s.Ready()
assert.Nil(t, err)
assert.True(t, sm.ready)
assert.False(t, sm.shutdown)

s.Health()
err = s.Health()
assert.Nil(t, err)
assert.True(t, sm.hm.healthy)

s.Shutdown()
err = s.Shutdown()
assert.Nil(t, err)
assert.True(t, sm.ready)
assert.True(t, sm.shutdown)
}
Expand Down

0 comments on commit 14f8329

Please sign in to comment.