Skip to content

Commit

Permalink
Merge pull request kubernetes#1791 from aledbf/fix-headers
Browse files Browse the repository at this point in the history
Fix verification of boilerplate, style and file headers
  • Loading branch information
aledbf authored Dec 4, 2017
2 parents 17a4c53 + a4f67c0 commit 2a2d861
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
3 changes: 1 addition & 2 deletions hack/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
44 changes: 44 additions & 0 deletions hack/kube-env.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 78 additions & 0 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
43 changes: 43 additions & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 40 additions & 0 deletions hack/verify-golint.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions images/custom-error-pages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
16 changes: 16 additions & 0 deletions internal/file/filesystem.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
16 changes: 16 additions & 0 deletions internal/file/structure.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
16 changes: 16 additions & 0 deletions internal/ingress/controller/certificate.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions internal/ingress/controller/process/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions internal/ingress/controller/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ import (
"github.com/paultag/sniff/parser"
)

// TCPServer describes a server that works in passthrough mode
type TCPServer struct {
Hostname string
IP string
Port int
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
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/ingress/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions internal/watch/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
Loading

0 comments on commit 2a2d861

Please sign in to comment.