mirror of https://github.com/k3s-io/k3s.git
Add a verbosity concept to kubernetes scripts
The KUBE_VERBOSE environment variable sets the verbosity level to use. Log messages can specify a verbosity by setting the V variable. e.g. V=2 kube::log::info foo bar Would only print "foo bar" if $KUBE_VERBOSE >= 2.pull/6/head
parent
07b650e165
commit
9abdf719b8
2
Makefile
2
Makefile
|
@ -49,6 +49,8 @@ META_DIR := .make
|
|||
KUBE_GOFLAGS := $(GOFLAGS)
|
||||
KUBE_GOLDFLAGS := $(GOLDFLAGS)
|
||||
|
||||
KUBE_VERBOSE ?= 1
|
||||
|
||||
GOGCFLAGS ?=
|
||||
BRANCH ?=
|
||||
KUBE_GOGCFLAGS = $(GOGCFLAGS)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 "$@"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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}"
|
||||
|
|
Loading…
Reference in New Issue