diff --git a/stx-rook-ceph-helm/debian/deb_folder/rules b/stx-rook-ceph-helm/debian/deb_folder/rules index dfae3a1..961335c 100644 --- a/stx-rook-ceph-helm/debian/deb_folder/rules +++ b/stx-rook-ceph-helm/debian/deb_folder/rules @@ -4,6 +4,8 @@ export DH_VERBOSE = 1 export ROOT = debian/tmp export APP_FOLDER = $(ROOT)/usr/local/share/applications/helm export INITRD_DIR = $(ROOT)/etc/init.d +export LOCAL_BIN_DIR = $(ROOT)/usr/local/bin +export BASH_COMPLETION_DIR = $(ROOT)/etc/bash_completion.d export DEB_VERSION = $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ') export RELEASE = $(shell cat /etc/build.info | grep SW_VERSION | cut -d'"' -f2) @@ -63,11 +65,17 @@ override_dh_auto_install: # Install the app tar file install -d -m 755 $(APP_FOLDER) install -d -m 755 $(INITRD_DIR) + install -d -m 755 $(LOCAL_BIN_DIR) + install -d -m 755 $(BASH_COMPLETION_DIR) install -p -D -m 755 $(APP_TARBALL) $(APP_FOLDER) install -m 750 files/rook-mon-exit.sh $(INITRD_DIR)/rook-mon-exit + install -m 750 files/ceph-wrapper.sh $(LOCAL_BIN_DIR)/ceph + install -m 644 files/bash_completion $(BASH_COMPLETION_DIR)/ceph # Prevents dh_fixperms from changing the permissions defined in this file override_dh_fixperms: + dh_fixperms --exclude etc/bash_completion.d/ceph dh_fixperms --exclude etc/init.d/rook-mon-exit + dh_fixperms --exclude usr/local/bin/ceph override_dh_usrlocal: diff --git a/stx-rook-ceph-helm/debian/deb_folder/stx-rook-ceph-helm.install b/stx-rook-ceph-helm/debian/deb_folder/stx-rook-ceph-helm.install index 9a6fff7..2cbb9e7 100644 --- a/stx-rook-ceph-helm/debian/deb_folder/stx-rook-ceph-helm.install +++ b/stx-rook-ceph-helm/debian/deb_folder/stx-rook-ceph-helm.install @@ -1,2 +1,4 @@ usr/local/share/applications/helm/* +usr/local/bin/ceph +etc/bash_completion.d/ceph etc/init.d/rook-mon-exit diff --git a/stx-rook-ceph-helm/files/bash_completion b/stx-rook-ceph-helm/files/bash_completion new file mode 100644 index 0000000..3d6eb96 --- /dev/null +++ b/stx-rook-ceph-helm/files/bash_completion @@ -0,0 +1,50 @@ +# +# Ceph - scalable distributed file system +# +# This is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software +# Foundation. +# + +_ceph() +{ + local options_noarg="-h --help -s --status -w --watch --watch-debug --watch-info --watch-sec --watch-warn --watch-error --version -v --verbose --concise" + local options_arg="-c --conf -i --in-file -o --out-file --id --user -n --name --cluster --admin-daemon --admin-socket -f --format --connect-timeout" + local cnt=${#COMP_WORDS[@]} + local cur=${COMP_WORDS[COMP_CWORD]} + local prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ " -c --conf -i --in-file -o --out-file " =~ " ${prev} " ]] + then + #default autocomplete for options (file autocomplete) + compopt -o default + COMPREPLY=() + return 0 + fi + if [[ "${cur:0:1}" == "-" ]] ; + then + COMPREPLY=( $(compgen -W "${options_noarg} ${options_arg}" -- $cur) ) + return 0 + fi + declare -a hint_args + for (( i=1 ; i/dev/null) ) +} +complete -F _ceph ceph diff --git a/stx-rook-ceph-helm/files/ceph-wrapper.sh b/stx-rook-ceph-helm/files/ceph-wrapper.sh new file mode 100644 index 0000000..3a625f9 --- /dev/null +++ b/stx-rook-ceph-helm/files/ceph-wrapper.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# This script is wrapper for ceph, providing access to +# bare-metal or rook, according to defined backend. + +NODE_ROOK_CONFIGURED_FLAG="/etc/platform/.node_rook_configured" +NODE_CEPH_CONFIGURED_FLAG="/etc/platform/.node_ceph_configured" + +PLATFORM_CONF="/etc/platform/platform.conf" + +ROOK_CEPH_NAMESPACE="rook-ceph" +ROOK_CEPH_TOOLS_NAME="rook-ceph-tools" +KUBE_CONFIG="/etc/kubernetes/admin.conf" + +# Logger setup +LOG_FACILITY=user +LOG_PRIORITY=info + +ARGS="$*" +COMPLETION=false +CMD_DIR="/tmp" + +function LOG { + if [ "${COMPLETION}" = false ]; then + logger -t "${0##*/}[$$]" -p ${LOG_FACILITY}.${LOG_PRIORITY} "$@" + echo "$@" + fi +} + +function process_argument { + local FILENAME + local ARG=$1 + FILENAME=$(basename -- "$ARG") + local REMOTE_FILE=${CMD_DIR}/${FILENAME} + ARGS="${ARGS/$ARG/$REMOTE_FILE}" + if [ "$2" = "in" ]; then + kubectl --kubeconfig ${KUBE_CONFIG} cp "${ARG}" \ + -n ${ROOK_CEPH_NAMESPACE} "${ROOK_CEPH_TOOLS_POD}":"${CMD_DIR}" + elif [ "$2" = "out" ]; then + OUTPUT_REMOTE=$REMOTE_FILE + fi +} + +for ((i=1;i<=$#;i++)); do + if [ "${!i}" = "-i" ] || [ "${!i}" = "--in-file" ]; then + $((i++)) + INPUT_ARG=${!i}; + fi + + if [ "${!i}" = "-o" ] || [ "${!i}" = "--out-file" ]; then + $((i++)) + OUTPUT_ARG=${!i}; + fi + + if [ "${!i}" = "-c" ] || [ "${!i}" = "--conf" ]; then + $((i++)) + CONF_ARG=${!i}; + fi +done; + +if [[ "${ARGS}" == *" " ]]; then + COMPLETION=true +fi + +if [ -f "${NODE_ROOK_CONFIGURED_FLAG}" ]; then + . $PLATFORM_CONF + if [[ $nodetype != "controller" ]]; then + LOG "Rook CLI access is only available on control plane hosts." + exit + fi + + # Get rook-ceph-tools pod state + ROOK_CEPH_TOOLS_POD=$(kubectl --kubeconfig ${KUBE_CONFIG} \ + get pods -n ${ROOK_CEPH_NAMESPACE} \ + --selector=app=${ROOK_CEPH_TOOLS_NAME} \ + --field-selector=status.phase==Running \ + -o jsonpath="{.items[0].metadata.name}" 2>/dev/null) + RETURN_CODE=$? + + if [ ${RETURN_CODE} -ne 0 ]; then + LOG "The rook toolbox is not running." + exit ${RETURN_CODE} + fi + + if [ -z "${ARGS}" ]; then + # Interactive Rook toolbox + kubectl --kubeconfig ${KUBE_CONFIG} \ + exec -it -n ${ROOK_CEPH_NAMESPACE} \ + deploy/${ROOK_CEPH_TOOLS_NAME} -- /usr/bin/ceph + else + if [[ $INPUT_ARG ]]; then + process_argument "$INPUT_ARG" "in" + fi + + if [[ $CONF_ARG ]]; then + process_argument "$CONF_ARG" "in" + fi + + if [[ $OUTPUT_ARG ]]; then + process_argument "$OUTPUT_ARG" "out" + fi + + if [ "${COMPLETION}" = true ]; then + ARGS+=" ''" + fi + + # Execute single ceph command in Rook toolbox + kubectl --kubeconfig ${KUBE_CONFIG} exec \ + -n ${ROOK_CEPH_NAMESPACE} deploy/${ROOK_CEPH_TOOLS_NAME} -- \ + bash -c "cd ${CMD_DIR} && /usr/bin/ceph ${ARGS}" + + if [[ $OUTPUT_ARG ]]; then + kubectl --kubeconfig ${KUBE_CONFIG} cp -n ${ROOK_CEPH_NAMESPACE} \ + "${ROOK_CEPH_TOOLS_POD}":"${OUTPUT_REMOTE:1}" "${OUTPUT_ARG}" + fi + fi +elif [ -f "${NODE_CEPH_CONFIGURED_FLAG}" ]; then + if [ "${COMPLETION}" = true ]; then + /usr/bin/ceph ${ARGS} '' + else + /usr/bin/ceph ${ARGS} + fi +else + LOG "Ceph not enabled." +fi