-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_functions
More file actions
114 lines (91 loc) · 2.78 KB
/
Copy pathdot_functions
File metadata and controls
114 lines (91 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Warns user about uncommited dotfile changes
function check_dotfiles_uncommitted_changes() {
local REPO=$HOME/repos/github/sanderginn/dotfiles
if ! git --git-dir=$REPO/.git diff-index --quiet HEAD; then
tput setaf 1
read -sk "response?Uncommitted changes found in your dotfiles. Go to repository? [Y/n] "
local RESPONSE=${response:l} #tolower
tput sgr0
if [[ $RESPONSE =~ ^(yes|y| ) ]] || [[ -z $RESPONSE ]]; then
cd $REPO
fi
fi
}
#
# Kubernetes helper functions
#
# Set kubectl context for Azure AKS cluster in resource group
function setazctx() {
if [[ "$1" != "" && "$2" != "" ]]
then
az aks get-credentials -n "$1" -g "$2"
else
printf "Usage: setazctx <cluster name> <resource group>\n"
fi
}
function kga() {
kubectl get all "$@"
}
function kgp() {
kubectl get pods "$@"
}
function kgans() {
kubectl get all --all-namespaces "$@"
}
function fsync() {
if [[ -z "$1" ]]
then
fluxctl sync --k8s-fwd-ns flux
else
fluxctl sync --k8s-fwd-ns "$1"
fi
}
function ksd() {
if [[ -z "$2" ]]
then
kubectl get secret "$1" -o go-template='{{range $data,$value := .data}}{{print $data " = " ($value | base64decode) "\n"}}{{end}}'
else
kubectl get secret "$1" -n "$2" -o go-template='{{range $data,$value := .data}}{{print $data " = " ($value | base64decode) "\n"}}{{end}}'
fi
}
function kshell() {
kubectl run --limits='cpu=100m,memory=200Mi' --requests='cpu=100m,memory=200Mi' --image=alpine:3.5 -it alpine-shell -- /bin/sh
}
function kgacr {
for i in $(kubectl api-resources --verbs=list --namespaced -o name | grep -v "events.events.k8s.io" | grep -v "events" | sort | uniq); do
echo "Resource:" $i
if [ -z "$1" ]
then
kubectl get --ignore-not-found ${i}
else
kubectl -n ${1} get --ignore-not-found ${i}
fi
done
}
function gdlb() {
git branch -r | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | xargs git branch -d
}
function kube_ps1()
{
# Get current context
CONTEXT=$(cat ~/.kube/config | grep "current-context:" | sed "s/current-context: //")
if [ -n "$CONTEXT" ]; then
echo "(k8s: ${CONTEXT})"
fi
}
function buildkite-local-agent() {
local base_dir="/opt/homebrew/var/buildkite-agent/builds"
mkdir -p "$base_dir"
local build_dir
build_dir="$(mktemp -d -p "$base_dir" agent-XXXXXX)"
cleanup() { rm -rf "$build_dir"; }
trap cleanup INT TERM
local token
token="$(op item get Buildkite --fields label="Local build agent token" --format json | jq -r '.value')"
BUILDKITE_AGENT_TOKEN="$token" buildkite-agent start --queue local-agents --build-path "$build_dir"
cleanup
}
function cy() {
GITHUB_PAT_TOKEN=$(op item get yo5dtypr3chca3oeulv7th5lbm --fields label="broader token" --reveal)
GITHUB_PAT_TOKEN=$GITHUB_PAT_TOKEN codex --yolo
}