Fix verification of boilerplate, style and file headers

This commit is contained in:
Manuel de Brito Fontes 2017-12-02 12:02:00 -03:00
parent 738d83985e
commit a4f67c0853
20 changed files with 297 additions and 18 deletions

View file

@ -32,7 +32,7 @@ jobs:
- stage: Static Check - stage: Static Check
script: script:
- go get github.com/golang/lint/golint - go get github.com/golang/lint/golint
- make fmt lint vet - make verify-all
- stage: Coverage - stage: Coverage
before_script: before_script:
# start minikube # start minikube

View file

@ -143,18 +143,12 @@ build: clean
-ldflags "-s -w -X ${PKG}/version.RELEASE=${TAG} -X ${PKG}/version.COMMIT=${COMMIT} -X ${PKG}/version.REPO=${REPO_INFO}" \ -ldflags "-s -w -X ${PKG}/version.RELEASE=${TAG} -X ${PKG}/version.COMMIT=${COMMIT} -X ${PKG}/version.REPO=${REPO_INFO}" \
-o ${TEMP_DIR}/rootfs/nginx-ingress-controller ${PKG}/cmd/nginx -o ${TEMP_DIR}/rootfs/nginx-ingress-controller ${PKG}/cmd/nginx
.PHONY: fmt .PHONY: verify-all
fmt: verify-all:
@echo "+ $@" @./hack/verify-all.sh
@go list -f '{{if len .TestGoFiles}}"gofmt -s -l {{.Dir}}"{{end}}' $(shell go list ${PKG}/... | grep -v vendor) | xargs -L 1 sh -c
.PHONY: lint
lint:
@echo "+ $@"
@go list -f '{{if len .TestGoFiles}}"golint {{.Dir}}/..."{{end}}' $(shell go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e') | xargs -L 1 sh -c
.PHONY: test .PHONY: test
test: fmt lint vet test:
@echo "+ $@" @echo "+ $@"
@go test -v -race -tags "$(BUILDTAGS) cgo" $(shell go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e') @go test -v -race -tags "$(BUILDTAGS) cgo" $(shell go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e')

View file

@ -130,8 +130,7 @@ def file_passes(filename, refs, regexs):
def file_extension(filename): def file_extension(filename):
return os.path.splitext(filename)[1].split(".")[-1].lower() return os.path.splitext(filename)[1].split(".")[-1].lower()
skipped_dirs = ['Godeps', 'third_party', '_gopath', '_output', '.git', 'cluster/env.sh', skipped_dirs = ['.git', "vendor", "test/e2e/framework/framework.go", "test/e2e/generated/bindata.go", "hack/boilerplate/test", "internal/file/bindata.go"]
"vendor", "test/e2e/generated/bindata.go", "hack/boilerplate/test"]
def normalize_files(files): def normalize_files(files):
newfiles = [] newfiles = []

44
hack/kube-env.sh Normal file
View file

@ -0,0 +1,44 @@
#!/bin/bash
# Copyright 2014 The Kubernetes Authors.
#
# 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.
# Some useful colors.
if [[ -z "${color_start-}" ]]; then
declare -r color_start="\033["
declare -r color_red="${color_start}0;31m"
declare -r color_yellow="${color_start}0;33m"
declare -r color_green="${color_start}0;32m"
declare -r color_norm="${color_start}0m"
fi
# Returns the server version as MMmmpp, with MM as the major
# component, mm the minor component, and pp as the patch
# revision. e.g. 0.7.1 is echoed as 701, and 1.0.11 would be
# 10011. (This makes for easy integer comparison in bash.)
function kube_server_version() {
local server_version
local major
local minor
local patch
# This sed expression is the POSIX BRE to match strings like:
# Server Version: &version.Info{Major:"0", Minor:"7+", GitVersion:"v0.7.0-dirty", GitCommit:"ad44234f7152e9c66bc2853575445c7071335e57", GitTreeState:"dirty"}
# and capture the GitVersion portion (which has the patch level)
server_version=$(${KUBECTL} --match-server-version=false version | grep "Server Version:")
read major minor patch < <(
echo ${server_version} | \
sed "s/.*GitVersion:\"v\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\).*/\1 \2 \3/")
printf "%02d%02d%02d" ${major} ${minor} ${patch} | sed 's/^0*//'
}

78
hack/verify-all.sh Executable file
View file

@ -0,0 +1,78 @@
#!/bin/bash
# Copyright 2014 The Kubernetes Authors.
#
# 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.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/kube-env.sh"
SILENT=true
function is-excluded {
for e in $EXCLUDE; do
if [[ $1 -ef ${BASH_SOURCE} ]]; then
return
fi
if [[ $1 -ef "$KUBE_ROOT/hack/$e" ]]; then
return
fi
done
return 1
}
while getopts ":v" opt; do
case $opt in
v)
SILENT=false
;;
\?)
echo "Invalid flag: -$OPTARG" >&2
exit 1
;;
esac
done
if $SILENT ; then
echo "Running in the silent mode, run with -v if you want to see script logs."
fi
EXCLUDE="verify-all.sh verify-codegen.sh"
ret=0
for t in `ls $KUBE_ROOT/hack/verify-*.sh`
do
if is-excluded $t ; then
echo "Skipping $t"
continue
fi
if $SILENT ; then
echo -e "Verifying $t"
if bash "$t" &> /dev/null; then
echo -e "${color_green}SUCCESS${color_norm}"
else
echo -e "${color_red}FAILED${color_norm}"
ret=1
fi
else
bash "$t" || ret=1
fi
done
exit $ret
# ex: ts=2 sw=2 et filetype=sh

View file

@ -21,8 +21,8 @@ set -o pipefail
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/.. SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/..
SCRIPT_BASE=${SCRIPT_ROOT}/../.. SCRIPT_BASE=${SCRIPT_ROOT}/../..
DIFFROOT="${SCRIPT_ROOT}/pkg" DIFFROOT="${SCRIPT_ROOT}/internal"
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg" TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/internal"
_tmp="${SCRIPT_ROOT}/_tmp" _tmp="${SCRIPT_ROOT}/_tmp"
cleanup() { cleanup() {

43
hack/verify-gofmt.sh Executable file
View file

@ -0,0 +1,43 @@
#!/bin/bash
# Copyright 2014 The Kubernetes Authors.
#
# 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.
# GoFmt apparently is changing @ head...
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${KUBE_ROOT}"
find_files() {
find . -not \( \
\( \
-wholename './.git' \
-o -wholename '*/vendor/*' \
-o -wholename '*bindata.go' \
\) -prune \
\) -name '*.go'
}
GOFMT="gofmt -s"
bad_files=$(find_files | xargs $GOFMT -l)
if [[ -n "${bad_files}" ]]; then
echo "!!! '$GOFMT' needs to be run on the following files: "
echo "${bad_files}"
exit 1
fi

40
hack/verify-golint.sh Executable file
View file

@ -0,0 +1,40 @@
#!/bin/bash
# Copyright 2014 The Kubernetes Authors.
#
# 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.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${KUBE_ROOT}"
GOLINT=${GOLINT:-"golint"}
PACKAGES=($(go list ./... | grep -v /vendor/ | grep -v /test\/e2e/))
bad_files=()
for package in "${PACKAGES[@]}"; do
out=$("${GOLINT}" -min_confidence=0.9 "${package}")
if [[ -n "${out}" ]]; then
bad_files+=("${out}")
fi
done
if [[ "${#bad_files[@]}" -ne 0 ]]; then
echo "!!! '$GOLINT' problems: "
echo "${bad_files[@]}"
exit 1
fi
# ex: ts=2 sw=2 et filetype=sh

View file

@ -27,10 +27,13 @@ import (
) )
const ( const (
// FormatHeader name of the header used to extract the format
FormatHeader = "X-Format" FormatHeader = "X-Format"
// CodeHeader name of the header used as source of the HTTP statu code to return
CodeHeader = "X-Code" CodeHeader = "X-Code"
// ContentType name of the header that defines the format of the reply
ContentType = "Content-Type" ContentType = "Content-Type"
) )

View file

@ -1,3 +1,19 @@
/*
Copyright 2017 The Kubernetes Authors.
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.
*/
package file package file
import ( import (

View file

@ -1,3 +1,19 @@
/*
Copyright 2017 The Kubernetes Authors.
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.
*/
package file package file
const ( const (

View file

@ -1,3 +1,19 @@
/*
Copyright 2017 The Kubernetes Authors.
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.
*/
package controller package controller
import ( import (

View file

@ -45,6 +45,8 @@ NGINX master process died (%v): %v
return true return true
} }
// WaitUntilPortIsAvailable waits until there is no NGINX master or worker
// process/es listentning in a particular port.
func WaitUntilPortIsAvailable(port int) { func WaitUntilPortIsAvailable(port int) {
// we wait until the workers are killed // we wait until the workers are killed
for { for {

View file

@ -26,6 +26,7 @@ import (
"github.com/paultag/sniff/parser" "github.com/paultag/sniff/parser"
) )
// TCPServer describes a server that works in passthrough mode
type TCPServer struct { type TCPServer struct {
Hostname string Hostname string
IP string IP string
@ -33,11 +34,13 @@ type TCPServer struct {
ProxyProtocol bool ProxyProtocol bool
} }
// TCPProxy describes the passthrough servers and a default as catch all
type TCPProxy struct { type TCPProxy struct {
ServerList []*TCPServer ServerList []*TCPServer
Default *TCPServer Default *TCPServer
} }
// Get returns the TCPServer to use
func (p *TCPProxy) Get(host string) *TCPServer { func (p *TCPProxy) Get(host string) *TCPServer {
if p.ServerList == nil { if p.ServerList == nil {
return p.Default return p.Default
@ -52,6 +55,8 @@ func (p *TCPProxy) Get(host string) *TCPServer {
return p.Default return p.Default
} }
// Handle reads enough information from the connection to extract the hostname
// and open a connection to the passthrough server.
func (p *TCPProxy) Handle(conn net.Conn) { func (p *TCPProxy) Handle(conn net.Conn) {
defer conn.Close() defer conn.Close()
data := make([]byte, 4096) data := make([]byte, 4096)

View file

@ -84,10 +84,13 @@ func IsInvalidContent(e error) bool {
return ok return ok
} }
// New returns a new error
func New(m string) error { func New(m string) error {
return errors.New(m) return errors.New(m)
} }
// Errorf formats according to a format specifier and returns the string
// as a value that satisfies error.
func Errorf(format string, args ...interface{}) error { func Errorf(format string, args ...interface{}) error {
return errors.Errorf(format, args) return errors.Errorf(format, args)
} }

View file

@ -19,6 +19,7 @@ package watch
// DummyFileWatcher noop implementation of a file watcher // DummyFileWatcher noop implementation of a file watcher
type DummyFileWatcher struct{} type DummyFileWatcher struct{}
// NewDummyFileWatcher creates a FileWatcher using the DummyFileWatcher
func NewDummyFileWatcher(file string, onEvent func()) FileWatcher { func NewDummyFileWatcher(file string, onEvent func()) FileWatcher {
return DummyFileWatcher{} return DummyFileWatcher{}
} }

View file

@ -24,6 +24,7 @@ import (
"gopkg.in/fsnotify.v1" "gopkg.in/fsnotify.v1"
) )
// FileWatcher is an interface we use to watch changes in files
type FileWatcher interface { type FileWatcher interface {
Close() error Close() error
} }

View file

@ -24,10 +24,12 @@ import (
"github.com/onsi/ginkgo/config" "github.com/onsi/ginkgo/config"
"github.com/onsi/gomega" "github.com/onsi/gomega"
"k8s.io/apiserver/pkg/util/logs" "k8s.io/apiserver/pkg/util/logs"
// required
_ "k8s.io/client-go/plugin/pkg/client/auth" _ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/ingress-nginx/test/e2e/framework" "k8s.io/ingress-nginx/test/e2e/framework"
// tests to run
_ "k8s.io/ingress-nginx/test/e2e/annotations" _ "k8s.io/ingress-nginx/test/e2e/annotations"
_ "k8s.io/ingress-nginx/test/e2e/defaultbackend" _ "k8s.io/ingress-nginx/test/e2e/defaultbackend"
_ "k8s.io/ingress-nginx/test/e2e/settings" _ "k8s.io/ingress-nginx/test/e2e/settings"

View file

@ -1,3 +1,19 @@
/*
Copyright 2017 The Kubernetes Authors.
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.
*/
package framework package framework
import ( import (