@@ -121,6 +121,39 @@ var _ = Describe("CertWatcher", func() {
121
121
Expect (called .Load ()).To (BeNumerically (">=" , 1 ))
122
122
})
123
123
124
+ It ("should reload currentCert when changed with rename" , func () {
125
+ doneCh := startWatcher ()
126
+ called := atomic.Int64 {}
127
+ watcher .RegisterCallback (func (crt tls.Certificate ) {
128
+ called .Add (1 )
129
+ Expect (crt .Certificate ).ToNot (BeEmpty ())
130
+ })
131
+
132
+ firstcert , _ := watcher .GetCertificate (nil )
133
+
134
+ err := writeCerts (certPath + ".new" , keyPath + ".new" , "192.168.0.2" )
135
+ Expect (err ).ToNot (HaveOccurred ())
136
+
137
+ Expect (os .Link (certPath , certPath + ".old" )).To (Succeed ())
138
+ Expect (os .Rename (certPath + ".new" , certPath )).To (Succeed ())
139
+
140
+ Expect (os .Link (keyPath , keyPath + ".old" )).To (Succeed ())
141
+ Expect (os .Rename (keyPath + ".new" , keyPath )).To (Succeed ())
142
+
143
+ Expect (os .Remove (certPath + ".old" )).To (Succeed ())
144
+ Expect (os .Remove (keyPath + ".old" )).To (Succeed ())
145
+
146
+ Eventually (func () bool {
147
+ secondcert , _ := watcher .GetCertificate (nil )
148
+ first := firstcert .PrivateKey .(* rsa.PrivateKey )
149
+ return first .Equal (secondcert .PrivateKey )
150
+ }).ShouldNot (BeTrue ())
151
+
152
+ ctxCancel ()
153
+ Eventually (doneCh , "4s" ).Should (BeClosed ())
154
+ Expect (called .Load ()).To (BeNumerically (">=" , 1 ))
155
+ })
156
+
124
157
Context ("prometheus metric read_certificate_total" , func () {
125
158
var readCertificateTotalBefore float64
126
159
var readCertificateErrorsBefore float64
0 commit comments