@@ -34,6 +34,7 @@ import (
34
34
. "github.com/onsi/ginkgo/v2"
35
35
. "github.com/onsi/gomega"
36
36
"github.com/prometheus/client_golang/prometheus/testutil"
37
+
37
38
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
38
39
"sigs.k8s.io/controller-runtime/pkg/certwatcher/metrics"
39
40
)
@@ -113,7 +114,7 @@ var _ = Describe("CertWatcher", func() {
113
114
Eventually (func () bool {
114
115
secondcert , _ := watcher .GetCertificate (nil )
115
116
first := firstcert .PrivateKey .(* rsa.PrivateKey )
116
- return first .Equal (secondcert .PrivateKey )
117
+ return first .Equal (secondcert .PrivateKey ) || firstcert . Leaf . SerialNumber == secondcert . Leaf . SerialNumber
117
118
}).ShouldNot (BeTrue ())
118
119
119
120
ctxCancel ()
@@ -143,14 +144,41 @@ var _ = Describe("CertWatcher", func() {
143
144
Eventually (func () bool {
144
145
secondcert , _ := watcher .GetCertificate (nil )
145
146
first := firstcert .PrivateKey .(* rsa.PrivateKey )
146
- return first .Equal (secondcert .PrivateKey )
147
+ return first .Equal (secondcert .PrivateKey ) || firstcert . Leaf . SerialNumber == secondcert . Leaf . SerialNumber
147
148
}).ShouldNot (BeTrue ())
148
149
149
150
ctxCancel ()
150
151
Eventually (doneCh , "4s" ).Should (BeClosed ())
151
152
Expect (called .Load ()).To (BeNumerically (">=" , 1 ))
152
153
})
153
154
155
+ It ("should reload currentCert after move out" , func () {
156
+ doneCh := startWatcher ()
157
+ called := atomic.Int64 {}
158
+ watcher .RegisterCallback (func (crt tls.Certificate ) {
159
+ called .Add (1 )
160
+ Expect (crt .Certificate ).ToNot (BeEmpty ())
161
+ })
162
+
163
+ firstcert , _ := watcher .GetCertificate (nil )
164
+
165
+ Expect (os .Rename (certPath , certPath + ".old" )).To (Succeed ())
166
+ Expect (os .Rename (keyPath , keyPath + ".old" )).To (Succeed ())
167
+
168
+ err := writeCerts (certPath , keyPath , "192.168.0.3" )
169
+ Expect (err ).ToNot (HaveOccurred ())
170
+
171
+ Eventually (func () bool {
172
+ secondcert , _ := watcher .GetCertificate (nil )
173
+ first := firstcert .PrivateKey .(* rsa.PrivateKey )
174
+ return first .Equal (secondcert .PrivateKey ) || firstcert .Leaf .SerialNumber == secondcert .Leaf .SerialNumber
175
+ }, "10s" , "1s" ).ShouldNot (BeTrue ())
176
+
177
+ ctxCancel ()
178
+ Eventually (doneCh , "4s" ).Should (BeClosed ())
179
+ Expect (called .Load ()).To (BeNumerically (">=" , 1 ))
180
+ })
181
+
154
182
Context ("prometheus metric read_certificate_total" , func () {
155
183
var readCertificateTotalBefore float64
156
184
var readCertificateErrorsBefore float64
0 commit comments