Skip to content

Commit

Permalink
test timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxpeople committed Jan 27, 2024
1 parent 98f3fa2 commit c9ed8d1
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions kubernetes/apps/networking/metallb/app/helmrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
namespace: networking
spec:
interval: 15m
timeout: 10m
chart:
spec:
chart: metallb
Expand Down
116 changes: 116 additions & 0 deletions tools/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash

kubectl apply -f - <<EOF
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-backup
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pv-backup
spec:
selector:
matchLabels:
app: pv-backup
replicas: 1
template:
metadata:
labels:
app: pv-backup
spec:
containers:
- image: ubuntu
imagePullPolicy: Always
command:
- sleep
- inf
name: pv-backup
resources:
requests:
cpu: 10m
memory: 50Mi
limits:
cpu: 1000m
memory: 1000Mi
volumeMounts:
- mountPath: /pv-backup
name: pv-backup
- mountPath: /nfs-backup
name: nfs-backup
volumes:
- name: pv-backup
persistentVolumeClaim:
claimName: pv-backup
- name: nfs-backup
nfs:
server: 10.20.30.40
path: /volume2/data/backup/kubernetes/pv-backup
EOF

sleep 5

kubectl wait --for=condition=ready pod -l app=pv-backup --timeout=5m || exit 1

backuppod=$(kubectl get pod -l app=pv-backup -o name | cut -d'/' -f2)
kubectl exec -it ${backuppod} -- bash -c "mkdir -p /pv-backup/_tgz"
kubectl exec -it ${backuppod} -- bash -c "rm -rf /pv-backup/*"

# echo disable flux
# flux suspend kustomization --all -n flux-system > /dev/null

for namespace in $(kubectl get ns --no-headers | awk '{ print $1 }'); do
for pvc in $(kubectl get pvc --no-headers -n ${namespace} | awk '{ print $1 }' | grep -v pv-backup); do
echo "Backup ${pvc} ..."
kubectl exec -it ${backuppod} -- bash -c "mkdir -p /pv-backup/${namespace}"
# usedby=$(kubectl describe -n ${namespace} pvc ${pvc} | grep "Used By" | awk '{print $3}')
# controlledby=$(kubectl describe -n ${namespace} pod ${usedby} | grep "Controlled By" | awk '{print $3}')
# if echo ${controlledby} | grep "StatefulSet\|Deployment"
# then
# kubectl scale -n ${namespace} --replicas 0 ${controlledby}
# else
# controlledby1=$(kubectl describe -n ${namespace} ${controlledby} | grep "Controlled By" | awk '{print $3}')
# if echo ${controlledby1} | grep "StatefulSet\|Deployment"
# then
# kubectl scale -n ${namespace} --replicas 0 ${controlledby1}
# else
# controlledby2=$(kubectl describe -n ${namespace} ${controlledby} | grep "Controlled By" | awk '{print $3}')
# if echo ${controlledby2} | grep "StatefulSet\|Deployment"
# then
# kubectl scale -n ${namespace} --replicas 0 ${controlledby2}
# fi
# fi
# fi
# echo Waiting for pvc not being used
# max_retry=10
# counter=0
# until kubectl describe -n ${namespace} pvc ${pvc} | grep "Used By" | awk '{print $3}' | grep "<none>"
# do
# sleep 5
# [[ counter -eq $max_retry ]] && echo "Failed!" && break
# kubectl describe -n ${namespace} pvc ${pvc} | grep "Used By" | awk '{print $3}' | grep "<none>"
# echo -n .
# ((counter++))
# done
pv-migrate migrate ${pvc} pv-backup -i --dest-path ${namespace}/${pvc} --dest-namespace default --source-namespace ${namespace} -d | grep '❌\|✅ '
kubectl exec -it ${backuppod} -- bash -c "rm -f /nfs-backup/${namespace}--${pvc}.tar.gz; cd /pv-backup/${namespace}; tar -czf /nfs-backup/${namespace}--${pvc}.tar.gz ${pvc}; rm -rf ${pvc}"
echo ""
done
done

sleep 10

# echo enable flux
# flux resume kustomization --all -n flux-system > /dev/null

kubectl get pods -A --no-headers | grep pv- | awk '{ print $1 " " $2 }' | xargs -L1 kubectl delete pod -n
kubectl delete deployment pv-backup
kubectl delete persistentvolumeclaim pv-backup

0 comments on commit c9ed8d1

Please sign in to comment.