diff --git a/Makefile b/Makefile index ffb3e847b9c..e21ae1ece95 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,8 @@ META_DIR := .make KUBE_GOFLAGS := $(GOFLAGS) KUBE_GOLDFLAGS := $(GOLDFLAGS) +KUBE_VERBOSE ?= 1 + GOGCFLAGS ?= BRANCH ?= KUBE_GOGCFLAGS = $(GOGCFLAGS) diff --git a/Makefile.generated_files b/Makefile.generated_files index 55c5e115470..f8848f0d811 100644 --- a/Makefile.generated_files +++ b/Makefile.generated_files @@ -209,6 +209,7 @@ DEEPCOPY_FILES := $(addsuffix /$(DEEPCOPY_FILENAME), $(DEEPCOPY_DIRS)) gen_deepcopy: $(DEEPCOPY_FILES) if [[ -f $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \ ./hack/run-in-gopath.sh $(DEEPCOPY_GEN) \ + --v $(KUBE_VERBOSE) \ -i $$(cat $(META_DIR)/$(DEEPCOPY_GEN).todo | paste -sd, -) \ --bounding-dirs $(PRJ_SRC_PATH) \ -O $(DEEPCOPY_BASENAME); \ @@ -323,6 +324,7 @@ CONVERSION_FILES := $(addsuffix /$(CONVERSION_FILENAME), $(CONVERSION_DIRS)) gen_conversion: $(CONVERSION_FILES) if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \ ./hack/run-in-gopath.sh $(CONVERSION_GEN) \ + --v $(KUBE_VERBOSE) \ -i $$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -) \ -O $(CONVERSION_BASENAME); \ fi diff --git a/cluster/lib/logging.sh b/cluster/lib/logging.sh index 6b8f0577c23..959f8474427 100644 --- a/cluster/lib/logging.sh +++ b/cluster/lib/logging.sh @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Controls verbosity of the script output and logging. +KUBE_VERBOSE="${KUBE_VERBOSE:-5}" + # Handler for when we exit automatically on an error. # Borrowed from https://gist.github.com/ahendrix/7030300 kube::log::errexit() { @@ -70,16 +73,19 @@ kube::log::error_exit() { local stack_skip="${3:-0}" stack_skip=$((stack_skip + 1)) - local source_file=${BASH_SOURCE[$stack_skip]} - local source_line=${BASH_LINENO[$((stack_skip - 1))]} - echo "!!! Error in ${source_file}:${source_line}" >&2 - [[ -z ${1-} ]] || { - echo " ${1}" >&2 - } + if [[ ${KUBE_VERBOSE} -ge 4 ]]; then + local source_file=${BASH_SOURCE[$stack_skip]} + local source_line=${BASH_LINENO[$((stack_skip - 1))]} + echo "!!! Error in ${source_file}:${source_line}" >&2 + [[ -z ${1-} ]] || { + echo " ${1}" >&2 + } - kube::log::stack $stack_skip + kube::log::stack $stack_skip + + echo "Exiting with status ${code}" >&2 + fi - echo "Exiting with status ${code}" >&2 exit "${code}" } @@ -114,6 +120,11 @@ kube::log::usage_from_stdin() { # Print out some info that isn't a top level status line kube::log::info() { + local V="${V:-0}" + if [[ $KUBE_VERBOSE < $V ]]; then + return + fi + for message; do echo "$message" done @@ -137,6 +148,11 @@ kube::log::info_from_stdin() { # Print a status line. Formatted to show up in a stream of output. kube::log::status() { + local V="${V:-0}" + if [[ $KUBE_VERBOSE < $V ]]; then + return + fi + timestamp=$(date +"[%m%d %H:%M:%S]") echo "+++ $timestamp $1" shift diff --git a/cmd/libs/go2idl/conversion-gen/main.go b/cmd/libs/go2idl/conversion-gen/main.go index 33a4001370e..e4e8434f1ee 100644 --- a/cmd/libs/go2idl/conversion-gen/main.go +++ b/cmd/libs/go2idl/conversion-gen/main.go @@ -70,5 +70,5 @@ func main() { ); err != nil { glog.Fatalf("Error: %v", err) } - glog.Info("Completed successfully.") + glog.V(2).Info("Completed successfully.") } diff --git a/cmd/libs/go2idl/deepcopy-gen/main.go b/cmd/libs/go2idl/deepcopy-gen/main.go index 057bdc76fb8..b1c9fa0271d 100644 --- a/cmd/libs/go2idl/deepcopy-gen/main.go +++ b/cmd/libs/go2idl/deepcopy-gen/main.go @@ -75,5 +75,5 @@ func main() { ); err != nil { glog.Fatalf("Error: %v", err) } - glog.Info("Completed successfully.") + glog.V(2).Info("Completed successfully.") } diff --git a/cmd/libs/go2idl/generator/execute.go b/cmd/libs/go2idl/generator/execute.go index 5f822a6c8f9..eedbfdaa21f 100644 --- a/cmd/libs/go2idl/generator/execute.go +++ b/cmd/libs/go2idl/generator/execute.go @@ -64,7 +64,7 @@ type DefaultFileType struct { } func (ft DefaultFileType) AssembleFile(f *File, pathname string) error { - glog.V(0).Infof("Assembling file %q", pathname) + glog.V(2).Infof("Assembling file %q", pathname) destFile, err := os.Create(pathname) if err != nil { return err @@ -91,7 +91,7 @@ func (ft DefaultFileType) AssembleFile(f *File, pathname string) error { } func (ft DefaultFileType) VerifyFile(f *File, pathname string) error { - glog.V(0).Infof("Verifying file %q", pathname) + glog.V(2).Infof("Verifying file %q", pathname) friendlyName := filepath.Join(f.PackageName, f.Name) b := &bytes.Buffer{} et := NewErrorTracker(b) @@ -211,7 +211,7 @@ func (c *Context) addNameSystems(namers namer.NameSystems) *Context { // import path already, this will be appended to 'outDir'. func (c *Context) ExecutePackage(outDir string, p Package) error { path := filepath.Join(outDir, p.Path()) - glog.V(0).Infof("Processing package %q, disk location %q", p.Name(), path) + glog.V(2).Infof("Processing package %q, disk location %q", p.Name(), path) // Filter out any types the *package* doesn't care about. packageContext := c.filteredBy(p.Filter) os.MkdirAll(path, 0755) diff --git a/cmd/libs/go2idl/import-boss/generators/import_restrict.go b/cmd/libs/go2idl/import-boss/generators/import_restrict.go index 81818057b93..8e27e20ccfb 100644 --- a/cmd/libs/go2idl/import-boss/generators/import_restrict.go +++ b/cmd/libs/go2idl/import-boss/generators/import_restrict.go @@ -214,7 +214,7 @@ func (importRuleFile) VerifyFile(f *generator.File, path string) error { } found := false for _, allowed := range r.AllowedPrefixes { - glog.V(0).Infof("Checking %v against %v\n", v, allowed) + glog.V(4).Infof("Checking %v against %v\n", v, allowed) if strings.HasPrefix(v, allowed) { found = true break @@ -226,7 +226,7 @@ func (importRuleFile) VerifyFile(f *generator.File, path string) error { } } if len(rules.Rules) > 0 { - glog.V(0).Infof("%v passes rules found in %v\n", path, actualPath) + glog.V(2).Infof("%v passes rules found in %v\n", path, actualPath) } return nil diff --git a/cmd/libs/go2idl/import-boss/main.go b/cmd/libs/go2idl/import-boss/main.go index 7e587cc6e68..9162744718d 100644 --- a/cmd/libs/go2idl/import-boss/main.go +++ b/cmd/libs/go2idl/import-boss/main.go @@ -84,5 +84,5 @@ func main() { glog.Errorf("Error: %v", err) os.Exit(1) } - glog.Info("Completed successfully.") + glog.V(2).Info("Completed successfully.") } diff --git a/cmd/libs/go2idl/set-gen/main.go b/cmd/libs/go2idl/set-gen/main.go index bd8cae26a9d..1ac88cfb7e8 100644 --- a/cmd/libs/go2idl/set-gen/main.go +++ b/cmd/libs/go2idl/set-gen/main.go @@ -49,5 +49,5 @@ func main() { glog.Errorf("Error: %v", err) os.Exit(1) } - glog.Info("Completed successfully.") + glog.V(2).Info("Completed successfully.") } diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index f0397b5c542..9c487d869a4 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -367,7 +367,7 @@ kube::golang::place_bins() { local host_platform host_platform=$(kube::golang::host_platform) - kube::log::status "Placing binaries" + V=2 kube::log::status "Placing binaries" local platform for platform in "${KUBE_CLIENT_PLATFORMS[@]}"; do @@ -598,7 +598,7 @@ kube::golang::build_binaries() { ( # Check for `go` binary and set ${GOPATH}. kube::golang::setup_env - echo "Go version: $(go version)" + V=2 kube::log::info "Go version: $(go version)" local host_platform host_platform=$(kube::golang::host_platform) diff --git a/hack/make-rules/build.sh b/hack/make-rules/build.sh index 85f5cbe69e7..472151af118 100755 --- a/hack/make-rules/build.sh +++ b/hack/make-rules/build.sh @@ -21,6 +21,7 @@ set -o nounset set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +KUBE_VERBOSE="${KUBE_VERBOSE:-1}" source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::build_binaries "$@" diff --git a/hack/update-bindata.sh b/hack/update-bindata.sh index eeed2f60340..f021bfca286 100755 --- a/hack/update-bindata.sh +++ b/hack/update-bindata.sh @@ -23,6 +23,8 @@ if [[ -z "${KUBE_ROOT:-}" ]]; then KUBE_ROOT="../../../" fi +source "${KUBE_ROOT}/cluster/lib/logging.sh" + if [[ ! -d "${KUBE_ROOT}/examples" ]]; then echo "${KUBE_ROOT}/examples not detected. This script should be run from a location where the source dirs are available." exit 1 @@ -44,4 +46,4 @@ go-bindata -nometadata -prefix "${KUBE_ROOT}" -o ${BINDATA_OUTPUT} -pkg generate gofmt -s -w ${BINDATA_OUTPUT} -echo "Generated bindata file : $(wc -l ${BINDATA_OUTPUT}) lines of lovely automated artifacts" +V=2 kube::log::info "Generated bindata file : $(wc -l ${BINDATA_OUTPUT}) lines of lovely automated artifacts" diff --git a/hack/verify-flags/exceptions.txt b/hack/verify-flags/exceptions.txt index a27cf2534ae..e8b075b9ddc 100644 --- a/hack/verify-flags/exceptions.txt +++ b/hack/verify-flags/exceptions.txt @@ -25,7 +25,7 @@ cluster/juju/layers/kubernetes/reactive/k8s.py: client_key = '/srv/kubernetes cluster/juju/layers/kubernetes/reactive/k8s.py: cluster_name = 'kubernetes' cluster/juju/layers/kubernetes/reactive/k8s.py: tlslib.client_key(None, client_key, user='ubuntu', group='ubuntu') cluster/lib/logging.sh: local source_file=${BASH_SOURCE[$frame_no]} -cluster/lib/logging.sh: local source_file=${BASH_SOURCE[$stack_skip]} +cluster/lib/logging.sh: local source_file=${BASH_SOURCE[$stack_skip]} cluster/log-dump.sh: for node_name in "${NODE_NAMES[@]}"; do cluster/log-dump.sh: local -r node_name="${1}" cluster/log-dump.sh:readonly report_dir="${1:-_artifacts}"