Skip to content

Instantly share code, notes, and snippets.

@nuxlli
Created July 6, 2020 14:47
Show Gist options
  • Save nuxlli/7f8b84121c09a2c876de0b596bf1de45 to your computer and use it in GitHub Desktop.
Save nuxlli/7f8b84121c09a2c876de0b596bf1de45 to your computer and use it in GitHub Desktop.
Fish k8s alias and scripts
function av-exec
aws-vault exec $argv[1] -- $argv[2..-1]
end
function av-shell
av-exec $argv[1] fish
end
alias kexec-dev="kubectl-exec firma-dev"
alias kexec-stage="kubectl-exec firma-stage"
alias kexec-prod="kubectl-exec firma-prod"
alias kexec-shared="kubectl-exec firma-shared"
alias kexec-docker="kubectl-exec docker-desktop --no-aws-vault"
#!/usr/bin/env fish
function get-kube-context
kubectl config get-contexts --output='name' | grep $argv[1] | awk '{ print $1 }'
end
set profile "$argv[1]"
set cmd "$argv[2]"
set awsValt true
set index 3
if test "$cmd" = "--no-aws-vault"
set index 4
set cmd "$argv[3]"
set awsValt false
end
set context (get-kube-context $profile)
function set-kube-context
kubectl config use-context $context
if test $argv[1] = "true"
av-exec $profile kubergrunt helm configure --tiller-namespace applications-tiller --resource-namespace applications --rbac-user allow-full-access-from-other-accounts
end
end
if test "$cmd" = "reauth"
kubectl config delete-context $context
aws-vault exec $profile -- kubergrunt eks configure --eks-cluster-arn $context
else if test "$cmd" = "set-context"
set-kube-context true
else
set -l current_context (kubectl config current-context)
set -l argv $argv[$index..-1]
if test "$cmd" = "helm"
set --prepend argv --tls --tls-verify --tiller-namespace applications-tiller
end
if test "$current_context" != "$context"
set-kube-context (test "$cmd" = "helm"; and echo "true"; or echo "false")
end
set --prepend argv $cmd
if test $awsValt = "true"
set --prepend argv aws-vault exec $profile --
end
echo "$argv"
$argv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment