Repository navigation
Expand file tree
/
Copy pathmise.toml
More file actions
193 lines (171 loc) · 5.45 KB
/
Copy pathmise.toml
File metadata and controls
193 lines (171 loc) · 5.45 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
[tools]
bitwarden = "latest"
bitwarden-secrets-manager = "2.1.0"
flux2 = "2.9.6"
kubectl = "1.37.1"
kubecolor = "0.8.0"
oxker = "0.13.4"
talosctl = "1.14.5"
usage = "7.1.3"
viddy = "1.3.1"
weave-gitops = "0.38.0"
codex = "0.149.0"
aws-cli = "2.38.6"
k9s = "0.51.0"
java = "27.0.0"
[settings]
auto_install = true
[shell_alias]
ll = "ls -la"
la = "ls -A"
gs = "git status"
gc = "git commit"
k = "kubecolor"
h = "helm"
t = "talosctl"
gto = "gitops"
ft = "forgetool"
tcl = "talosctl"
badPods = 'kubecolor get pods -A --field-selector=status.phase!=Running'
badFlux = "flux get kustomizations -A --status-selector ready=false"
stopAll = "mise chart -stop-all"
kRes = "kubectl rollout restart deployment -n"
vK = "viddy kubectl get pods,ingress,configmaps"
getPods = "mise chart -pods-info -n"
sebDC = "docker compose -f docker/.doco-cd/compose.yaml"
dcLogs = "docker logs doco-cd -f"
kHighRes = "kubectl get pods -A --no-headers | awk '$5 > 0' | sort -k5,5nr"
ingress = "mise chart -ingress"
dns = "mise chart -dns"
deFrag = "mise talos:etcd:status --defrag --yes"
delPods = "mise chart --pods-delete --confirm"
podInfo = "mise chart -pods-info"
volClean = "mise volsync --cleanup --dry-run"
kUps = "mise run kUps --"
cnpgRepair = "mise run cnpg:repair --"
[tasks.kUps]
description = "Get or describe Kubernetes and Talos upgrades"
run = '''
#!/usr/bin/env bash
set -euo pipefail
case "${1:-}" in
-g|--get)
action="get"
;;
-d|--describe)
action="describe"
;;
*)
echo "Usage: kUps (-g|--get|-d|--describe)" >&2
exit 2
;;
esac
kubecolor "$action" kubernetesupgrades,talosupgrades
'''
[tasks."cnpg:repair"]
description = "Diagnose unhealthy CNPG clusters and optionally recycle unhealthy replicas"
run = '''
#!/usr/bin/env bash
set -euo pipefail
namespace=""
apply=false
all_namespaces=true
usage() {
cat <<'EOF'
Usage: mise run cnpg:repair -- [-n <namespace> | -A] [--apply]
Defaults to all namespaces.
Diagnoses every CloudNativePG Cluster in a namespace or across all namespaces.
With --apply, deletes
only unhealthy replica pods so the CNPG operator can recreate them. It never
deletes a current primary or any PVC.
Examples:
mise run cnpg:repair
mise run cnpg:repair -- -n ggrequestz
mise run cnpg:repair -- -A
mise run cnpg:repair -- -n ggrequestz --apply
EOF
}
while (($#)); do
case "$1" in
-n|--namespace)
namespace="${2:-}"
all_namespaces=false
shift 2
;;
-A|--all-namespaces)
all_namespaces=true
shift
;;
--apply)
apply=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 2
;;
esac
done
if [[ "$all_namespaces" == true && -n "$namespace" ]]; then
echo "Use either --namespace or --all-namespaces, not both." >&2
usage >&2
exit 2
fi
if [[ "$all_namespaces" == true ]]; then
mapfile -t clusters < <(kubectl get cluster.postgresql.cnpg.io -A -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name --no-headers)
else
mapfile -t clusters < <(kubectl get cluster.postgresql.cnpg.io -n "$namespace" -o custom-columns=NAME:.metadata.name --no-headers)
fi
if [[ -z "${clusters[0]:-}" ]]; then
if [[ "$all_namespaces" == true ]]; then
echo "No CNPG clusters found."
else
echo "No CNPG clusters found in namespace: $namespace"
fi
exit 0
fi
for cluster_ref in "${clusters[@]}"; do
if [[ "$all_namespaces" == true ]]; then
read -r cluster_namespace cluster <<< "$cluster_ref"
else
cluster_namespace="$namespace"
cluster="$cluster_ref"
fi
primary="$(kubectl get cluster.postgresql.cnpg.io "$cluster" -n "$cluster_namespace" -o jsonpath='{.status.currentPrimary}')"
ready="$(kubectl get cluster.postgresql.cnpg.io "$cluster" -n "$cluster_namespace" -o jsonpath='{range .status.conditions[?(@.type=="Ready")]}{.status}{end}')"
archiving="$(kubectl get cluster.postgresql.cnpg.io "$cluster" -n "$cluster_namespace" -o jsonpath='{range .status.conditions[?(@.type=="ContinuousArchiving")]}{.status}{end}')"
echo
echo "CNPG cluster: $cluster_namespace/$cluster"
echo " primary: ${primary:-unknown}"
echo " ready: ${ready:-unknown}; continuous archiving: ${archiving:-not configured}"
kubectl get pods -n "$cluster_namespace" -l "cnpg.io/cluster=$cluster" \
-o custom-columns=NAME:.metadata.name,READY:.status.containerStatuses[0].ready,PHASE:.status.phase,RESTARTS:.status.containerStatuses[0].restartCount --no-headers
mapfile -t instances < <(kubectl get pods -n "$cluster_namespace" -l "cnpg.io/cluster=$cluster" -o custom-columns=NAME:.metadata.name --no-headers)
for pod in "${instances[@]}"; do
[[ "$pod" == "$primary" ]] && continue
pod_ready="$(kubectl get pod "$pod" -n "$cluster_namespace" -o jsonpath='{range .status.conditions[?(@.type=="Ready")]}{.status}{end}')"
if [[ "$pod_ready" == "True" ]]; then
continue
fi
echo " unhealthy replica: $pod"
kubectl logs -n "$cluster_namespace" "$pod" --tail=25 2>/dev/null \
| grep -E -i 'error|fatal|startup probe|archive|wal|no such bucket' \
| tail -10 \
| sed 's/^/ /' || true
if [[ "$apply" == true ]]; then
echo " recycling unhealthy replica: $pod"
kubectl delete pod -n "$cluster_namespace" "$pod"
else
echo " diagnostic only; rerun with --apply to recycle this replica"
fi
done
if [[ "$archiving" == "False" ]]; then
echo " warning: continuous archiving is failing; inspect the log lines above before recycling replicas"
fi
done
'''