-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathenv.sh
executable file
·104 lines (78 loc) · 2.12 KB
/
env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -euo pipefail
# -----------------------------------------------------------------------------
# usage
usage() {
cat << EOF
Print out the helm environment.
Usage:
helm env [OPTIONS]
Options:
--vars-only only print environment variables
-q, --quiet don't print headers
EOF
exit
}
# -----------------------------------------------------------------------------
# rule
#
# Print a horizontal line the width of the terminal.
rule() {
local cols="${COLUMNS:-$(tput cols)}"
local char=$'\u2500'
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
}
# -----------------------------------------------------------------------------
# header
#
# Print step header text in a consistent way
header() {
if [[ "${QUIET}" ]]; then
return
fi
# If called with no args, assume the key is the caller's function name
local msg="$*"
printf "\n%s[%s]\n\n" "$(rule)" "${msg}"
}
# -----------------------------------------------------------------------------
# print_helm_envars
#
# Print helm related environment variables.
print_helm_envars() {
header "Helm environment"
env | sort | grep -e HELM_ -e TILLER_ -e KUBE_
}
# -----------------------------------------------------------------------------
# print_kubectl_config
#
# Print pertinent values from kubectl config.
print_kubectl_config() {
header "kubectl config"
local current_context server
current_context=$(kubectl config current-context)
server=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
cat << EOF
current-context: ${current_context}
server: ${server}
EOF
}
# -----------------------------------------------------------------------------
# parse command line options
ENVARS_ONLY=
QUIET=
while [[ $# -ne 0 ]]; do
case "$1" in
--vars-only) ENVARS_ONLY=1 ;;
--quiet|-q) QUIET=1 ;;
-*) usage "Unrecognized command line argument $1" ;;
*) break;
esac
shift
done
# -----------------------------------------------------------------------------
# main
print_helm_envars
if [[ ${ENVARS_ONLY} ]]; then
exit
fi
print_kubectl_config