Skip to content

Instantly share code, notes, and snippets.

@Babbleshack
Created October 1, 2024 09:59
Show Gist options
  • Select an option

  • Save Babbleshack/e0ee60b858f63fcc9b5019bf97b82421 to your computer and use it in GitHub Desktop.

Select an option

Save Babbleshack/e0ee60b858f63fcc9b5019bf97b82421 to your computer and use it in GitHub Desktop.
Shell function for accessing cockroachdb via client_secure
function client_secure -d "Starts client secure pod in the current env"
set -l namespace "cockroachdb"
set -l command "bash"
argparse -x c,s h/help n/namespace= c/command= s/sql -- $argv
or begin
echo "Invalid arguments. Use '--help' to see usage information."
return 1
end
if set -ql _flag_help
echo "
Usage: client_secure [-n <namespace>] [-c <command> | -s] [--help]
Options:
-n, --namespace Specify the Kubernetes namespace (default: cockroachdb).
-c, --command Specify the command to execute inside the pod (default: bash). This option cannot be set with `--sql/-s`.
-s, --sql Start the CockroachDB SQL shell. This option cannot be set with `--command/-c`.
-h, --help Display this help message.
Description:
Start a secure client pod in the CockroachDB environment.
"
return 0
end
if set -ql _flag_namespace
set namespace $_flag_namespace
end
if set -ql _flag_sql
set command \
cockroach sql \
--certs-dir=/cockroach/cockroach-certs \
--host=cockroachdb-public
else if set -ql _flag_command
set command $_flag_command
end
set -l client_secure_pod_name (kubectl get pods -n $namespace -l app=cockroachdb-client-secure -o jsonpath="{.items[0].metadata.name}")
if test -z "$client_secure_pod_name"
echo "Error: Failed to get the client secure pod name or the pod does not exist in the namespace '$namespace'."
return 1
end
echo "starting client_secure shell: { namespace: $namespace, pod_name: $client_secure_pod_name, command: $command }"
kubectl exec -it -n $namespace $client_secure_pod_name -- $command
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment