@@ -67,7 +67,7 @@ type Controller struct {
67
67
68
68
// Reconcile performs a full reconciliation for the object referred to by the Request.
69
69
func (c * Controller ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
70
- klog .V (4 ).Infof ("Reconciling cluster %s" , req .NamespacedName . String () )
70
+ klog .V (4 ).InfoS ("Reconciling cluster" , "cluster" , req .Name )
71
71
72
72
cluster := & clusterv1alpha1.Cluster {}
73
73
if err := c .Client .Get (ctx , req .NamespacedName , cluster ); err != nil {
@@ -86,13 +86,13 @@ func (c *Controller) Reconcile(ctx context.Context, req controllerruntime.Reques
86
86
}
87
87
88
88
if cluster .Spec .ImpersonatorSecretRef == nil {
89
- klog .Infof ("Unified auth is disabled on cluster %s as it does not have an impersonator secret" , cluster .Name )
89
+ klog .InfoS ("Unified auth is disabled: no impersonator secret" , "cluster " , cluster .Name )
90
90
return controllerruntime.Result {}, nil
91
91
}
92
92
93
93
err := c .syncImpersonationConfig (ctx , cluster )
94
94
if err != nil {
95
- klog .Errorf ( "Failed to sync impersonation config for cluster %s. Error: %v. " , cluster .Name , err )
95
+ klog .ErrorS ( err , "Failed to sync impersonation config" , " cluster" , cluster .Name )
96
96
c .EventRecorder .Eventf (cluster , corev1 .EventTypeWarning , events .EventReasonSyncImpersonationConfigFailed , err .Error ())
97
97
return controllerruntime.Result {}, err
98
98
}
@@ -113,13 +113,13 @@ func (c *Controller) syncImpersonationConfig(ctx context.Context, cluster *clust
113
113
114
114
// step3: sync ClusterRole to cluster for impersonation
115
115
if err := c .buildImpersonationClusterRole (ctx , cluster , rules ); err != nil {
116
- klog .Errorf ( "Failed to sync impersonate ClusterRole to cluster(%s): %v" , cluster .Name , err )
116
+ klog .ErrorS ( err , "Failed to sync impersonate ClusterRole to cluster" , "cluster" , cluster .Name )
117
117
return err
118
118
}
119
119
120
120
// step4: sync ClusterRoleBinding to cluster for impersonation
121
121
if err := c .buildImpersonationClusterRoleBinding (ctx , cluster ); err != nil {
122
- klog .Errorf ( "Failed to sync impersonate ClusterRoleBinding to cluster(%s): %v" , cluster .Name , err )
122
+ klog .ErrorS ( err , "Failed to sync impersonate ClusterRoleBinding to cluster" , "cluster" , cluster .Name )
123
123
return err
124
124
}
125
125
@@ -129,7 +129,7 @@ func (c *Controller) syncImpersonationConfig(ctx context.Context, cluster *clust
129
129
func findRBACSubjectsWithCluster (ctx context.Context , c client.Client , cluster string ) ([]rbacv1.Subject , error ) {
130
130
clusterRoleList := & rbacv1.ClusterRoleList {}
131
131
if err := c .List (ctx , clusterRoleList ); err != nil {
132
- klog .Errorf ( "Failed to list ClusterRoles, error: %v" , err )
132
+ klog .ErrorS ( err , "Failed to list ClusterRoles" , "cluster" , cluster )
133
133
return nil , err
134
134
}
135
135
@@ -158,7 +158,7 @@ func findRBACSubjectsWithCluster(ctx context.Context, c client.Client, cluster s
158
158
159
159
clusterRoleBindings := & rbacv1.ClusterRoleBindingList {}
160
160
if err := c .List (ctx , clusterRoleBindings ); err != nil {
161
- klog .Errorf ( "Failed to list ClusterRoleBindings, error: %v" , err )
161
+ klog .ErrorS ( err , "Failed to list ClusterRoleBindings" , "cluster" , cluster )
162
162
return nil , err
163
163
}
164
164
@@ -189,7 +189,7 @@ func (c *Controller) buildImpersonationClusterRole(ctx context.Context, cluster
189
189
190
190
clusterRoleObj , err := helper .ToUnstructured (impersonationClusterRole )
191
191
if err != nil {
192
- klog .Errorf ( "Failed to transform ClusterRole %s. Error: %v" , impersonationClusterRole .GetName (), err )
192
+ klog .ErrorS ( err , "Failed to transform ClusterRole" , "name" , impersonationClusterRole .GetName (), "cluster" , cluster . Name )
193
193
return err
194
194
}
195
195
@@ -224,7 +224,7 @@ func (c *Controller) buildImpersonationClusterRoleBinding(ctx context.Context, c
224
224
225
225
clusterRoleBindingObj , err := helper .ToUnstructured (impersonatorClusterRoleBinding )
226
226
if err != nil {
227
- klog .Errorf ( "Failed to transform ClusterRoleBinding %s. Error: %v" , impersonatorClusterRoleBinding .GetName (), err )
227
+ klog .ErrorS ( err , "Failed to transform ClusterRoleBinding" , "name" , impersonatorClusterRoleBinding .GetName (), "cluster" , cluster . Name )
228
228
return err
229
229
}
230
230
@@ -283,7 +283,7 @@ func (c *Controller) newClusterRoleBindingMapFunc() handler.MapFunc {
283
283
284
284
clusterRole := & rbacv1.ClusterRole {}
285
285
if err := c .Client .Get (ctx , types.NamespacedName {Name : clusterRoleBinding .RoleRef .Name }, clusterRole ); err != nil {
286
- klog .Errorf ( "Failed to get reference ClusterRole, error: %v" , err )
286
+ klog .ErrorS ( err , "Failed to get reference ClusterRole" , "name" , clusterRoleBinding . RoleRef . Name )
287
287
return nil
288
288
}
289
289
return c .generateRequestsFromClusterRole (ctx , clusterRole )
@@ -294,7 +294,7 @@ func (c *Controller) newClusterRoleBindingMapFunc() handler.MapFunc {
294
294
func (c * Controller ) generateRequestsFromClusterRole (ctx context.Context , clusterRole * rbacv1.ClusterRole ) []reconcile.Request {
295
295
clusterList := & clusterv1alpha1.ClusterList {}
296
296
if err := c .Client .List (ctx , clusterList ); err != nil {
297
- klog .Errorf ( "Failed to list existing clusters, error: %v" , err )
297
+ klog .ErrorS ( err , "Failed to list existing clusters" )
298
298
return nil
299
299
}
300
300
0 commit comments