Created
March 16, 2023 15:09
-
-
Save cdoan1/d7ec1464fe394e1d6983a60adf8d1a0b to your computer and use it in GitHub Desktop.
Roate Certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function convert() { | |
echo $(date -d "$1" "+%s") | |
} | |
function dlog() { | |
echo $(date -u +"%Y-%m-%d-%I:%M:%S") $1 | |
} | |
for certificate in $(oc get certificate -n default -o name) | |
do | |
_before=$(oc get $certificate -n default -ojson | jq -r ".status.notBefore") | |
_renew=$(oc get $certificate -n default -ojson | jq -r ".status.renewalTime") | |
_DELTA=$(expr $(convert $_renew) - $(convert $_before)) | |
_a=$((_DELTA/3600)) | |
_b=$((_a - 4)) | |
_renewBefore=$_b | |
dlog " delta : $_DELTA" | |
dlog " set renewBefore : $_renewBefore" | |
oc patch $certificate -n default --patch ' | |
- op: replace | |
path: /spec/renewBefore | |
value: '$_renewBefore'h | |
- op: replace | |
path: /spec/duration | |
value: '$_a'h | |
' --type=json | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment