Skip to content

Commit

Permalink
add rollout deployment option to acme chart
Browse files Browse the repository at this point in the history
  • Loading branch information
zubenkoivan committed Feb 15, 2022
1 parent 434d615 commit 7633dfb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
4 changes: 2 additions & 2 deletions charts/acme/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
version: 1.0.2
appVersion: 1.0.2
version: 1.0.3
appVersion: 1.0.3
name: acme
description: SSL certificate automatic issue and renewal using acme.sh script. https://github.com/acmesh-official/acme.sh
62 changes: 44 additions & 18 deletions charts/acme/files/acme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ _notify_hook=""
_force_option=""
_secret=()
_secret_namespace="default"
_rollout_deployment=""
_rollout_deployment_namespace="default"

_acme_install() {
curl https://get.acme.sh | sh -s email="$_email"
Expand All @@ -40,31 +42,39 @@ _acme_issue() {
acme.sh --set-notify --notify-hook "$_notify_hook"
fi

_renew_hook="$_script install-cert $_debug_option -d ${_domains[0]}"

if [ ! -z "$_secret" ]; then
_renew_hook="$_renew_hook --secret $_secret --secret-namespace $_secret_namespace"
fi

if [ ! -z "$_rollout_deployment" ]; then
_renew_hook="$_renew_hook --rollout-deployment $_rollout_deployment --rollout-deployment-namespace $_rollout_deployment_namespace"
fi

acme.sh --issue \
--dns dns_$_dns \
--server $_server \
--renew-hook "$_script install-cert $_debug_option -d ${_domains[0]} --secret $_secret --secret-namespace $_secret_namespace" \
--renew-hook "$_renew_hook" \
$_debug_option \
$_force_option \
$_domain_options \
|| true

$_script install-cert \
$_debug_option \
-d ${_domains[0]}\
--secret $_secret \
--secret-namespace $_secret_namespace
-d "${_domains[0]}" \
--secret "$_secret" \
--secret-namespace "$_secret_namespace" \
--rollout-deployment "$_rollout_deployment" \
--rollout-deployment-namespace "$_rollout_deployment_namespace"
}

_acme_install_cert() {
if [ ${#_domains[@]} == 0 ]; then
echo "Domain is required."
exit 1
fi
if [ -z "$_secret" ]; then
echo "Secret is required."
exit 1
fi

local _path="$HOME/certs"

Expand All @@ -77,15 +87,21 @@ _acme_install_cert() {
--fullchain-file $_path/fullchain.pem \
--key-file $_path/key.pem

kubectl create secret generic $_secret \
-n $_secret_namespace \
--from-file=cert.crt=$_path/fullchain.pem \
--from-file=cert.key=$_path/key.pem \
--save-config \
--dry-run \
-o yaml \
2>/dev/null | \
kubectl apply -f -
if [ ! -z "$_secret" ]; then
kubectl create secret generic $_secret \
-n $_secret_namespace \
--from-file=cert.crt=$_path/fullchain.pem \
--from-file=cert.key=$_path/key.pem \
--save-config \
--dry-run \
-o yaml \
2>/dev/null | \
kubectl apply -f -
fi

if [ ! -z "$_rollout_deployment" ]; then
kubectl rollout restart deployment/$_rollout_deployment -n $_rollout_deployment_namespace
fi
}

shift # past cmd
Expand Down Expand Up @@ -118,7 +134,7 @@ while [[ $# -gt 0 ]]; do
shift # past argument
shift # past value
;;
--notify)
--notify-hook)
_notify_hook="$2"
shift # past argument
shift # past value
Expand All @@ -137,6 +153,16 @@ while [[ $# -gt 0 ]]; do
shift # past argument
shift # past value
;;
--rollout-deployment)
_rollout_deployment="$2"
shift # past argument
shift # past value
;;
--rollout-deployment-namespace)
_rollout_deployment_namespace="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
Expand Down
10 changes: 8 additions & 2 deletions charts/acme/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ spec:
{{- range .Values.acme.domains }}
--domain "{{ . }}" \
{{- end }}
{{- if .Values.acme.notify }}
--notify {{ .Values.acme.notify }} \
{{- if .Values.acme.notifyHook }}
--notify-hook {{ .Values.acme.notifyHook }} \
{{- end }}
{{- if .Values.acme.sslCertSecretName }}
--secret {{ .Values.acme.sslCertSecretName }} \
--secret-namespace {{ .Release.Namespace }} \
{{- end }}
{{- if .Values.acme.rolloutDeploymentName }}
--rollout-deployment {{ .Values.acme.rolloutDeploymentName }} \
--rollout-deployment-namespace {{ .Release.Namespace }} \
{{- end }}
&
tail -f /dev/null
Expand Down
3 changes: 2 additions & 1 deletion charts/acme/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ bashImage:
acme:
email: ""
dns: ""
notify: ""
server: letsencrypt
domains: []
notifyHook: ""
sslCertSecretName: ssl-cert
rolloutDeploymentName: ""

podLabels: {}

Expand Down

0 comments on commit 7633dfb

Please sign in to comment.