From 70d860fe08f0c992ed66ff38bfa5bdb8835563e3 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Wed, 20 Jul 2016 09:39:18 -0400 Subject: [PATCH] Start verifying golint on a per-package basis as packages are fixed Signed-off-by: Jess Frazelle --- hack/.linted_packages | 196 ++++++++++++++++++++++++++++++++++++++++++ hack/verify-golint.sh | 94 ++++++++++++++++++++ 2 files changed, 290 insertions(+) create mode 100644 hack/.linted_packages create mode 100755 hack/verify-golint.sh diff --git a/hack/.linted_packages b/hack/.linted_packages new file mode 100644 index 0000000000..f5c7c5953c --- /dev/null +++ b/hack/.linted_packages @@ -0,0 +1,196 @@ +cluster/addons/fluentd-elasticsearch/es-image +cmd/gendocs +cmd/genkubedocs +cmd/genman +cmd/genswaggertypedocs +cmd/integration +cmd/kube-apiserver +cmd/kube-apiserver/app +cmd/kube-apiserver/app/options +cmd/kube-controller-manager +cmd/kube-controller-manager/app/options +cmd/kubectl +cmd/kube-dns +cmd/kubelet +cmd/kube-proxy +cmd/kubernetes-discovery +cmd/libs/go2idl/client-gen/generators +cmd/libs/go2idl/client-gen/test_apis/testgroup.k8s.io/install +cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned +cmd/libs/go2idl/conversion-gen +cmd/libs/go2idl/deepcopy-gen +cmd/libs/go2idl/generator +cmd/libs/go2idl/go-to-protobuf +cmd/libs/go2idl/go-to-protobuf/protoc-gen-gogo +cmd/libs/go2idl/import-boss +cmd/libs/go2idl/parser +cmd/libs/go2idl/set-gen +cmd/libs/go2idl/set-gen/generators +cmd/linkcheck +contrib/mesos/cmd/k8sm-controller-manager +contrib/mesos/cmd/k8sm-executor +contrib/mesos/cmd/k8sm-scheduler +contrib/mesos/pkg/executor/config +contrib/mesos/pkg/flagutil +contrib/mesos/pkg/scheduler/components/algorithm +contrib/mesos/pkg/scheduler/service +docs/user-guide/environment-guide/containers/backend +docs/user-guide/environment-guide/containers/show +docs/user-guide/liveness/image +examples +examples/apiserver/server +examples/explorer +examples/https-nginx +examples/sharing-clusters +federation/apis/core/install +federation/apis/federation/install +federation/cmd/federation-apiserver +federation/cmd/federation-controller-manager +federation/cmd/genfeddocs +hack/cmd/teststale +pkg/api +pkg/api/annotations +pkg/api/errors +pkg/api/install +pkg/apimachinery +pkg/api/meta +pkg/api/resource +pkg/apis/abac/v0 +pkg/apis/apps/install +pkg/apis/authentication/install +pkg/apis/authentication.k8s.io/install +pkg/apis/authorization/install +pkg/apis/autoscaling/install +pkg/apis/batch/install +pkg/apis/certificates/install +pkg/apis/componentconfig/install +pkg/api/service +pkg/apis/extensions/install +pkg/apis/extensions/v1beta1 +pkg/apis/policy/install +pkg/apis/rbac/install +pkg/api/v1 +pkg/auth/authenticator +pkg/auth/authorizer/union +pkg/client/testing/core +pkg/client/unversioned +pkg/client/unversioned/adapters/internalclientset +pkg/client/unversioned/auth +pkg/client/unversioned/remotecommand +pkg/cloudprovider/providers +pkg/cloudprovider/providers/azure +pkg/controller/framework +pkg/controller/volume +pkg/controller/volume/attachdetach/cache +pkg/controller/volume/attachdetach/populator +pkg/controller/volume/attachdetach/reconciler +pkg/controller/volume/cache +pkg/controller/volume/populator +pkg/controller/volume/reconciler +pkg/controller/volume/statusupdater +pkg/conversion/queryparams +pkg/credentialprovider/aws +pkg/hyperkube +pkg/kubelet/api +pkg/kubelet/container +pkg/kubelet/envvars +pkg/kubelet/util/format +pkg/kubelet/util/ioutils +pkg/kubelet/volume +pkg/kubelet/volume/cache +pkg/kubelet/volumemanager +pkg/kubelet/volumemanager/cache +pkg/kubelet/volumemanager/populator +pkg/kubelet/volumemanager/reconciler +pkg/kubelet/volume/populator +pkg/kubelet/volume/reconciler +pkg/proxy/config +pkg/quota/install +pkg/registry +pkg/registry/authorization/util +pkg/registry/clusterrolebinding/etcd +pkg/registry/clusterrole/etcd +pkg/registry/configmap/etcd +pkg/registry/endpoint +pkg/registry/node/rest +pkg/registry/pod/etcd +pkg/registry/podsecuritypolicy/etcd +pkg/registry/rangeallocation +pkg/registry/rolebinding/etcd +pkg/registry/role/etcd +pkg/registry/serviceaccount +pkg/registry/service/ipallocator/controller +pkg/registry/service/ipallocator/etcd +pkg/registry/thirdpartyresource +pkg/registry/thirdpartyresource/etcd +pkg/runtime +pkg/runtime/serializer/json +pkg/runtime/serializer/protobuf +pkg/runtime/serializer/recognizer/testing +pkg/runtime/serializer/versioning +pkg/runtime/serializer/yaml +pkg/security +pkg/security/podsecuritypolicy/capabilities +pkg/serviceaccount +pkg/storage +pkg/storage/etcd3 +pkg/storage/storagebackend/factory +pkg/util/async +pkg/util/certificates +pkg/util/codeinspector +pkg/util/crypto +pkg/util/flock +pkg/util/flushwriter +pkg/util/goroutinemap +pkg/util/hash +pkg/util/homedir +pkg/util/interrupt +pkg/util/io +pkg/util/json +pkg/util/limitwriter +pkg/util/logs +pkg/util/validation/field +pkg/util/workqueue +pkg/volume +pkg/volume/downwardapi +pkg/volume/util/nestedpendingoperations +pkg/volume/util/operationexecutor +pkg/volume/util/types +pkg/volume/util/volumehelper +pkg/watch/json +pkg/watch/versioned +plugin/cmd/kube-scheduler +plugin/cmd/kube-scheduler/app/options +plugin/pkg/admission/admit +plugin/pkg/admission/alwayspullimages +plugin/pkg/admission/deny +plugin/pkg/admission/exec +plugin/pkg/admission/namespace/autoprovision +plugin/pkg/admission/namespace/exists +plugin/pkg/admission/securitycontext/scdeny +plugin/pkg/auth +plugin/pkg/auth/authenticator +plugin/pkg/auth/authenticator/password +plugin/pkg/auth/authenticator/password/allow +plugin/pkg/auth/authenticator/request/basicauth +plugin/pkg/auth/authenticator/request/union +plugin/pkg/auth/authorizer +plugin/pkg/client/auth +plugin/pkg/client/auth/gcp +test/e2e/cleanup +test/e2e/generated +test/e2e/perftype +test/images/clusterapi-tester +test/images/entrypoint-tester +test/images/fakegitserver +test/images/goproxy +test/images/mount-tester +test/images/n-way-http +test/images/porter +test/images/port-forward-tester +test/images/resource-consumer/consume-cpu +test/images/serve_hostname +test/integration/openshift +test/soak/cauldron +test/soak/serve_hostnames +third_party/forked/golang/expansion diff --git a/hack/verify-golint.sh b/hack/verify-golint.sh new file mode 100755 index 0000000000..e1d4568e02 --- /dev/null +++ b/hack/verify-golint.sh @@ -0,0 +1,94 @@ +#!/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/lib/init.sh" + +kube::golang::verify_go_version + +cd "${KUBE_ROOT}" + +array_contains () { + local seeking=$1; shift # shift will iterate through the array + local in=1 # in holds the exit status for the function + for element; do + if [[ "$element" == "$seeking" ]]; then + in=0 # set in to 0 since we found it + break + fi + done + return $in +} + +export IFS=$'\n' +all_packages=( + $(go list -e ./... | egrep -v "/(third_party|vendor|staging|generated|clientset_generated)" | sed 's/k8s.io\/kubernetes\///g') +) +linted_file="${KUBE_ROOT}/hack/.linted_packages" +linted_packages=( + $(cat $linted_file) +) +unset IFS +linted=() +errors=() +for p in "${all_packages[@]}"; do + # Run golint on package/*.go file explicitly to validate all go files + # and not just the ones for the current platform. + failedLint=$(golint "$p"/*.go) + if [ "$failedLint" ]; then + if array_contains "$p" "${linted_packages[@]}"; then + errors+=( "$failedLint" ) + fi + else + array_contains "$p" "${linted_packages[@]}" || linted+=( "$p" ) + fi +done + +# Check to be sure all the packages that should pass lint are. +if [ ${#errors[@]} -eq 0 ]; then + echo 'Congratulations! All Go source files have been linted.' +else + { + echo "Errors from golint:" + for err in "${errors[@]}"; do + echo "$err" + done + echo + echo 'Please fix the above errors. You can test via "golint" and commit the result.' + echo + } >&2 + false +fi + +# check to make sure all packages that pass lint are in the linted file. +if [ ${#linted[@]} -eq 0 ]; then + echo 'Success! All packages that should pass lint are listed in the linted file.' +else + { + echo "The following packages passed golint but are not listed in $linted_file:" + for p in "${linted[@]}"; do + echo "echo $p >> hack/.linted_packages" + done + echo + echo 'Please add the following packages to the linted file. You can test via this script and commit the result.' + echo + } >&2 + false +fi