From 823ca426eda86828ccfbfcfbdc29aed9fc3db59f Mon Sep 17 00:00:00 2001 From: drymer Date: Mon, 2 Jul 2018 22:39:12 +0200 Subject: [PATCH] Add kubernetes functions One for dump all logs related to a deploy and the other to get the pods of a deployment. They can be used together. --- roles/shell-dotfiles/files/functions | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/roles/shell-dotfiles/files/functions b/roles/shell-dotfiles/files/functions index 60fcbe1..21f9462 100644 --- a/roles/shell-dotfiles/files/functions +++ b/roles/shell-dotfiles/files/functions @@ -280,3 +280,34 @@ function warn_me (){ # -v /var/run/docker.sock:/var/run/docker.sock \ # -v `pwd`/config:/home/docker/.ssh/config ansible:2.5 "$@" # } + + +function kube_dump_logs(){ + local deploy="$1" + local time="$2" + if [[ -z "$deploy" ]] + then + echo "You must pass a kubernetes deployment as an argument." + return 1 + fi + if [[ -z "$time" ]] + then + time=1h + fi + mkdir -p "$deploy" + for pod in $(ku get pods | grep "$deploy" | awk '{print $1}') + do + ku logs "$pod" --since="$time" > "$deploy"/"$pod" + done + echo "Dumped $deploy logs." +} + +function kube_get_deploy_pods(){ + local deploy="$1" + if [[ -z "$deploy" ]] + then + echo "You must pass a kubernetes deployment as an argument." + return 1 + fi + ku get pods | grep "$deploy" | awk '{print $1}' +}