-
Notifications
You must be signed in to change notification settings - Fork 0
/
renew.sh
33 lines (20 loc) · 964 Bytes
/
renew.sh
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
#!/bin/bash
set -e
export CERT_NAME=$(kubectl get certificates -o name | cut -d'/' -f 2)
export ORIGINAL_CERT_EXPIRY=$(kubectl get certificate -o=jsonpath='{.items[0].status.notAfter}')
echo "Certificate expires on $ORIGINAL_CERT_EXPIRY"
kubectl delete certificate $CERT_NAME
export CERTS_SECRET=$(kubectl get secrets -o=jsonpath='{.items[1].metadata.name}')
kubectl delete secrets $CERTS_SECRET
kubectl apply -f ./cluster-issuer.yaml
echo "Sleeping for 40 seconds to give the certificate time to generate"
sleep 40
export NEW_CERT_EXPIRY=$(kubectl get certificate -o=jsonpath='{.items[0].status.notAfter}')
echo "New Certificate expires on $NEW_CERT_EXPIRY"
if [ $NEW_CERT_EXPIRY_DATE -ge $ORIGINAL_CERT_EXPIRY_DATE ];
then
echo "Success! New certificate generated. New expiry date is $NEW_CERT_EXPIRY"
else
echo "***ERROR!! Expiry date not updated. Old expiry date: $ORIGINAL_CERT_EXPIRY. New expiry date: $NEW_CERT_EXPIRY"
exit 1
fi