-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
66 lines (53 loc) · 2.72 KB
/
Copy pathTaskfile.yaml
File metadata and controls
66 lines (53 loc) · 2.72 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
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: '3'
set: [pipefail]
shopt: [globstar]
vars:
BOOTSTRAP_DIR: '{{.ROOT_DIR}}/bootstrap'
KUBERNETES_DIR: '{{.ROOT_DIR}}/kubernetes'
SCRIPTS_DIR: '{{.ROOT_DIR}}/scripts'
TALOS_DIR: '{{.ROOT_DIR}}/talos'
PRIVATE_DIR: '{{.ROOT_DIR}}/.private'
env:
KUBECONFIG: '{{.ROOT_DIR}}/kubeconfig'
TALOSCONFIG: '{{.ROOT_DIR}}/talos/talosconfig'
includes:
1password: .taskfiles/1password
flux: .taskfiles/flux
rook: .taskfiles/rook
network: .taskfiles/network
actions-runner: .taskfiles/actions-runner
tasks:
default: task --list
setup-dev-env:
cmds:
- mise install
- mise exec -- pre-commit install
- mise exec -- pre-commit install --hook-type commit-msg
desc: Setup dev environment and install pre-commit hooks
reconcile:
desc: Force Flux to pull in changes from your Git repository
cmd: flux --namespace flux-system reconcile kustomization flux-system --with-source
preconditions:
- test -f {{.KUBECONFIG}}
- which flux
cleanup-failed-pods:
desc: Remove all failed/error pods (keeps completed pods)
cmd: kubectl delete pods --all-namespaces --field-selector=status.phase=Failed
cleanup-succeeded-pods:
desc: Remove old succeeded pods (keeps recent ones from last 24h)
cmd: CUTOFF=$(date -d '1 day ago' -u +"%Y-%m-%dT%H:%M:%SZ") && kubectl get pods --all-namespaces --field-selector=status.phase=Succeeded -o json | jq -r --arg cutoff "$CUTOFF" '.items[] | select(.metadata.creationTimestamp < $cutoff) | [.metadata.namespace, .metadata.name] | @tsv' | while IFS=$'\t' read -r ns name; do kubectl delete pod "$name" -n "$ns"; done
cleanup-error-pods:
desc: Remove all pods in Error state
cmd: kubectl get pods --all-namespaces --field-selector=status.phase!=Running,status.phase!=Succeeded,status.phase!=Pending --no-headers -o custom-columns="NAMESPACE:.metadata.namespace,NAME:.metadata.name" | while read -r ns name; do kubectl delete pod "$name" -n "$ns"; done
cleanup-replicasets:
desc: Remove old ReplicaSets with 0 desired replicas (excludes intentionally scaled ones)
cmd: CUTOFF=$(date -d '1 day ago' -u +"%Y-%m-%dT%H:%M:%SZ") && kubectl get rs --all-namespaces -o json | jq -r --arg cutoff "$CUTOFF" '.items[] | select((.spec.replicas // 0) == 0 and (.status.replicas // 0) == 0 and .metadata.creationTimestamp < $cutoff) | [.metadata.namespace, .metadata.name] | @tsv' | while IFS=$'\t' read -r ns name; do kubectl delete rs "$name" -n "$ns"; done
cleanup-all:
desc: Clean up all failed pods, error pods, and unused replicasets
cmds:
- task: cleanup-failed-pods
- task: cleanup-succeeded-pods
- task: cleanup-error-pods
- task: cleanup-replicasets