diff options
author | Chris Werner Rau | 2023-09-06 16:25:01 +0200 |
---|---|---|
committer | Chris Werner Rau | 2023-09-06 16:25:01 +0200 |
commit | 8b20bda7bd5ee0fbb7cf44afb9a6f0bd29c41297 (patch) | |
tree | 84393897090a537267f64d976cc8b2c32c54c39f | |
download | aur-8b20bda7bd5ee0fbb7cf44afb9a6f0bd29c41297.tar.gz |
initial commit
-rw-r--r-- | .SRCINFO | 12 | ||||
-rw-r--r-- | PKGBUILD | 17 | ||||
-rwxr-xr-x | capo-shell | 37 |
3 files changed, 66 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..e2887a9688ab --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,12 @@ +pkgbase = capo-shell + pkgdesc = Wrapper to start a tool or shell with KUBECONFIG and OS_ environment variables to interact with cluster-api-provider-openstack clusters + pkgver = 1.0.0 + pkgrel = 1 + arch = x86_64 + license = APACHE + depends = kubectl + depends = yq + source = capo-shell + sha512sums = 485c93e3a25f2b216ecc37141c3c766a3f905c98dae730d1afa8a8fae639d8d5532fbb7ef1955d96809a61dcea38930f95599b82bbcf24405cbcc3a6254d4760 + +pkgname = capo-shell diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..ed45bf5de0a4 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,17 @@ +# Maintainer Chris Werner Rau <aur@cwrau.io> + +pkgname=capo-shell +pkgver=1.0.0 +pkgrel=1 +pkgdesc="Wrapper to start a tool or shell with KUBECONFIG and OS_ environment variables to interact with cluster-api-provider-openstack clusters" +license=('APACHE') +arch=('x86_64') +depends=('kubectl' 'yq') +source=("$pkgname") +sha512sums=('485c93e3a25f2b216ecc37141c3c766a3f905c98dae730d1afa8a8fae639d8d5532fbb7ef1955d96809a61dcea38930f95599b82bbcf24405cbcc3a6254d4760') + +package() { + install -D -m 0755 -t $pkgdir/usr/bin/ $srcdir/$pkgname +} + +#vim: syntax=sh diff --git a/capo-shell b/capo-shell new file mode 100755 index 000000000000..f93f7107672c --- /dev/null +++ b/capo-shell @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +namespace="${1?}" +name="${2?}" +shift +shift +envs=() + +NEW_KUBECONFIG="$(mktemp -p "$XDG_RUNTIME_DIR")" +trap 'rm -f $NEW_KUBECONFIG' EXIT +if kubectl -n "$namespace" get secrets "${name}-kubeconfig" -o jsonpath='{.data.value}' 2>/dev/null | base64 -d >"$NEW_KUBECONFIG"; then + hasKubeconfig=true + envs+=(KUBECONFIG="$NEW_KUBECONFIG") +else + hasKubeconfig=false +fi +if secretName="$(kubectl -n "$namespace" get openstackcluster -l cluster.x-k8s.io/cluster-name="$name" -o yaml 2>/dev/null | yq -r '.items[0].spec.identityRef.name')"; then + hasOSConfig=true + mapfile -t osEnvs < <(kubectl -n "$namespace" get secret "$secretName" -o jsonpath='{.data.clouds\.yaml}' | base64 -d | yq -r '.clouds.openstack | {OS_AUTH_TYPE: .["auth_type"], OS_AUTH_URL: .auth["auth_url"], OS_APPLICATION_CREDENTIAL_ID: .auth["application_credential_id"], OS_APPLICATION_CREDENTIAL_SECRET: .auth["application_credential_secret"], OS_REGION_NAME: .["region_name"], OS_INTERFACE: .interface, OS_IDENTITY_API_VERSION: .["identity_api_version"]} | to_entries[] | "\(.key)=\(.value)"') + envs+=(OS_SHELL=true "${osEnvs[@]}") +else + hasOSConfig=false +fi +if [[ "$hasOSConfig" == false ]] && [[ "$hasKubeconfig" == false ]]; then + echo "All secrets are missing!" >/dev/stderr + exit 1 +fi +if [[ "$hasOSConfig" == false ]]; then + echo "OpenStack config missing, only setting KUBECONFIG" >/dev/stderr +fi +if [[ "$hasKubeconfig" == false ]]; then + echo "KUBECONFIG missing, only setting OpenStack env" >/dev/stderr +fi +env "${envs[@]}" "${@:-${SHELL:-/usr/bin/env bash}}" |