@@ -87,7 +87,7 @@ type CertRotationController struct {
87
87
// The Controller will requeue the Request to be processed again if an error is non-nil or
88
88
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
89
89
func (c * CertRotationController ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
90
- klog .V (4 ).Infof ("Rotating the certificate of karmada-agent for the member cluster: %s" , req .NamespacedName .Name )
90
+ klog .V (4 ).InfoS ("Rotating the certificate of karmada-agent for the member cluster" , "cluster" , req .NamespacedName .String () )
91
91
92
92
var err error
93
93
@@ -108,18 +108,18 @@ func (c *CertRotationController) Reconcile(ctx context.Context, req controllerru
108
108
// create a ClusterClient for the given member cluster
109
109
c .ClusterClient , err = c .ClusterClientSetFunc (cluster .Name , c .Client , c .ClusterClientOption )
110
110
if err != nil {
111
- klog .Errorf ( "Failed to create a ClusterClient for the given member cluster: %s, err is: %v" , cluster .Name , err )
111
+ klog .ErrorS ( err , "Failed to create a ClusterClient for the given member cluster" , "cluster" , cluster .Name )
112
112
return controllerruntime.Result {}, err
113
113
}
114
114
115
115
secret , err := c .ClusterClient .KubeClient .CoreV1 ().Secrets (c .KarmadaKubeconfigNamespace ).Get (ctx , KarmadaKubeconfigName , metav1.GetOptions {})
116
116
if err != nil {
117
- klog .Errorf ( "failed to get karmada kubeconfig secret: %v" , err )
117
+ klog .ErrorS ( err , "failed to get karmada kubeconfig secret" )
118
118
return controllerruntime.Result {}, err
119
119
}
120
120
121
121
if err = c .syncCertRotation (ctx , secret ); err != nil {
122
- klog .Errorf ( "Failed to rotate the certificate of karmada-agent for the given member cluster: %s, err is: %v" , cluster .Name , err )
122
+ klog .ErrorS ( err , "Failed to rotate the certificate of karmada-agent for the given member cluster" , "cluster" , cluster .Name )
123
123
return controllerruntime.Result {}, err
124
124
}
125
125
@@ -181,20 +181,20 @@ func (c *CertRotationController) syncCertRotation(ctx context.Context, secret *c
181
181
}
182
182
183
183
var newCertData []byte
184
- klog .V (1 ).Infof ("Waiting for the client certificate to be issued" )
184
+ klog .V (1 ).InfoS ("Waiting for the client certificate to be issued" )
185
185
err = wait .PollUntilContextTimeout (ctx , 1 * time .Second , 5 * time .Minute , false , func (context.Context ) (done bool , err error ) {
186
186
csr , err := c .KubeClient .CertificatesV1 ().CertificateSigningRequests ().Get (ctx , csr , metav1.GetOptions {})
187
187
if err != nil {
188
188
return false , fmt .Errorf ("failed to get the cluster csr %s. err: %v" , clusterName , err )
189
189
}
190
190
191
191
if csr .Status .Certificate != nil {
192
- klog .V (1 ).Infof ("Signing certificate successfully" )
192
+ klog .V (1 ).InfoS ("Signing certificate successfully" )
193
193
newCertData = csr .Status .Certificate
194
194
return true , nil
195
195
}
196
196
197
- klog .V (1 ).Infof ("Waiting for the client certificate to be issued" )
197
+ klog .V (1 ).InfoS ("Waiting for the client certificate to be issued" )
198
198
return false , nil
199
199
})
200
200
if err != nil {
@@ -217,11 +217,11 @@ func (c *CertRotationController) syncCertRotation(ctx context.Context, secret *c
217
217
218
218
newCert , err := certutil .ParseCertsPEM (newCertData )
219
219
if err != nil {
220
- klog .Errorf ( "Unable to parse new certificate: %v" , err )
220
+ klog .ErrorS ( err , "Unable to parse new certificate" )
221
221
return err
222
222
}
223
223
224
- klog .V (4 ).Infof ("The certificate has been rotated successfully, new expiration time is %v " , newCert [0 ].NotAfter )
224
+ klog .V (4 ).InfoS ("The certificate has been rotated successfully" , " new expiration time" , newCert [0 ].NotAfter )
225
225
226
226
return nil
227
227
}
@@ -287,15 +287,15 @@ func (c *CertRotationController) shouldRotateCert(certData []byte) (bool, error)
287
287
288
288
total := notAfter .Sub (* notBefore )
289
289
remaining := time .Until (* notAfter )
290
- klog .V (4 ).Infof ("The certificate of karmada-agent: time total=%v, remaining=%v, remaining/total=%v " , total , remaining , remaining .Seconds ()/ total .Seconds ())
290
+ klog .V (4 ).InfoS ("The certificate of karmada-agent" , " time total" , total , " remaining" , remaining , " remaining/total" , remaining .Seconds ()/ total .Seconds ())
291
291
292
292
if remaining .Seconds ()/ total .Seconds () > c .CertRotationRemainingTimeThreshold {
293
293
// Do nothing if the certificate of karmada-agent is valid and has more than a valid threshold of its life remaining
294
- klog .V (4 ).Infof ("The certificate of karmada-agent is valid and has more than %.2f%% of its life remaining" , c .CertRotationRemainingTimeThreshold * 100 )
294
+ klog .V (4 ).InfoS ("The certificate of karmada-agent is valid and has more than the valid threshold of its life remaining" , "threshold " , c .CertRotationRemainingTimeThreshold * 100 )
295
295
return false , nil
296
296
}
297
297
298
- klog .V (4 ).Infof ("The certificate of karmada-agent has less than or equal %.2f%% of its life remaining and need to be rotated" , c .CertRotationRemainingTimeThreshold * 100 )
298
+ klog .V (4 ).InfoS ("The certificate of karmada-agent has less than or equal the valid threshold of its life remaining and need to be rotated" , "threshold " , c .CertRotationRemainingTimeThreshold * 100 )
299
299
return true , nil
300
300
}
301
301
0 commit comments