Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added eks support for kubernetes prompt #211

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,31 @@ set -g @dracula-clients-singular client
set -g @dracula-clients-plural clients
```

#### Kubernetes options

Add prefix label before the context

```bash
set -g @dracula-kubernetes-context-label "Some Label"
```

Hide user from the context string

```
set -g @dracula-kubernetes-hide-user true
```

Hide ARN (show only cluster name) - Available for EKS only (only available for cluster names that are ARNs)

```
set -g @dracula-kubernetes-eks-hide-arn true
```

Extract the account as a prefix to the cluster name - Available for EKS only (only available for cluster names that are ARNs)

```
set -g @dracula-kubernetes-eks-extract-account true

#### continuum options

Set the output mode. Options are:
Expand Down
7 changes: 5 additions & 2 deletions scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ source $current_dir/utils.sh
main()
{
# set configuration option variables
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
eks_hide_arn=$(get_tmux_option "@dracula-kubernetes-eks-hide-arn" false)
eks_extract_account=$(get_tmux_option "@dracula-kubernetes-eks-extract-account" false)
hide_kubernetes_user=$(get_tmux_option "@dracula-kubernetes-hide-user" false)
terraform_label=$(get_tmux_option "@dracula-terraform-label" "")
show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true)
show_location=$(get_tmux_option "@dracula-show-location" true)
Expand All @@ -25,7 +29,6 @@ main()
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
show_synchronize_panes_label=$(get_tmux_option "@dracula-synchronize-panes-label" "Sync")
time_format=$(get_tmux_option "@dracula-time-format" "")
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")
show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true)

Expand Down Expand Up @@ -206,7 +209,7 @@ main()

elif [ $plugin = "kubernetes-context" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray")
script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)"
script="#($current_dir/kubernetes_context.sh $eks_hide_arn $eks_extract_account $hide_kubernetes_user $show_kubernetes_context_label)"

elif [ $plugin = "terraform" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-terraform-colors" "light_purple dark_gray")
Expand Down
24 changes: 23 additions & 1 deletion scripts/kubernetes_context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8

label=$1
hide_arn_from_cluster=$1
extract_account=$2
hide_user=$3
label=$4

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
Expand All @@ -12,11 +15,30 @@ current_user=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.na
current_cluster=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.cluster}'; echo)
current_namespace=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.namespace}'; echo)

current_account_id=""
if [[ "$current_cluster" =~ ^arn:aws:eks:[a-z0-9\-]*:[0-9]*:cluster/[a-z0-9\-]*$ ]]; then
if [ "$extract_account" = "true" ]; then
current_account_id=$(echo "$current_cluster" | cut -d':' -f5)
fi
if [ "$hide_arn_from_cluster" = "true" ]; then
current_cluster=${current_cluster##*/}
fi
fi

if [ "$hide_user" = "true" ]; then
current_user=""
fi

main()
{
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
OUTPUT_STRING=""
if [ ! -z "$current_account_id" ]
then
OUTPUT_STRING="${current_account_id}/"
fi

if [ ! -z "$current_user" ]
then
OUTPUT_STRING="${current_user}@"
Expand Down