diff --git a/Makefile b/Makefile index ffb3e847b9c24..e21ae1ece952c 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 55c5e11547083..f8848f0d811c7 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 6b8f0577c232b..959f8474427c1 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/hack/lib/golang.sh b/hack/lib/golang.sh index f0397b5c542f9..9c487d869a4f0 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 85f5cbe69e717..472151af118c4 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 eeed2f603400d..f021bfca2865e 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 2eede332961fa..aebe015e9d3b9 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}"