6
6
"os"
7
7
"path/filepath"
8
8
"strings"
9
+ "sync"
9
10
"time"
10
11
11
12
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
@@ -66,6 +67,7 @@ func Setup(ctx context.Context, nodeConfig *daemonconfig.Node, dataDir string) e
66
67
}
67
68
deps .CreateRuntimeCertFiles (& controlConfig )
68
69
70
+ startupOnce := & sync.Once {}
69
71
caMap := map [string ][]string {}
70
72
nodeList := services .Agent
71
73
if _ , err := os .Stat (controlConfig .DataDir ); err == nil {
@@ -83,15 +85,25 @@ func Setup(ctx context.Context, nodeConfig *daemonconfig.Node, dataDir string) e
83
85
84
86
go wait .Until (func () {
85
87
logrus .Debugf ("Running %s certificate expiration check" , controllerName )
88
+ var hasErr bool
86
89
if err := checkCerts (nodeMap , time .Hour * 24 * daemonconfig .CertificateRenewDays ); err != nil {
87
90
message := fmt .Sprintf ("Node certificates require attention - restart %s on this node to trigger automatic rotation: %v" , version .Program , err )
88
91
recorder .Event (nodeRef , corev1 .EventTypeWarning , "CertificateExpirationWarning" , message )
92
+ hasErr = true
89
93
}
90
94
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 )
92
96
recorder .Event (nodeRef , corev1 .EventTypeWarning , "CACertificateExpirationWarning" , message )
93
-
97
+ hasErr = true
94
98
}
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
+
95
107
}, certCheckInterval , ctx .Done ())
96
108
97
109
return nil
0 commit comments