Fix verification of boilerplate, style and file headers
This commit is contained in:
parent
738d83985e
commit
a4f67c0853
20 changed files with 297 additions and 18 deletions
|
@ -32,7 +32,7 @@ jobs:
|
|||
- stage: Static Check
|
||||
script:
|
||||
- go get github.com/golang/lint/golint
|
||||
- make fmt lint vet
|
||||
- make verify-all
|
||||
- stage: Coverage
|
||||
before_script:
|
||||
# start minikube
|
||||
|
|
14
Makefile
14
Makefile
|
@ -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}" \
|
||||
-o ${TEMP_DIR}/rootfs/nginx-ingress-controller ${PKG}/cmd/nginx
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
@echo "+ $@"
|
||||
@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: verify-all
|
||||
verify-all:
|
||||
@./hack/verify-all.sh
|
||||
|
||||
.PHONY: test
|
||||
test: fmt lint vet
|
||||
test:
|
||||
@echo "+ $@"
|
||||
@go test -v -race -tags "$(BUILDTAGS) cgo" $(shell go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e')
|
||||
|
||||
|
|
|
@ -130,8 +130,7 @@ def file_passes(filename, refs, regexs):
|
|||
def file_extension(filename):
|
||||
return os.path.splitext(filename)[1].split(".")[-1].lower()
|
||||
|
||||
skipped_dirs = ['Godeps', 'third_party', '_gopath', '_output', '.git', 'cluster/env.sh',
|
||||
"vendor", "test/e2e/generated/bindata.go", "hack/boilerplate/test"]
|
||||
skipped_dirs = ['.git', "vendor", "test/e2e/framework/framework.go", "test/e2e/generated/bindata.go", "hack/boilerplate/test", "internal/file/bindata.go"]
|
||||
|
||||
def normalize_files(files):
|
||||
newfiles = []
|
||||
|
|
44
hack/kube-env.sh
Normal file
44
hack/kube-env.sh
Normal 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
78
hack/verify-all.sh
Executable 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
|
|
@ -21,8 +21,8 @@ set -o pipefail
|
|||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
SCRIPT_BASE=${SCRIPT_ROOT}/../..
|
||||
|
||||
DIFFROOT="${SCRIPT_ROOT}/pkg"
|
||||
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg"
|
||||
DIFFROOT="${SCRIPT_ROOT}/internal"
|
||||
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/internal"
|
||||
_tmp="${SCRIPT_ROOT}/_tmp"
|
||||
|
||||
cleanup() {
|
||||
|
|
43
hack/verify-gofmt.sh
Executable file
43
hack/verify-gofmt.sh
Executable 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
40
hack/verify-golint.sh
Executable 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
|
|
@ -27,10 +27,13 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// FormatHeader name of the header used to extract the format
|
||||
FormatHeader = "X-Format"
|
||||
|
||||
// CodeHeader name of the header used as source of the HTTP statu code to return
|
||||
CodeHeader = "X-Code"
|
||||
|
||||
// ContentType name of the header that defines the format of the reply
|
||||
ContentType = "Content-Type"
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
import (
|
||||
|
|
|
@ -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
|
||||
|
||||
const (
|
||||
|
|
|
@ -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
|
||||
|
||||
import (
|
||||
|
|
|
@ -45,6 +45,8 @@ NGINX master process died (%v): %v
|
|||
return true
|
||||
}
|
||||
|
||||
// WaitUntilPortIsAvailable waits until there is no NGINX master or worker
|
||||
// process/es listentning in a particular port.
|
||||
func WaitUntilPortIsAvailable(port int) {
|
||||
// we wait until the workers are killed
|
||||
for {
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/paultag/sniff/parser"
|
||||
)
|
||||
|
||||
// TCPServer describes a server that works in passthrough mode
|
||||
type TCPServer struct {
|
||||
Hostname string
|
||||
IP string
|
||||
|
@ -33,11 +34,13 @@ type TCPServer struct {
|
|||
ProxyProtocol bool
|
||||
}
|
||||
|
||||
// TCPProxy describes the passthrough servers and a default as catch all
|
||||
type TCPProxy struct {
|
||||
ServerList []*TCPServer
|
||||
Default *TCPServer
|
||||
}
|
||||
|
||||
// Get returns the TCPServer to use
|
||||
func (p *TCPProxy) Get(host string) *TCPServer {
|
||||
if p.ServerList == nil {
|
||||
return p.Default
|
||||
|
@ -52,6 +55,8 @@ func (p *TCPProxy) Get(host string) *TCPServer {
|
|||
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) {
|
||||
defer conn.Close()
|
||||
data := make([]byte, 4096)
|
||||
|
|
|
@ -84,10 +84,13 @@ func IsInvalidContent(e error) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
// New returns a new error
|
||||
func New(m string) error {
|
||||
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 {
|
||||
return errors.Errorf(format, args)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package watch
|
|||
// DummyFileWatcher noop implementation of a file watcher
|
||||
type DummyFileWatcher struct{}
|
||||
|
||||
// NewDummyFileWatcher creates a FileWatcher using the DummyFileWatcher
|
||||
func NewDummyFileWatcher(file string, onEvent func()) FileWatcher {
|
||||
return DummyFileWatcher{}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"gopkg.in/fsnotify.v1"
|
||||
)
|
||||
|
||||
// FileWatcher is an interface we use to watch changes in files
|
||||
type FileWatcher interface {
|
||||
Close() error
|
||||
}
|
||||
|
|
|
@ -24,10 +24,12 @@ import (
|
|||
"github.com/onsi/ginkgo/config"
|
||||
"github.com/onsi/gomega"
|
||||
"k8s.io/apiserver/pkg/util/logs"
|
||||
// required
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
|
||||
// tests to run
|
||||
_ "k8s.io/ingress-nginx/test/e2e/annotations"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/defaultbackend"
|
||||
_ "k8s.io/ingress-nginx/test/e2e/settings"
|
||||
|
|
|
@ -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
|
||||
|
||||
import (
|
||||
|
|
Loading…
Reference in a new issue