Skip to content

Commit

Permalink
Dump contents of etcd v3 using the etcdhelper tool
Browse files Browse the repository at this point in the history
When we are running tests with etcd v3 enabled, the `curl` approach to
recursively dumping contents from etcd will not work, even with the
correct keyspace, as the contents are encoded in protobuf. The
`etcdhelper` tool allows us to make a plain-text dump of the full
contents.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
Signed-off-by: Monis Khan <mkhan@redhat.com>
  • Loading branch information
stevekuznetsov authored and enj committed May 17, 2017
1 parent 5693891 commit c60806d
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions hack/lib/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,40 @@ readonly -f os::cleanup::all
# None
function os::cleanup::dump_etcd() {
if [[ -n "${API_SCHEME:-}" && -n "${API_HOST:-}" && -n "${ETCD_PORT:-}" ]]; then
os::log::info "[CLEANUP] Dumping etcd contents to $( os::util::repository_relative_path "${ARTIFACT_DIR}/etcd_dump.json" )"
os::util::curl_etcd "/v2/keys/?recursive=true" > "${ARTIFACT_DIR}/etcd_dump.json"
local dump_dir="${ARTIFACT_DIR}/etcd"
mkdir -p "${dump_dir}"
os::log::info "[CLEANUP] Dumping etcd contents to $( os::util::repository_relative_path "${dump_dir}" )"
os::util::curl_etcd "/v2/keys/?recursive=true" > "${dump_dir}/v2_dump.json"
os::cleanup::internal::dump_etcd_v3 > "${dump_dir}/v3_dump.json"
fi
}
readonly -f os::cleanup::dump_etcd

# os::cleanup::internal::dump_etcd_v3 dumps the full contents of etcd v3 to a file.
#
# Globals:
# - ARTIFACT_DIR
# - API_SCHEME
# - API_HOST
# - ETCD_PORT
# Arguments:
# None
# Returns:
# None
function os::cleanup::internal::dump_etcd_v3() {
local full_url="${API_SCHEME}://${API_HOST}:${ETCD_PORT}"

local etcd_client_cert="${MASTER_CONFIG_DIR}/master.etcd-client.crt"
local etcd_client_key="${MASTER_CONFIG_DIR}/master.etcd-client.key"
local ca_bundle="${MASTER_CONFIG_DIR}/ca-bundle.crt"

os::util::ensure::built_binary_exists 'etcdhelper' >&2

etcdhelper --cert "${etcd_client_cert}" --key "${etcd_client_key}" \
--cacert "${ca_bundle}" --endpoint "${full_url}" dump
}
readonly -f os::cleanup::internal::dump_etcd_v3

# os::cleanup::prune_etcd removes the etcd data store from disk.
#
# Globals:
Expand Down Expand Up @@ -308,4 +336,4 @@ function os::cleanup::processes() {
${USE_SUDO:+sudo} kill "${job}" &> /dev/null
done
}
readonly -f os::cleanup::processes
readonly -f os::cleanup::processes

0 comments on commit c60806d

Please sign in to comment.