Skip to content

Commit d44545b

Browse files
committed
Emit certs OK event on startup, if no certs need renewal
Signed-off-by: Brad Davidson <[email protected]>
1 parent d56e4e8 commit d44545b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/certmonitor/certmonitor.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"strings"
9+
"sync"
910
"time"
1011

1112
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
@@ -66,6 +67,7 @@ func Setup(ctx context.Context, nodeConfig *daemonconfig.Node, dataDir string) e
6667
}
6768
deps.CreateRuntimeCertFiles(&controlConfig)
6869

70+
startupOnce := &sync.Once{}
6971
caMap := map[string][]string{}
7072
nodeList := services.Agent
7173
if _, err := os.Stat(controlConfig.DataDir); err == nil {
@@ -83,15 +85,25 @@ func Setup(ctx context.Context, nodeConfig *daemonconfig.Node, dataDir string) e
8385

8486
go wait.Until(func() {
8587
logrus.Debugf("Running %s certificate expiration check", controllerName)
88+
var hasErr bool
8689
if err := checkCerts(nodeMap, time.Hour*24*daemonconfig.CertificateRenewDays); err != nil {
8790
message := fmt.Sprintf("Node certificates require attention - restart %s on this node to trigger automatic rotation: %v", version.Program, err)
8891
recorder.Event(nodeRef, corev1.EventTypeWarning, "CertificateExpirationWarning", message)
92+
hasErr = true
8993
}
9094
if err := checkCerts(caMap, time.Hour*24*365); err != nil {
91-
message := fmt.Sprintf("Certificate authority certificates require attention - check %s documentation and begin planning rotation: %v", version.Program, err)
95+
message := fmt.Sprintf("Certificate Authority certificates require attention - check %s documentation and begin planning rotation: %v", version.Program, err)
9296
recorder.Event(nodeRef, corev1.EventTypeWarning, "CACertificateExpirationWarning", message)
93-
97+
hasErr = true
9498
}
99+
// Only check for no errors and emit an OK event once, on the initial check after startup.
100+
startupOnce.Do(func() {
101+
if !hasErr {
102+
message := fmt.Sprintf("Node and Certificate Authority certificates managed by %s are OK", version.Program)
103+
recorder.Event(nodeRef, corev1.EventTypeNormal, "CertificateExpirationOK", message)
104+
}
105+
})
106+
95107
}, certCheckInterval, ctx.Done())
96108

97109
return nil

0 commit comments

Comments
 (0)