Skip to content

Commit 038b1d4

Browse files
Merge pull request #211 from dormunis/feature/eks-support
Added eks support for kubernetes prompt
2 parents ce10069 + c200b96 commit 038b1d4

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

INSTALL.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,31 @@ set -g @dracula-clients-singular client
326326
set -g @dracula-clients-plural clients
327327
```
328328

329+
#### Kubernetes options
330+
331+
Add prefix label before the context
332+
333+
```bash
334+
set -g @dracula-kubernetes-context-label "Some Label"
335+
```
336+
337+
Hide user from the context string
338+
339+
```
340+
set -g @dracula-kubernetes-hide-user true
341+
```
342+
343+
Hide ARN (show only cluster name) - Available for EKS only (only available for cluster names that are ARNs)
344+
345+
```
346+
set -g @dracula-kubernetes-eks-hide-arn true
347+
```
348+
349+
Extract the account as a prefix to the cluster name - Available for EKS only (only available for cluster names that are ARNs)
350+
351+
```
352+
set -g @dracula-kubernetes-eks-extract-account true
353+
329354
#### continuum options
330355
331356
Set the output mode. Options are:

scripts/dracula.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ source $current_dir/utils.sh
88
main()
99
{
1010
# set configuration option variables
11+
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
12+
eks_hide_arn=$(get_tmux_option "@dracula-kubernetes-eks-hide-arn" false)
13+
eks_extract_account=$(get_tmux_option "@dracula-kubernetes-eks-extract-account" false)
14+
hide_kubernetes_user=$(get_tmux_option "@dracula-kubernetes-hide-user" false)
1115
terraform_label=$(get_tmux_option "@dracula-terraform-label" "")
1216
show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true)
1317
show_location=$(get_tmux_option "@dracula-show-location" true)
@@ -25,7 +29,6 @@ main()
2529
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
2630
show_synchronize_panes_label=$(get_tmux_option "@dracula-synchronize-panes-label" "Sync")
2731
time_format=$(get_tmux_option "@dracula-time-format" "")
28-
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
2932
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")
3033
show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true)
3134

@@ -206,7 +209,7 @@ main()
206209

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

211214
elif [ $plugin = "terraform" ]; then
212215
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-terraform-colors" "light_purple dark_gray")

scripts/kubernetes_context.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# setting the locale, some users have issues with different locales, this forces the correct one
33
export LC_ALL=en_US.UTF-8
44

5-
label=$1
5+
hide_arn_from_cluster=$1
6+
extract_account=$2
7+
hide_user=$3
8+
label=$4
69

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

18+
current_account_id=""
19+
if [[ "$current_cluster" =~ ^arn:aws:eks:[a-z0-9\-]*:[0-9]*:cluster/[a-z0-9\-]*$ ]]; then
20+
if [ "$extract_account" = "true" ]; then
21+
current_account_id=$(echo "$current_cluster" | cut -d':' -f5)
22+
fi
23+
if [ "$hide_arn_from_cluster" = "true" ]; then
24+
current_cluster=${current_cluster##*/}
25+
fi
26+
fi
27+
28+
if [ "$hide_user" = "true" ]; then
29+
current_user=""
30+
fi
31+
1532
main()
1633
{
1734
# storing the refresh rate in the variable RATE, default is 5
1835
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
1936
OUTPUT_STRING=""
37+
if [ ! -z "$current_account_id" ]
38+
then
39+
OUTPUT_STRING="${current_account_id}/"
40+
fi
41+
2042
if [ ! -z "$current_user" ]
2143
then
2244
OUTPUT_STRING="${current_user}@"

0 commit comments

Comments
 (0)