@@ -24,16 +24,19 @@ func HTTPClient(
2424 url : caUrl ,
2525 privkey : privkey ,
2626 }
27- if _ , err := cr .GetClientCertificate (nil ); err != nil {
27+ if _ , err := cr .getClientCertificate (nil ); err != nil {
2828 return nil , err
2929 }
30+
3031 tlsConfig := & tls.Config {
31- GetClientCertificate : cr .GetClientCertificate ,
32+ GetClientCertificate : cr .getClientCertificate ,
3233 RootCAs : roots ,
3334 KeyLogWriter : ssllog ,
3435 }
36+
3537 tlsTransport := http .DefaultTransport .(* http.Transport ).Clone ()
3638 tlsTransport .TLSClientConfig = tlsConfig
39+
3740 return & http.Client {
3841 Transport : tlsTransport ,
3942 }, nil
@@ -45,17 +48,16 @@ type certRefresher struct {
4548 cert atomic.Pointer [Certificate ]
4649}
4750
48- func (cr * certRefresher ) GetClientCertificate (
51+ func (cr * certRefresher ) getClientCertificate (
4952 info * tls.CertificateRequestInfo ,
5053) (* tls.Certificate , error ) {
5154 ctx := context .Background ()
5255 if info != nil {
5356 ctx = info .Context ()
5457 }
5558
56- // If the certificate is nil or is going to expire soon, request a new one.
57- if cert := cr .cert .Load (); cert == nil ||
58- cert .NotAfter .Before (time .Now ().Add (- time .Minute * 10 )) {
59+ // If we don't have a certificate or it's about to expire, request a new one.
60+ if cert := cr .cert .Load (); cert == nil || time .Until (cert .NotAfter ) < 10 * time .Minute {
5961 Logger ().DebugContext (ctx , "refreshing client certificate" )
6062
6163 cert , err := RequestCertificate (ctx , cr .url , cr .privkey )
@@ -69,7 +71,8 @@ func (cr *certRefresher) GetClientCertificate(
6971 break
7072 }
7173 }
72- Logger ().InfoContext (ctx , "got new client certificate" )
74+ Logger ().InfoContext (ctx , "got new client certificate" ,
75+ "namespace" , cert .Namespace , "uuid" , cert .ID )
7376 }
7477
7578 tlsCert := X509ToTLSCertificate (cr .cert .Load ().Certificate , cr .privkey .PrivateKey )
0 commit comments