Skip to content

Commit

Permalink
Merge pull request #262 from erikwilson/golangci-lint
Browse files Browse the repository at this point in the history
Upgrade to golangci-lint & go v1.12.1
  • Loading branch information
ibuildthecloud committed Mar 26, 2019
2 parents 4463408 + 5e2b58c commit 028b8a4
Show file tree
Hide file tree
Showing 29 changed files with 66 additions and 71 deletions.
19 changes: 19 additions & 0 deletions .golangci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"linters": {
"disable-all": true,
"enable": [
"govet",
"golint",
"goimports",
"misspell",
"ineffassign",
"gofmt"
]
},
"run": {
"skip-files": [
"/zz_generated_"
],
"deadline": "5m"
}
}
11 changes: 0 additions & 11 deletions .gometalinter.json

This file was deleted.

18 changes: 9 additions & 9 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
FROM golang:1.11.4-alpine3.8
# FROM arm=golang@sha256:fe81149b4e7f07ecb558fd16cdbcdb11e739846a046e38cc6e170aa39a67e7ec arm64=golang@sha256:da9c2d140ed4bf911ef8f6d9437912b80497c256ef2235c65836eac83d1c0ce7
FROM golang:1.12.1-alpine3.9

RUN apk -U --no-cache add bash git gcc musl-dev docker vim less file curl wget ca-certificates jq linux-headers zlib-dev tar zip squashfs-tools npm coreutils \
python3 py3-pip python3-dev openssl-dev libffi-dev libseccomp libseccomp-dev make
RUN pip3 install 'tox==3.6.0'
RUN apk -U --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/ add sqlite-dev sqlite-static
RUN mkdir -p /go/src/golang.org/x && \
cd /go/src/golang.org/x && git clone https://github.com/golang/tools && git clone https://github.com/golang/lint && \
git -C /go/src/golang.org/x/lint/golint checkout -b current 06c8688daad7faa9da5a0c2f163a3d14aac986ca && \
go install golang.org/x/lint/golint
RUN go get -d github.com/alecthomas/gometalinter && \
git -C /go/src/github.com/alecthomas/gometalinter checkout -b current v2.0.11 && \
go install github.com/alecthomas/gometalinter && \
gometalinter --install
cd /go/src/golang.org/x && git clone https://github.com/golang/tools && \
git -C /go/src/golang.org/x/tools checkout -b current aa82965741a9fecd12b026fbb3d3c6ed3231b8f8 && \
go install golang.org/x/tools/cmd/goimports
RUN rm -rf /go/src /go/pkg

ARG DAPPER_HOST_ARCH
ENV ARCH $DAPPER_HOST_ARCH

RUN if [ "${ARCH}" == "amd64" ]; then \
curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0; \
fi

ENV DAPPER_RUN_ARGS --privileged -v k3s-cache:/go/src/github.com/rancher/k3s/.cache
ENV DAPPER_ENV REPO TAG DRONE_TAG IMAGE_NAME
ENV DAPPER_SOURCE /go/src/github.com/rancher/k3s/
Expand Down
4 changes: 2 additions & 2 deletions cmd/k3s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ func getAssetAndDir(dataDir string) (string, string) {

func extract(dataDir string) (string, error) {
// first look for global asset folder so we don't create a HOME version if not needed
asset, dir := getAssetAndDir(datadir.DefaultDataDir)
_, dir := getAssetAndDir(datadir.DefaultDataDir)
if _, err := os.Stat(dir); err == nil {
logrus.Debugf("Asset dir %s", dir)
return dir, nil
}

asset, dir = getAssetAndDir(dataDir)
asset, dir := getAssetAndDir(dataDir)
if _, err := os.Stat(dir); err == nil {
logrus.Debugf("Asset dir %s", dir)
return dir, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/flannel/flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func WriteSubnetFile(path string, nw ip.IP4Net, ipMasq bool, bn backend.Network)
// Write out the first usable IP by incrementing
// sn.IP by one
sn := bn.Lease().Subnet
sn.IP += 1
sn.IP++

fmt.Fprintf(f, "FLANNEL_NETWORK=%s\n", nw)
fmt.Fprintf(f, "FLANNEL_SUBNET=%s\n", sn)
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/flannel/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
]
}
`
netJson = `{
netJSON = `{
"Network": "%CIDR%",
"Backend": {
"Type": "vxlan"
Expand Down Expand Up @@ -99,5 +99,5 @@ func createFlannelConf(config *config.Node) error {
return nil
}
return util.WriteFile(config.FlannelConf,
strings.Replace(netJson, "%CIDR%", config.AgentConfig.ClusterCIDR.String(), -1))
strings.Replace(netJSON, "%CIDR%", config.AgentConfig.ClusterCIDR.String(), -1))
}
6 changes: 3 additions & 3 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Server struct {
DisableAgent bool
KubeConfigOutput string
KubeConfigMode string
KnownIPs cli.StringSlice
KnownIPs cli.StringSlice
}

var ServerConfig Server
Expand Down Expand Up @@ -96,8 +96,8 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
EnvVar: "K3S_KUBECONFIG_MODE",
},
cli.StringSliceFlag{
Name: "tls-san",
Usage: "Add additional hostname or IP as a Subject Alternative Name in the TLS cert",
Name: "tls-san",
Usage: "Add additional hostname or IP as a Subject Alternative Name in the TLS cert",
Value: &ServerConfig.KnownIPs,
},
NodeIPFlag,
Expand Down
5 changes: 3 additions & 2 deletions pkg/deploy/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package deploy

import (
"bytes"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func Stage(dataDir string, templateVars map[string]string, skipList []string) error {
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ func startNorman(ctx context.Context, config *Config) (string, error) {
},
}

ctx, _, err = normanConfig.Build(ctx, nil)
if err != nil {
if _, _, err = normanConfig.Build(ctx, nil); err != nil {
return "", err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/servicelb/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (h *handler) newDeployment(svc *core.Service) (*apps.Deployment, error) {

for _, node := range nodes {
if Ready.IsTrue(node) {
replicas += 1
replicas++
}
if replicas >= 2 {
break
Expand Down
27 changes: 7 additions & 20 deletions scripts/validate
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,21 @@ set -e

cd $(dirname $0)/..

if ! command -v golangci-lint; then
echo Skipping validation: no golangci-lint available
exit
fi
echo Running validation

PACKAGES="$(go list ./...)"

if [ ! -e build/data ];then
mkdir -p build/data
fi

echo Running: go generate
go generate

echo Running: go vet
go vet ${PACKAGES}
echo Running: gometalinter
for i in ${PACKAGES}; do
if [ -n "$(gometalinter $i | \
grep -v 'pkg/data/zz_generated_bindata.go' | \
grep -v 'should have comment.*or be unexported' | \
grep -v 'cli/cmd.*don.t use underscores in Go name' | \
grep -v 'cli/cmd.*should be DNS' | \
tee /dev/stderr)" ]; then
failed=true
fi
done
test -z "$failed"
echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | \
grep -v 'pkg/data/zz_generated_bindata.go' | \
tee /dev/stderr)"
echo Running: golangci-lint
golangci-lint run

. ./scripts/version.sh

Expand Down
2 changes: 1 addition & 1 deletion types/apis/apps/v1/zz_generated_deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/apps/v1"
v1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/apps/v1"
v1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion types/apis/batch/v1/zz_generated_job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/batch/v1"
v1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
2 changes: 1 addition & 1 deletion types/apis/batch/v1/zz_generated_job_lifecycle_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/batch/v1"
v1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion types/apis/core/v1/zz_generated_config_map_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion types/apis/core/v1/zz_generated_endpoints_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion types/apis/core/v1/zz_generated_node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
2 changes: 1 addition & 1 deletion types/apis/core/v1/zz_generated_node_lifecycle_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion types/apis/core/v1/zz_generated_pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
2 changes: 1 addition & 1 deletion types/apis/core/v1/zz_generated_pod_lifecycle_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion types/apis/core/v1/zz_generated_service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/rbac/v1"
v1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1

import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/rbac/v1"
v1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down

0 comments on commit 028b8a4

Please sign in to comment.