Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactivate golint in staging #40303

Merged
merged 3 commits into from Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 26 additions & 61 deletions hack/.linted_packages
Expand Up @@ -8,7 +8,6 @@ cmd/genkubedocs
cmd/genman
cmd/genswaggertypedocs
cmd/genyaml
cmd/integration
cmd/kube-aggregator
cmd/kube-aggregator/pkg/apis/apiregistration/install
cmd/kube-aggregator/pkg/client/informers
Expand All @@ -25,7 +24,6 @@ cmd/kube-controller-manager/app/options
cmd/kube-discovery
cmd/kube-proxy
cmd/kubeadm
cmd/kubeadm
cmd/kubeadm/app/apis/kubeadm/install
cmd/kubeadm/app/phases/apiconfig
cmd/kubeadm/app/phases/certs
Expand All @@ -34,24 +32,17 @@ cmd/kubelet
cmd/libs/go2idl/client-gen
cmd/libs/go2idl/client-gen/generators
cmd/libs/go2idl/client-gen/test_apis/testgroup/install
cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/internalversion
cmd/libs/go2idl/conversion-gen
cmd/libs/go2idl/deepcopy-gen
cmd/libs/go2idl/defaulter-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/informer-gen
cmd/libs/go2idl/lister-gen
cmd/libs/go2idl/openapi-gen
cmd/libs/go2idl/parser
cmd/libs/go2idl/set-gen
cmd/libs/go2idl/set-gen/generators
cmd/linkcheck
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
Expand All @@ -75,11 +66,9 @@ pkg/api/resource
pkg/api/service
pkg/api/v1
pkg/api/v1/service
pkg/apimachinery
pkg/apis/abac/v0
pkg/apis/abac/v1beta1
pkg/apis/apps/install
pkg/apis/authentication.k8s.io/install
pkg/apis/authentication/install
pkg/apis/authorization/install
pkg/apis/autoscaling/install
Expand All @@ -97,8 +86,6 @@ pkg/apis/rbac/install
pkg/apis/rbac/v1alpha1
pkg/apis/storage/install
pkg/apis/storage/validation
pkg/auth/authenticator
pkg/auth/authorizer/union
pkg/client/cache
pkg/client/conditions
pkg/client/informers/informers_generated/apps
Expand Down Expand Up @@ -131,7 +118,6 @@ pkg/client/informers/informers_generated/storage
pkg/client/informers/informers_generated/storage/internalversion
pkg/client/informers/informers_generated/storage/v1beta1
pkg/client/listers/apps/internalversion
pkg/client/listers/apps/v1alpha1
pkg/client/listers/apps/v1beta1
pkg/client/listers/authentication/internalversion
pkg/client/listers/authentication/v1beta1
Expand Down Expand Up @@ -160,34 +146,23 @@ pkg/client/listers/storage/internalversion
pkg/client/listers/storage/v1beta1
pkg/client/metrics
pkg/client/metrics/prometheus
pkg/client/restclient/watch
pkg/client/testing/core
pkg/client/typed/discovery
pkg/client/unversioned
pkg/client/unversioned/adapters/internalclientset
pkg/client/unversioned/auth
pkg/client/unversioned/remotecommand
pkg/cloudprovider/providers
pkg/cloudprovider/providers/azure
pkg/cloudprovider/providers/cloudstack
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
pkg/conversion/queryparams
pkg/credentialprovider/aws
pkg/fields
pkg/genericapiserver
pkg/genericapiserver/endpoints/audit
pkg/genericapiserver/endpoints/handlers/responsewriters
pkg/genericapiserver/endpoints/openapi
pkg/genericapiserver/endpoints/request
pkg/genericapiserver/registry
pkg/genericapiserver/server/filters
pkg/genericapiserver/server/mux
Expand All @@ -197,14 +172,9 @@ pkg/kubelet/api
pkg/kubelet/container
pkg/kubelet/envvars
pkg/kubelet/eviction
pkg/kubelet/sysctls
pkg/kubelet/util/csr
pkg/kubelet/util/format
pkg/kubelet/util/ioutils
pkg/kubelet/volume
pkg/kubelet/volume/cache
pkg/kubelet/volume/populator
pkg/kubelet/volume/reconciler
pkg/kubelet/volumemanager
pkg/kubelet/volumemanager/cache
pkg/kubelet/volumemanager/populator
Expand All @@ -216,9 +186,6 @@ pkg/quota
pkg/quota/install
pkg/registry
pkg/registry/authorization/util
pkg/registry/clusterrole/storage
pkg/registry/clusterrolebinding/storage
pkg/registry/configmap/storage
pkg/registry/core/configmap/storage
pkg/registry/core/endpoint
pkg/registry/core/node/rest
Expand All @@ -227,34 +194,20 @@ pkg/registry/core/rangeallocation
pkg/registry/core/service/ipallocator/controller
pkg/registry/core/service/ipallocator/storage
pkg/registry/core/serviceaccount
pkg/registry/endpoint
pkg/registry/extensions/podsecuritypolicy/storage
pkg/registry/extensions/thirdpartyresource
pkg/registry/extensions/thirdpartyresource/storage
pkg/registry/node/rest
pkg/registry/pod/storage
pkg/registry/podsecuritypolicy/storage
pkg/registry/rangeallocation
pkg/registry/rbac/clusterrole/storage
pkg/registry/rbac/clusterrolebinding/storage
pkg/registry/rbac/role/storage
pkg/registry/rbac/rolebinding/storage
pkg/registry/role/storage
pkg/registry/rolebinding/storage
pkg/registry/service/ipallocator/controller
pkg/registry/service/ipallocator/storage
pkg/registry/serviceaccount
pkg/registry/thirdpartyresource
pkg/registry/thirdpartyresource/storage
pkg/runtime
pkg/runtime/serializer
pkg/runtime/serializer/json
pkg/runtime/serializer/protobuf
pkg/runtime/serializer/recognizer
pkg/runtime/serializer/recognizer/testing
pkg/runtime/serializer/streaming
pkg/runtime/serializer/versioning
pkg/runtime/serializer/yaml
pkg/security
pkg/security/podsecuritypolicy/apparmor
pkg/security/podsecuritypolicy/capabilities
Expand All @@ -265,15 +218,11 @@ pkg/storage/etcd3
pkg/storage/storagebackend/factory
pkg/types
pkg/util/async
pkg/util/cert
pkg/util/codeinspector
pkg/util/errors
pkg/util/flock
pkg/util/flushwriter
pkg/util/framer
pkg/util/goroutinemap
pkg/util/hash
pkg/util/homedir
pkg/util/i18n
pkg/util/interrupt
pkg/util/io
Expand All @@ -285,9 +234,6 @@ pkg/util/metrics
pkg/util/net
pkg/util/netsh
pkg/util/rand
pkg/util/ratelimit
pkg/util/replicaset
pkg/util/restoptions
pkg/util/runtime
pkg/util/sets
pkg/util/tail
Expand Down Expand Up @@ -324,14 +270,34 @@ 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/authenticator/request/x509
plugin/pkg/auth/authorizer
plugin/pkg/auth/authorizer/rbac/bootstrappolicy
plugin/pkg/client/auth
plugin/pkg/client/auth/gcp
test/e2e/cleanup
test/e2e/generated
staging/src/k8s.io/apimachinery/pkg/api/errors
staging/src/k8s.io/apimachinery/pkg/apimachinery
staging/src/k8s.io/apimachinery/pkg/conversion/queryparams
staging/src/k8s.io/apimachinery/pkg/runtime
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/testing
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/yaml
staging/src/k8s.io/apimachinery/pkg/util/json
staging/src/k8s.io/apimachinery/pkg/util/validation/field
staging/src/k8s.io/apimachinery/pkg/version
staging/src/k8s.io/apimachinery/pkg/watch
staging/src/k8s.io/apiserver/pkg/authentication/authenticator
staging/src/k8s.io/apiserver/pkg/authentication/request/union
staging/src/k8s.io/apiserver/pkg/authentication/request/x509
staging/src/k8s.io/apiserver/pkg/authorization/union
staging/src/k8s.io/apiserver/pkg/endpoints/request
staging/src/k8s.io/apiserver/pkg/server
staging/src/k8s.io/apiserver/pkg/storage/names
staging/src/k8s.io/apiserver/pkg/util/flushwriter
staging/src/k8s.io/client-go/discovery
staging/src/k8s.io/client-go/plugin/pkg/client/auth
staging/src/k8s.io/client-go/plugin/pkg/client/auth/gcp
staging/src/k8s.io/client-go/rest/watch
staging/src/k8s.io/client-go/tools/auth
staging/src/k8s.io/client-go/tools/metrics
test/e2e/perftype
test/e2e_node/runner/local
test/images/clusterapi-tester
Expand All @@ -355,4 +321,3 @@ test/integration/objectmeta
test/integration/openshift
test/soak/cauldron
test/soak/serve_hostnames
third_party/forked/golang/expansion
37 changes: 27 additions & 10 deletions hack/verify-golint.sh
Expand Up @@ -55,7 +55,7 @@ export IFS=$'\n'
# as the prefix, however if we run it outside it returns the full path of the file
# with a leading underscore. We'll need to support both scenarios for all_packages.
all_packages=(
$(go list -e ./... | egrep -v "/(third_party|vendor|staging|generated|clientset_generated)" | sed -e 's|^k8s.io/kubernetes/||' -e "s|^_${KUBE_ROOT}/\?||")
$(go list -e ./... | egrep -v "/(third_party|vendor|staging/src/k8s.io/client-go/pkg|generated|clientset_generated)" | sed -e 's|^k8s.io/kubernetes/||' -e "s|^_${KUBE_ROOT}/\?||")
)
linted_packages=(
$(cat $linted_file)
Expand All @@ -76,6 +76,12 @@ for p in "${all_packages[@]}"; do
fi
done

# Check that all linted_packages actually still exist
gone=()
for p in "${linted_packages[@]}"; do
array_contains "$p" "${all_packages[@]}" || gone+=( "$p" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More readable would be

if ! array_contains "${p}" "${all_packages[@]}"; then
    gone+=( "${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.'
Expand All @@ -94,18 +100,29 @@ fi

# check to make sure all packages that pass lint are in the linted file.
echo
if [ ${#linted[@]} -eq 0 ]; then
if [ ${#linted[@]} -eq 0 -a ${#gone[@]} -eq 0 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevekuznetsov does this do what it's supposed to do? It doesn't have to be the pinnacle of beauty, it just needs to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're running #!/bin/bash -- always use [[ over [. If using [[, use && and || for logic. If you must be POSIX compliant, use [ and -a and -o. Access to empty arrays with -o nounset is tricky but ${#array[@]} is safe.

echo 'Success! All packages that should pass lint are listed in the linted file.'
else
{
echo "Some packages passed golint but are not listed in hack/.linted_packages."
echo "Please add them in alphabetical order:"
echo
for p in "${linted[@]}"; do
echo " echo $p >> hack/.linted_packages"
done
echo " LC_ALL=C sort -o hack/.linted_packages hack/.linted_packages"
echo
if [ ${#gone[@]} -gt 0 ]; then
echo "Some packages in hack/.linted_packages do not exist anymore. Please remove them"
echo "from hack/.linted_packages:"
echo
for p in "${gone[@]}"; do
echo " $p"
done
echo
fi
if [ ${#linted[@]} -gt 0 ]; then
echo "Some packages passed golint but are not listed in hack/.linted_packages."
echo "Please add them in alphabetical order:"
echo
for p in "${linted[@]}"; do
echo " echo $p >> hack/.linted_packages"
done
echo " LC_ALL=C sort -o hack/.linted_packages hack/.linted_packages"
echo
fi
echo 'You can test via this script and commit the result.'
echo
} >&2
Expand Down