Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#836 from adrianludwin/cert-restart
Browse files Browse the repository at this point in the history
Restart the pod if certs change
  • Loading branch information
k8s-ci-robot authored Jul 2, 2020
2 parents b8e6e1a + b070055 commit efa6555
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion incubator/hnc/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ spec:
- "--metrics-addr=127.0.0.1:8080"
- "--max-reconciles=10"
- "--apiserver-qps-throttle=50"
- "--enable-internal-cert-management=true"
- "--enable-internal-cert-management"
- "--cert-restart-on-secret-refresh"
image: controller:latest
name: manager
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/x509/pkix"
"encoding/base64"
"encoding/pem"
"flag"
"fmt"
"math/big"
"os"
Expand Down Expand Up @@ -47,6 +48,12 @@ var vwhGVK = schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Vers

var _ manager.Runnable = &CertRotator{}

var restartOnSecretRefresh = false

func init() {
flag.BoolVar(&restartOnSecretRefresh, "cert-restart-on-secret-refresh", false, "Kills the process when secrets are refreshed so that the pod can be restarted (secrets take up to 60s to be updated by running pods)")
}

// AddRotator adds the CertRotator and ReconcileVWH to the manager.
func AddRotator(mgr manager.Manager, cr *CertRotator, vwhName string) error {
cr.client = mgr.GetClient()
Expand Down Expand Up @@ -129,6 +136,10 @@ func (cr *CertRotator) refreshCertIfNeeded() error {
return false, nil
}
crLog.Info("server certs refreshed")
if restartOnSecretRefresh {
crLog.Info("Secrets have been updated; exiting so pod can be restarted (omit --cert-restart-on-secret-refresh to wait instead of restarting")
os.Exit(0)
}
return true, nil
}
// make sure our reconciler is initialized on startup (either this or the above refreshCerts() will call this)
Expand Down

0 comments on commit efa6555

Please sign in to comment.