Skip to content

Instantly share code, notes, and snippets.

@miminar
Created February 27, 2019 09:23
Show Gist options
  • Save miminar/4a2321a08f16dd84c65c1223fe3de8fc to your computer and use it in GitHub Desktop.
Save miminar/4a2321a08f16dd84c65c1223fe3de8fc to your computer and use it in GitHub Desktop.
OpenShift heketi-cli helper

OpenShift heketi-cli helper

Purpose

To control OCS from inside of heketi-storage container running in an OpenShift cluster.

Prerequisites

  • OCP deployed
  • OCS deployed on top of it (converged or independent mode) ideally using the official playbooks
  • kube config in the path with an admin user for glusterfs project
  • oc client binary on the host and in the PATH

Howto

# # make sure oc knows where the kube config is
# export KUBECONFIG=$(pwd)/admin.kubeconfig
# osheketi-cli --help
# osheketi-cli topology info
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
namespaces=( default glusterfs storage )
function get_heketi_namespace() {
local n
for n in "${namespaces[@]}"; do
if oc get -n "$n" svc/heketi-storage >/dev/null 2>&1; then
echo "$n"
return 0
fi
done
return 1
}
function get_heketi_pod() {
# TODO: choose ready pod
oc get -n "${nm}" pod -l 'deploymentconfig==heketi-storage' -o name | head -n 1 | \
sed 's,^pods\?/,,'
}
function die() {
echo "$1" >&2
exit 1
}
nm="$(get_heketi_namespace)"
[[ -z "${nm:-}" ]] && die "Failed to find heketi namespace!"
token="$(oc get -n "$nm" secret heketi-storage-admin-secret -o jsonpath='{.data.key}' | base64 -d)"
[[ -z "${token:-}" ]] && die "Failed to get token for heketi's admin!"
hcmd=( heketi-cli --server http://localhost:8080 --user admin --secret "${token}" )
oc exec -n "${nm}" -t "$(get_heketi_pod)" -- "${hcmd[@]}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment