Skip to content

Instantly share code, notes, and snippets.

@cdoan1
Created March 16, 2023 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdoan1/d7ec1464fe394e1d6983a60adf8d1a0b to your computer and use it in GitHub Desktop.
Save cdoan1/d7ec1464fe394e1d6983a60adf8d1a0b to your computer and use it in GitHub Desktop.
Roate Certificate
#!/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