diff --git a/.commonfiles.sha b/.commonfiles.sha new file mode 100644 index 00000000000..e05a27c1281 --- /dev/null +++ b/.commonfiles.sha @@ -0,0 +1 @@ +5747f694803650e785957bd4e716604b6c8310aa diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000000..1cd3e071a59 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,188 @@ +# The original version of this file is located in the https://github.com/istio/common-files repo. +# If you're looking at this file in a different repo and want to make a change, please go to the +# common-files repo, make the change there and check it in. Then come back to this repo and run the +# scripts/updatecommonfiles.sh script. + +service: + # When updating this, also update bin/linters.sh accordingly + golangci-lint-version: 1.16.x # use the fixed version to not introduce new linters unexpectedly +run: + # timeout for analysis, e.g. 30s, 5m, default is 1m + deadline: 20m + + # which dirs to skip: they won't be analyzed; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but next dirs are always skipped independently + # from this option's value: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs: + - genfiles$ + - vendor$ + + # which files to skip: they will be analyzed, but issues from them + # won't be reported. Default value is empty list, but there is + # no need to include all autogenerated files, we confidently recognize + # autogenerated files. If it's not please let us know. + skip-files: + - ".*\\.pb\\.go" + - ".*\\.gen\\.go" + +linters: + enable-all: true + disable: + - depguard + - dupl + - gochecknoglobals + - gochecknoinits + - goconst + - gocyclo + - gosec + - nakedret + - prealloc + - scopelint + fast: false + +linters-settings: + errcheck: + # report about not checking of errors in type assetions: `a := b.(MyStruct)`; + # default is false: such cases aren't reported by default. + check-type-assertions: false + + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: false + govet: + # report about shadowed variables + check-shadowing: false + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0.0 + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: istio.io/ + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + misspell: + # Correct spellings using locale preferences for US or UK. + # Default is to use a neutral variety of English. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: US + lll: + # max line length, lines longer will be reported. Default is 120. + # '\t' is counted as 1 character by default, and can be changed with the tab-width option + line-length: 160 + # tab width in spaces. Default to 1. + tab-width: 1 + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + unparam: + # call graph construction algorithm (cha, rta). In general, use cha for libraries, + # and rta for programs with main packages. Default is cha. + algo: cha + + # Inspect exported functions, default is false. Set to true if no external program/library imports your code. + # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find external interfaces. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + gocritic: + enabled-checks: + - appendCombine + - argOrder + - assignOp + - badCond + - boolExprSimplify + - builtinShadow + - captLocal + - caseOrder + - codegenComment + - commentedOutCode + - commentedOutImport + - defaultCaseOrder + - deprecatedComment + - docStub + - dupArg + - dupBranchBody + - dupCase + - dupSubExpr + - elseif + - emptyFallthrough + - equalFold + - flagDeref + - flagName + - hexLiteral + - indexAlloc + - initClause + - methodExprCall + - nilValReturn + - octalLiteral + - offBy1 + - rangeExprCopy + - regexpMust + - sloppyLen + - stringXbytes + - switchTrue + - typeAssertChain + - typeSwitchVar + - typeUnparen + - underef + - unlambda + - unnecessaryBlock + - unslice + - valSwap + - weakCond + - yodaStyleExpr + + # Unused + # - appendAssign + # - commentFormatting + # - emptyStringTest + # - exitAfterDefer + # - ifElseChain + # - hugeParam + # - importShadow + # - nestingReduce + # - paramTypeCombine + # - ptrToRefParam + # - rangeValCopy + # - singleCaseSwitch + # - sloppyReassign + # - unlabelStmt + # - unnamedResult + # - wrapperFunc + +issues: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` + exclude: + - composite literal uses unkeyed fields + + exclude-rules: + # Exclude some linters from running on test files. + - path: _test\.go$|^tests/|^samples/ + linters: + - errcheck + - maligned + + # Independently from option `exclude` we use default exclude patterns, + # it can be disabled by this option. To list all + # excluded by default patterns execute `golangci-lint run --help`. + # Default value for this option is true. + exclude-use-default: true + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-per-linter: 0 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 diff --git a/BUGS-AND-FEATURE-REQUESTS.md b/BUGS-AND-FEATURE-REQUESTS.md new file mode 100644 index 00000000000..a0366030bac --- /dev/null +++ b/BUGS-AND-FEATURE-REQUESTS.md @@ -0,0 +1,7 @@ +# Bugs and Feature Requests + +You can report bugs and feature requests to the Istio team in one of three places: + +- [Product Bugs and Feature Requests](https://github.com/istio/istio/issues) +- [Documentation Bugs and Feature Requests](https://github.com/istio/istio.io/issues) +- [Community and Governance Issues](https://github.com/istio/community/issues) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 17cc87489fb..7b55cf47ab4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ # Contribution guidelines -So, you want to hack on the Istio proxy? Yay! Please refer to Istio's overall +So you want to hack on Istio? Yay! Please refer to Istio's overall [contribution guidelines](https://github.com/istio/community/blob/master/CONTRIBUTING.md) to find out how you can help. diff --git a/LICENSE b/LICENSE index 2c45691e883..e51498512b7 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2016 Istio Authors + Copyright 2019 Istio Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index 82dccc095d4..9487c47d8e3 100644 --- a/Makefile +++ b/Makefile @@ -53,16 +53,18 @@ test_asan: test_tsan: PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) test $(BAZEL_TEST_ARGS) --config=clang-tsan --test_env=TSAN_OPTIONS=suppressions=$(TOP)/tsan.suppressions -- $(BAZEL_TARGETS) $(SANITIZER_EXCLUSIONS) -check: - @script/check-license-headers - @script/check-repositories - @script/check-style +lint: + @scripts/check_licenses.sh + @scripts/check-repositories.sh + @scripts/check-style.sh artifacts: build - @script/push-debian.sh -c opt -p $(ARTIFACTS_DIR) + @scripts/push-debian.sh -c opt -p $(ARTIFACTS_DIR) deb: CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) //tools/deb:istio-proxy .PHONY: build clean test check artifacts + +include Makefile.common.mk diff --git a/Makefile.common.mk b/Makefile.common.mk new file mode 100644 index 00000000000..cc3729565e3 --- /dev/null +++ b/Makefile.common.mk @@ -0,0 +1,27 @@ +# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY +# +# The original version of this file is located in the https://github.com/istio/common-files repo. +# If you're looking at this file in a different repo and want to make a change, please go to the +# common-files repo, make the change there and check it in. Then come back to this repo and run the +# scripts/updatecommonfiles.sh script. + +# Copyright 2018 Istio 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. + +updatecommon: + @git clone https://github.com/istio/common-files + @cd common-files + @git rev-parse HEAD >.commonfiles.sha + @cp -r common-files/files/* common-files/files/.[^.]* . + @rm -fr common-files diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 00000000000..b487fc5a61c --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,7 @@ +# Support + +Here are some resources to help you understand and use Istio: + +- For in-depth information about how to use Istio, visit [istio.io](https://istio.io) +- To ask questions and get assistance from our community, visit [discuss.istio.io](https://discuss.istio.io) +- To learn how to participate in our overall community, visit [our community page](https://istio.io/about/community) diff --git a/prow/proxy-postsubmit.sh b/prow/proxy-postsubmit.sh index 1004e539c67..afa6cf17d4a 100755 --- a/prow/proxy-postsubmit.sh +++ b/prow/proxy-postsubmit.sh @@ -45,5 +45,5 @@ GIT_SHA="$(git rev-parse --verify HEAD)" cd $ROOT echo 'Create and push artifacts' -script/release-binary +scripts/release-binary.sh ARTIFACTS_DIR="gs://istio-artifacts/proxy/${GIT_SHA}/artifacts/debs" make artifacts diff --git a/script/check-license-headers b/script/check-license-headers deleted file mode 100755 index 2e3a6a6e8f7..00000000000 --- a/script/check-license-headers +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -# -# Copyright 2017 Istio Authors. 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. -# -################################################################################ -# -# Checks the source code files for proper license headers. - -ISTIO_COPYRIGHT='Copyright 20[0-9][0-9] Istio Authors\. All Rights Reserved\.' -ISTIO_LICENSE='Apache License, Version 2\.0' - -ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" - -function is_source_code_file() { - first_line="$(head -1 ${1} | xargs --null)" - filename="$(basename ${1})" - [[ "${filename}" == 'BUILD' ]] && return 0 - [[ "${first_line}" == '#!/bin/bash' ]] && return 0 - extension="$(echo ${1} | awk -F . '{if (NF>1) {print $NF}}')" - [[ "${extension}" == "c" || - "${extension}" == "cc" || - "${extension}" == "h" || - "${extension}" == "py" || - "${extension}" == "go" || - "${extension}" == "bzl" ]] && return 0 - return 1 -} - -BAD_LICENSE=0 - -for file in $(git ls-files) -do - base="$(echo ${file} | awk -F / '{print $1}')" - [[ "${base}" == "contrib" || "${base}" == "google" || "${base}" == "third_party" ]] && continue - if is_source_code_file "${file}"; then - istio_copyright_count="$(head -n 15 ${file} | grep "${ISTIO_COPYRIGHT}" | wc -l)" - istio_license_count="$(head -n 15 ${file} | grep "${ISTIO_LICENSE}" | wc -l)" - if [[ "${istio_copyright_count}" != 1 || "${istio_license_count}" != 1 ]]; then - echo ${file} - BAD_LICENSE=1 - fi - fi -done - -[[ ${BAD_LICENSE} == 0 ]] || (echo "Found invalid license headers." && exit 1) diff --git a/script/build_proxy_artifacts.yaml b/scripts/build_proxy_artifacts.yaml similarity index 100% rename from script/build_proxy_artifacts.yaml rename to scripts/build_proxy_artifacts.yaml diff --git a/script/check-repositories b/scripts/check-repository.sh similarity index 100% rename from script/check-repositories rename to scripts/check-repository.sh diff --git a/script/check-style b/scripts/check-style.sh similarity index 100% rename from script/check-style rename to scripts/check-style.sh diff --git a/scripts/check_license.sh b/scripts/check_license.sh new file mode 100755 index 00000000000..f003f4afb70 --- /dev/null +++ b/scripts/check_license.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY +# +# The original version of this file is located in the https://github.com/istio/common-files repo. +# If you're looking at this file in a different repo and want to make a change, please go to the +# common-files repo, make the change there and check it in. Then come back to this repo and run the +# scripts/updatecommonfiles.sh script. + +# Copyright 2018 Istio 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 -e + +SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOTDIR=$(dirname "${SCRIPTPATH}") +cd "${ROOTDIR}" + +ADD_LICENSE=$1 +THISYEAR=$(date +"%Y") +if [[ $ADD_LICENSE == true ]]; then + echo "Check License script is running in ADD_LICENSE mode. It will automatically add any missing licenses for you." +fi + +ret=0 +for fn in $(find "${ROOTDIR}" -type f \( -name '*.go' -o -name '*.cc' -o -name '*.h' -o -name '*.proto' \) | grep -v vendor | grep -v testdata); do + if [[ $fn == *.pb.go ]];then + continue + fi + + if head -20 "$fn" | grep "auto\\-generated" > /dev/null; then + continue + fi + + if head -20 "$fn" | grep "DO NOT EDIT" > /dev/null; then + continue + fi + + if head -20 "$fn" | grep "Code generated by go-bindata" > /dev/null; then + continue + fi + + if ! head -20 "$fn" | grep "Apache License, Version 2" > /dev/null; then + if [[ $ADD_LICENSE == true ]]; then + echo "// Copyright ${THISYEAR} Istio 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. + +$(cat "${fn}")" > "${fn}" + else + echo "${fn} missing license" + ret=$((ret+1)) + fi + fi + + if ! head -20 "$fn" | grep Copyright > /dev/null; then + echo "${fn} missing Copyright" + ret=$((ret+1)) + fi +done + +exit $ret diff --git a/script/pre-commit b/scripts/pre-commit similarity index 100% rename from script/pre-commit rename to scripts/pre-commit diff --git a/script/push-debian.sh b/scripts/push-debian.sh similarity index 100% rename from script/push-debian.sh rename to scripts/push-debian.sh diff --git a/script/release-binary b/scripts/release-binary.sh similarity index 100% rename from script/release-binary rename to scripts/release-binary.sh diff --git a/scripts/run_gofmt.sh b/scripts/run_gofmt.sh new file mode 100755 index 00000000000..94fcaf327bf --- /dev/null +++ b/scripts/run_gofmt.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY +# +# The original version of this file is located in the https://github.com/istio/common-files repo. +# If you're looking at this file in a different repo and want to make a change, please go to the +# common-files repo, make the change there and check it in. Then come back to this repo and run the +# scripts/updatecommonfiles.sh script. + +# Copyright 2018 Istio 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. + +# Applies requisite code formatters to the source tree + +set -e + +SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOTDIR=$(dirname "${SCRIPTPATH}") +cd "${ROOTDIR}" + +# Go format tool to use +# While 'goimports' is preferred we temporarily use 'gofmt' until https://github.com/golang/go/issues/28200 is resolved +GO_FMT_TOOL=goimportsdocker + +PKGS=${PKGS:-"."} +if [[ -z ${GO_FILES} ]];then + GO_FILES=$(find "${PKGS}" -type f -name '*.go' ! -name '*.gen.go' ! -name '*.pb.go' ! -name '*mock*.go' | grep -v ./vendor) +fi + +# need to pin goimports to align with golangci-lint. SHA is from x/tools repo +if [ $GO_FMT_TOOL = "goimportsdocker" ]; then + GO_IMPORTS_DOCKER="gcr.io/istio-testing/goimports:379209517ffe" + tool="docker run -i --rm -v ${ROOTDIR}:${ROOTDIR} -w ${ROOTDIR} ${GO_IMPORTS_DOCKER} /goimports" + fmt_args="-w -local istio.io" +fi + +if [ $GO_FMT_TOOL = "gofmt" ]; then + tool=gofmt + fmt_args="-w" +fi + +echo "Formatting the source files" +# shellcheck disable=SC2086 +$tool ${fmt_args} ${GO_FILES} +exit $? diff --git a/scripts/run_golangci.sh b/scripts/run_golangci.sh new file mode 100755 index 00000000000..e05f77ab8a8 --- /dev/null +++ b/scripts/run_golangci.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY +# +# The original version of this file is located in the https://github.com/istio/common-files repo. +# If you're looking at this file in a different repo and want to make a change, please go to the +# common-files repo, make the change there and check it in. Then come back to this repo and run the +# scripts/updatecommonfiles.sh script. + +# Copyright 2019 Istio 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 -e + +SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOTDIR=$(dirname "${SCRIPTPATH}") +cd "${ROOTDIR}" + +if [[ "$1" == "--fix" ]] +then + FIX="--fix" +fi + +# if you want to update this version, also change the version number in .golangci.yml +GOLANGCI_VERSION="v1.16.0" +curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b "$GOPATH"/bin "$GOLANGCI_VERSION" +golangci-lint --version +env GOGC=25 golangci-lint run ${FIX} -j 1 -v ./...