Skip to content

Commit

Permalink
add flux cli, auto completion for govc
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrand committed Sep 23, 2021
1 parent b93701f commit 7cae8a2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 32 deletions.
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ ARG DEBIAN_FRONTEND=noninteractive

#--- clis versions
ENV BBR_VERSION="1.9.1" \
BOSH_CLI_VERSION="6.4.4" \
BOSH_CLI_VERSION="6.4.7" \
BOSH_CLI_COMPLETION_VERSION="1.2.0" \
BOSH_GEN_VERSION="0.101.1" \
CF_CLI_VERSION="7.2.0" \
CF_CLI_VERSION="7.3.0" \
CF_UAAC_VERSION="4.2.0" \
CREDHUB_VERSION="2.9.0" \
DB_DUMPER_VERSION="1.4.2" \
FLUX_VERSION="0.17.2" \
FLY_VERSION="7.3.2" \
GOVC_VERSION="0.26.0" \
GOVC_VERSION="0.26.1" \
GO3FR_VERSION="0.5.0" \
HELM_VERSION="3.5.3" \
JQ_VERSION="1.6" \
K14S_KAPP_VERSION="0.37.0" \
K14S_KLBD_VERSION="0.30.0" \
K14S_YTT_VERSION="0.35.1" \
K9S_VERSION="0.24.14" \
K14S_KAPP_VERSION="0.40.0" \
K14S_KLBD_VERSION="0.31.0" \
K14S_YTT_VERSION="0.36.0" \
K9S_VERSION="0.24.15" \
KUBECTL_VERSION="1.20.7" \
KUSTOMIZE_VERSION="4.2.0" \
MONGO_SHELL_VERSION="4.0.25" \
Expand All @@ -32,7 +33,7 @@ ENV BBR_VERSION="1.9.1" \
SVCAT_VERSION="0.3.1" \
TERRAFORM_PLUGIN_CF_VERSION="0.11.2" \
TERRAFORM_VERSION="0.11.14" \
VENDIR_VERSION="0.19.0"
VENDIR_VERSION="0.23.0"

#--- Packages list, ruby env for COA and cf plugins
ENV INIT_PACKAGES="apt-transport-https ca-certificates curl openssh-server openssl sudo unzip wget" \
Expand Down Expand Up @@ -81,6 +82,7 @@ RUN printf '\n=====================================================\n Install sy
printf '\n=> Add CREDHUB-CLI\n' && curl -sSL "https://github.com/cloudfoundry-incubator/credhub-cli/releases/download/${CREDHUB_VERSION}/credhub-linux-${CREDHUB_VERSION}.tgz" | tar -xz -C /usr/local/bin && \
printf '\n=> Add DB-DUMPER-PLUGIN\n' && curl -sSLo /tmp/db-dumper-plugin "https://github.com/Orange-OpenSource/db-dumper-cli-plugin/releases/download/v${DB_DUMPER_VERSION}/db-dumper_linux_amd64" && chmod 755 /tmp/db-dumper-plugin && su -l bosh -s /bin/bash -c "cf install-plugin /tmp/db-dumper-plugin -f" && rm -f /tmp/db-dumper-plugin && \
printf '\n=> Add FLY-CLI\n' && curl -sSL "https://github.com/concourse/concourse/releases/download/v${FLY_VERSION}/fly-${FLY_VERSION}-linux-amd64.tgz" | tar -xz -C /usr/local/bin && \
printf '\n=> Add FLUX-CLI\n' && curl -sSL "https://github.com/fluxcd/flux2/releases/download/v${FLUX_VERSION}/flux_${FLUX_VERSION}_linux_amd64.tar.gz" | tar -xz -C /usr/local/bin && \
printf '\n=> Add GOVC-CLI\n' && curl -sSL "https://github.com/vmware/govmomi/releases/download/v${GOVC_VERSION}/govc_Linux_x86_64.tar.gz" | tar -xz -C /tmp && mv /tmp/govc /usr/local/bin/govc && \
printf '\n=> Add GO3FR-CLI\n' && curl -sSL "https://github.com/rlmcpherson/s3gof3r/releases/download/v${GO3FR_VERSION}/gof3r_${GO3FR_VERSION}_linux_amd64.tar.gz" | tar -xz -C /tmp && mv /tmp/gof3r_${GO3FR_VERSION}_linux_amd64/gof3r /usr/local/bin/go3fr && \
printf '\n=> Add HELM-CLI\n' && curl -sSL "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar -xz -C /tmp && mv /tmp/linux-amd64/helm /usr/local/bin/helm && chmod 755 /usr/local/bin/helm && \
Expand Down Expand Up @@ -127,6 +129,7 @@ RUN printf '\n=====================================================\n Install sy
printf " %-20s %s\n" "shield (${SHIELD_VERSION})" "Shield cli (https://docs.pivotal.io/partners/starkandwayne-shield/)" >> /etc/motd && \
printf 'Kubernetes tools:\n' >> /etc/motd && \
printf " %-20s %s\n" "helm (${HELM_VERSION})" "Kubernetes Package Manager (https://docs.helm.sh/)" >> /etc/motd && \
printf " %-20s %s\n" "flux (${FLUX_VERSION})" "Kubernetes Gitops cli (https://fluxcd.io/)" >> /etc/motd && \
printf " %-20s %s\n" "kubectl (${KUBECTL_VERSION})" "Kubernetes cli (https://kubernetes.io/docs/reference/generated/kubectl/overview/)" >> /etc/motd && \
printf " %-20s %s\n" "kapp (${K14S_KAPP_VERSION})" "Kubernetes YAML tool (https://github.com/k14s/kapp/)" >> /etc/motd && \
printf " %-20s %s\n" "klbd (${K14S_KLBD_VERSION})" "Kubernetes image build orchestrator tool (https://github.com/k14s/kbld/)" >> /etc/motd && \
Expand Down
1 change: 1 addition & 0 deletions bosh-cli/check-available-clis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ printf '\n=> Check BBR-CLI\n' ; bbr --version
printf '\n=> Check BOSH-CLI\n' ; bosh --version
printf '\n=> Check CF-CLI\n' ; cf --version
printf '\n=> Check CREDHUB-CLI\n' ; credhub --version
printf '\n=> Check FLUX-CLI\n' ; flux --version
printf '\n=> Check FLY-CLI\n' ; fly --version
printf '\n=> Check GOVC-CLI\n' ; govc version
printf '\n=> Check GO3FR-CLI\n' ; go3fr --version
Expand Down
48 changes: 24 additions & 24 deletions bosh-cli/log-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,22 @@ if [ ${flagError} = 0 ] ; then
esac
done

if [ "${K8S_TYPE}" = "k8s" ] ; then
if [ "${K8S_TYPE}" = "k3s" ] ; then
#--- Get k3s cluster configuration
export BOSH_CLIENT="admin"
export BOSH_CA_CERT="/etc/ssl/certs/ca-certificates.crt"
logToBosh "${K8S_DIRECTOR}"
if [ ${flagError} = 0 ] ; then
KUBECONFIG="${HOME}/.kube/${K8S_CLUSTER}.yml"
instance="$(bosh -d ${BOSH_K8S_DEPLOYMENT} is | grep "server/" | awk '{print $1}')"
bosh -d ${BOSH_K8S_DEPLOYMENT} scp ${instance}:/var/vcap/store/k3s-server/kubeconfig.yml ${KUBECONFIG} > /dev/null 2>&1
if [ $? != 0 ] ; then
printf "\n\n%bERROR : Get cluster configuration failed.%b\n\n" "${RED}" "${STD}" ; flagError=1
fi
updateYaml "${KUBECONFIG}" "clusters.name" "${K8S_CLUSTER}"
updateYaml "${KUBECONFIG}" "contexts.context.cluster" "${K8S_CLUSTER}"
fi
else
#--- Check if bosh dns exists
K8S_API_ENDPOINT="${K8S_CLUSTER}-api.internal.paas"
flag_host="$(host ${K8S_API_ENDPOINT} | awk '{print $4}')"
Expand Down Expand Up @@ -143,20 +158,14 @@ if [ ${flagError} = 0 ] ; then
fi
fi
fi
else
#--- Get k3s cluster configuration
export BOSH_CLIENT="admin"
export BOSH_CA_CERT="/etc/ssl/certs/ca-certificates.crt"
logToBosh "${K8S_DIRECTOR}"
if [ ${flagError} = 0 ] ; then
KUBECONFIG="${HOME}/.kube/${K8S_CLUSTER}.yml"
instance="$(bosh -d ${BOSH_K8S_DEPLOYMENT} is | grep "server/" | awk '{print $1}')"
bosh -d ${BOSH_K8S_DEPLOYMENT} scp ${instance}:/var/vcap/store/k3s-server/kubeconfig.yml ${KUBECONFIG} > /dev/null 2>&1
if [ $? != 0 ] ; then
printf "\n\n%bERROR : Get cluster configuration failed.%b\n\n" "${RED}" "${STD}" ; flagError=1
fi
updateYaml "${KUBECONFIG}" "clusters.name" "${K8S_CLUSTER}"
updateYaml "${KUBECONFIG}" "contexts.context.cluster" "${K8S_CLUSTER}"

#--- Display admin token (used for web ui portals)
admin_token_name="$(kubectl -n kube-system get secret | grep admin | awk '{print $1}')"
if [ "${admin_token_name}" = "" ] ; then
printf "\n%bk8s token:%b\nNo \"admin\" token available for cluster \"${K8S_CLUSTER}\".\n" "${YELLOW}${REVERSE}" "${STD}"
else
token="$(kubectl -n kube-system describe secret ${admin_token_name} | grep "token:" | sed -e "s+token: *++g")"
printf "\n%bk8s token:%b\n${token}\n" "${YELLOW}${REVERSE}" "${STD}"
fi
fi
fi
Expand All @@ -169,15 +178,6 @@ if [ ${flagError} = 0 ] ; then
export KUBECONFIG="${OLD_KUBECONFIG}"
source <(svcat completion bash)

#--- Display admin token (used for web ui portals)
admin_token_name="$(kubectl -n kube-system get secret | grep admin | awk '{print $1}')"
if [ "${admin_token_name}" = "" ] ; then
printf "\n%bk8s token:%b\nNo \"admin\" token available for cluster \"${K8S_CLUSTER}\".\n" "${YELLOW}${REVERSE}" "${STD}"
else
token="$(kubectl -n kube-system describe secret ${admin_token_name} | grep "token:" | sed -e "s+token: *++g")"
printf "\n%bk8s token:%b\n${token}\n" "${YELLOW}${REVERSE}" "${STD}"
fi

#--- Display cluster nodes
printf "\n%bCluster namespaces:%b\n" "${YELLOW}${REVERSE}" "${STD}"
kubectl get namespaces
Expand Down
40 changes: 40 additions & 0 deletions bosh-cli/profile
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,46 @@ fi
complete -C /usr/local/bin/mc mc
#--- govc cli auto-completion
_govc_complete()
{
local cur prev subcmd
prev=${COMP_WORDS[COMP_CWORD-1]}
cur=${COMP_WORDS[COMP_CWORD]}
subcmd=${COMP_WORDS[1]}
COMPREPLY=()
if [[ ${prev} == "govc" ]] ; then
COMPREPLY=( $(compgen -W "$(govc -h | grep -v Usage | tr -s '\n' ' ')" -- ${cur}) )
return 0
elif [[ ${cur} == "-"* ]] ; then
: #--- drop out and show options
elif [[ ${subcmd} == "ls" ]] ; then #--- not completing an option, try for appropriate values
if [[ ${prev} == "-t" ]] ; then
COMPREPLY=( $(compgen -W "$(govc ls -l "/**" | awk '{print $2}' | sort -u | tr -d '()' | tr '\n' ' ' )" -- ${cur}) )
else
COMPREPLY=( $(compgen -W "$(govc ls "${cur:-/*}*" | tr -s '\n' ' ' )" -- ${cur}) )
fi
elif [[ ${subcmd} == "vm."* || ${prev} == "-vm" ]] ; then
COMPREPLY=( $(compgen -W "$(govc ls -t VirtualMachine -l "${cur}*" | awk '{print $1}' | tr -s '\n' ' ' )" -- ${cur}) )
fi
#--- did not hit any specifcs so show all options from help
if [[ -z ${COMPREPLY} ]] ; then
COMPREPLY=( $(compgen -W "-h $(govc ${subcmd} -h | awk '{print $1}' | grep "^-" | sed -e 's/=.*//g' | tr -s '\n' ' ' )" -- ${cur}) )
fi
return 0
}
complete -F _govc_complete govc
#--- flux cli auto-completion
. <(flux completion bash)
#--- Load OSB-CMDB bash functions
if [ -f /usr/local/bin/cf-cli-cmdb-functions.bash ] ; then
source /usr/local/bin/cf-cli-cmdb-functions.bash
Expand Down

0 comments on commit 7cae8a2

Please sign in to comment.