16
16
17
17
# A set of helpers for starting/running etcd for tests
18
18
19
- ETCD_VERSION=${ETCD_VERSION:- 3.5.0 }
19
+ ETCD_VERSION=${ETCD_VERSION:- 3.5.7 }
20
20
ETCD_HOST=${ETCD_HOST:- 127.0.0.1}
21
21
ETCD_PORT=${ETCD_PORT:- 2379}
22
+ # This is intentionally not called ETCD_LOG_LEVEL:
23
+ # etcd checks that and compains when it is set in addition
24
+ # to the command line argument, even when both have the same value.
25
+ ETCD_LOGLEVEL=${ETCD_LOGLEVEL:- warn}
22
26
export KUBE_INTEGRATION_ETCD_URL=" http://${ETCD_HOST} :${ETCD_PORT} "
23
27
24
28
kube::etcd::validate () {
@@ -29,25 +33,39 @@ kube::etcd::validate() {
29
33
exit 1
30
34
}
31
35
32
- # validate if etcd is running and $ETCD_PORT is in use
33
- if ps -ef | grep " etcd " | grep ${ETCD_PORT} & > /dev/null; then
36
+ # validate etcd port is free
37
+ local port_check_command
38
+ if command -v ss & > /dev/null && ss -Version | grep ' iproute2' & > /dev/null; then
39
+ port_check_command=" ss"
40
+ elif command -v netstat & > /dev/null; then
41
+ port_check_command=" netstat"
42
+ else
43
+ kube::log::usage " unable to identify if etcd is bound to port ${ETCD_PORT} . unable to find ss or netstat utilities."
44
+ exit 1
45
+ fi
46
+ if ${port_check_command} -nat | grep " LISTEN" | grep " [\.:]${ETCD_PORT:? } " > /dev/null 2>&1 ; then
34
47
kube::log::usage " unable to start etcd as port ${ETCD_PORT} is in use. please stop the process listening on this port and retry."
48
+ kube::log::usage " $( netstat -nat | grep " [\.:]${ETCD_PORT:? } .*LISTEN" ) "
35
49
exit 1
36
50
fi
37
51
38
52
# need set the env of "ETCD_UNSUPPORTED_ARCH" on unstable arch.
39
53
arch=$( uname -m)
40
- if [[ $arch =~ aarch* ]]; then
41
- export ETCD_UNSUPPORTED_ARCH=arm64
42
- elif [[ $arch =~ arm* ]]; then
54
+ if [[ $arch =~ arm* ]]; then
43
55
export ETCD_UNSUPPORTED_ARCH=arm
44
56
fi
45
57
# validate installed version is at least equal to minimum
46
58
version=$( etcd --version | grep Version | head -n 1 | cut -d " " -f 3)
47
59
if [[ $( kube::etcd::version " ${ETCD_VERSION} " ) -gt $( kube::etcd::version " ${version} " ) ]]; then
60
+ export PATH=${KUBE_ROOT} /third_party/etcd:${PATH}
61
+ hash etcd
62
+ echo " ${PATH} "
63
+ version=$( etcd --version | grep Version | head -n 1 | cut -d " " -f 3)
64
+ if [[ $( kube::etcd::version " ${ETCD_VERSION} " ) -gt $( kube::etcd::version " ${version} " ) ]]; then
48
65
kube::log::usage " etcd version ${ETCD_VERSION} or greater required."
49
- kube::log::info " You can use 'hack/install-etcd.sh' to install."
66
+ kube::log::info " You can use 'hack/install-etcd.sh' to install a copy in third_party/ ."
50
67
exit 1
68
+ fi
51
69
fi
52
70
}
53
71
@@ -66,16 +84,48 @@ kube::etcd::start() {
66
84
else
67
85
ETCD_LOGFILE=${ETCD_LOGFILE:- " /dev/null" }
68
86
fi
69
- kube::log::info " etcd --advertise-client-urls ${KUBE_INTEGRATION_ETCD_URL} --data-dir ${ETCD_DIR} --listen-client-urls http://${ETCD_HOST} :${ETCD_PORT} --log-level=debug > \" ${ETCD_LOGFILE} \" 2 >/dev/null"
70
- etcd --advertise-client-urls " ${KUBE_INTEGRATION_ETCD_URL} " --data-dir " ${ETCD_DIR} " --listen-client-urls " ${KUBE_INTEGRATION_ETCD_URL} " --log-level=debug 2> " ${ETCD_LOGFILE} " > /dev/null &
87
+ kube::log::info " etcd --advertise-client-urls ${KUBE_INTEGRATION_ETCD_URL} --data-dir ${ETCD_DIR} --listen-client-urls http://${ETCD_HOST} :${ETCD_PORT} --log-level=${ETCD_LOGLEVEL} 2 > \" ${ETCD_LOGFILE} \" >/dev/null"
88
+ etcd --advertise-client-urls " ${KUBE_INTEGRATION_ETCD_URL} " --data-dir " ${ETCD_DIR} " --listen-client-urls " ${KUBE_INTEGRATION_ETCD_URL} " --log-level=" ${ETCD_LOGLEVEL} " 2> " ${ETCD_LOGFILE} " > /dev/null &
71
89
ETCD_PID=$!
72
90
73
91
echo " Waiting for etcd to come up."
74
92
kube::util::wait_for_url " ${KUBE_INTEGRATION_ETCD_URL} /health" " etcd: " 0.25 80
75
93
curl -fs -X POST " ${KUBE_INTEGRATION_ETCD_URL} /v3/kv/put" -d ' {"key": "X3Rlc3Q=", "value": ""}'
76
94
}
77
95
96
+ kube::etcd::start_scraping () {
97
+ if [[ -d " ${ARTIFACTS:- } " ]]; then
98
+ ETCD_SCRAPE_DIR=" ${ARTIFACTS} /etcd-scrapes"
99
+ else
100
+ ETCD_SCRAPE_DIR=$( mktemp -d -t test.XXXXXX) /etcd-scrapes
101
+ fi
102
+ kube::log::info " Periodically scraping etcd to ${ETCD_SCRAPE_DIR} ."
103
+ mkdir -p " ${ETCD_SCRAPE_DIR} "
104
+ (
105
+ while sleep 30; do
106
+ kube::etcd::scrape
107
+ done
108
+ ) &
109
+ ETCD_SCRAPE_PID=$!
110
+ }
111
+
112
+ kube::etcd::scrape () {
113
+ curl -s -S " ${KUBE_INTEGRATION_ETCD_URL} /metrics" > " ${ETCD_SCRAPE_DIR} /next" && mv " ${ETCD_SCRAPE_DIR} /next" " ${ETCD_SCRAPE_DIR} /$( date +%s) .scrape"
114
+ }
115
+
116
+
78
117
kube::etcd::stop () {
118
+ if [[ -n " ${ETCD_SCRAPE_PID:- } " ]] && [[ -n " ${ETCD_SCRAPE_DIR:- } " ]] ; then
119
+ kill " ${ETCD_SCRAPE_PID} " & > /dev/null || :
120
+ wait " ${ETCD_SCRAPE_PID} " & > /dev/null || :
121
+ kube::etcd::scrape || :
122
+ (
123
+ # shellcheck disable=SC2015
124
+ cd " ${ETCD_SCRAPE_DIR} " /.. && \
125
+ tar czf etcd-scrapes.tgz etcd-scrapes && \
126
+ rm -rf etcd-scrapes || :
127
+ )
128
+ fi
79
129
if [[ -n " ${ETCD_PID-} " ]]; then
80
130
kill " ${ETCD_PID} " & > /dev/null || :
81
131
wait " ${ETCD_PID} " & > /dev/null || :
@@ -100,27 +150,30 @@ kube::etcd::install() {
100
150
101
151
os=$( kube::util::host_os)
102
152
arch=$( kube::util::host_arch)
103
-
153
+ mkdir -p ${KUBE_ROOT} /third_party
154
+ cd " ${KUBE_ROOT} /third_party" || return 1
104
155
if [[ $( readlink etcd) == etcd-v${ETCD_VERSION} -${os} -* ]]; then
105
156
kube::log::info " etcd v${ETCD_VERSION} already installed. To use:"
106
157
kube::log::info " export PATH=\" $( pwd) /etcd:\$ {PATH}\" "
107
158
return # already installed
108
159
fi
109
160
110
161
if [[ ${os} == " darwin" ]]; then
111
- download_file=" etcd-v${ETCD_VERSION} -darwin-amd64 .zip"
112
- url=" https://github.com/etcd-io /etcd/releases/download/v${ETCD_VERSION} /${download_file} "
162
+ download_file=" etcd-v${ETCD_VERSION} -${os} - ${arch} .zip"
163
+ url=" https://github.com/coreos /etcd/releases/download/v${ETCD_VERSION} /${download_file} "
113
164
kube::util::download_file " ${url} " " ${download_file} "
114
165
unzip -o " ${download_file} "
115
- ln -fns " etcd-v${ETCD_VERSION} -darwin-amd64 " etcd
166
+ ln -fns " etcd-v${ETCD_VERSION} -${os} - ${arch} " etcd
116
167
rm " ${download_file} "
117
- else
118
- url=" https://github.com/etcd-io /etcd/releases/download/v${ETCD_VERSION} /etcd-v${ETCD_VERSION} -linux -${arch} .tar.gz"
119
- download_file=" etcd-v${ETCD_VERSION} -linux -${arch} .tar.gz"
168
+ elif [[ ${os} == " linux " ]] ; then
169
+ url=" https://github.com/coreos /etcd/releases/download/v${ETCD_VERSION} /etcd-v${ETCD_VERSION} -${os} -${arch} .tar.gz"
170
+ download_file=" etcd-v${ETCD_VERSION} -${os} -${arch} .tar.gz"
120
171
kube::util::download_file " ${url} " " ${download_file} "
121
172
tar xzf " ${download_file} "
122
- ln -fns " etcd-v${ETCD_VERSION} -linux -${arch} " etcd
173
+ ln -fns " etcd-v${ETCD_VERSION} -${os} -${arch} " etcd
123
174
rm " ${download_file} "
175
+ else
176
+ kube::log::info " ${os} is NOT supported."
124
177
fi
125
178
kube::log::info " etcd v${ETCD_VERSION} installed. To use:"
126
179
kube::log::info " export PATH=\" $( pwd) /etcd:\$ {PATH}\" "
0 commit comments