@@ -68,7 +68,7 @@ type Controller struct {
68
68
// The Controller will requeue the Request to be processed again if an error is non-nil or
69
69
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
70
70
func (c * Controller ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
71
- klog .V (4 ).Infof ("Namespaces sync controller reconciling %s " , req .NamespacedName .String ())
71
+ klog .V (4 ).InfoS ("Namespaces sync controller reconciling namespace" , "namespace " , req .NamespacedName .String ())
72
72
if ! c .namespaceShouldBeSynced (req .Name ) {
73
73
return controllerruntime.Result {}, nil
74
74
}
@@ -91,19 +91,19 @@ func (c *Controller) Reconcile(ctx context.Context, req controllerruntime.Reques
91
91
92
92
skipAutoPropagation := util .GetLabelValue (namespace .Labels , policyv1alpha1 .NamespaceSkipAutoPropagationLabel )
93
93
if strings .ToLower (skipAutoPropagation ) == "true" {
94
- klog .Infof ("Skip auto propagation namespace:%s " , namespace .Name )
94
+ klog .InfoS ("Skip auto propagation namespace" , "namespace " , namespace .Name )
95
95
return controllerruntime.Result {}, nil
96
96
}
97
97
98
98
clusterList := & clusterv1alpha1.ClusterList {}
99
99
if err := c .Client .List (ctx , clusterList ); err != nil {
100
- klog .Errorf ( "Failed to list clusters, error: %v" , err )
100
+ klog .ErrorS ( err , "Failed to list clusters" )
101
101
return controllerruntime.Result {}, err
102
102
}
103
103
104
104
err := c .buildWorks (ctx , namespace , clusterList .Items )
105
105
if err != nil {
106
- klog .Errorf ( "Failed to build work for namespace %s. Error: %v." , namespace .GetName (), err )
106
+ klog .ErrorS ( err , "Failed to build work for namespace" , "namespace" , namespace .GetName ())
107
107
return controllerruntime.Result {}, err
108
108
}
109
109
@@ -126,7 +126,7 @@ func (c *Controller) namespaceShouldBeSynced(namespace string) bool {
126
126
func (c * Controller ) buildWorks (ctx context.Context , namespace * corev1.Namespace , clusters []clusterv1alpha1.Cluster ) error {
127
127
namespaceObj , err := helper .ToUnstructured (namespace )
128
128
if err != nil {
129
- klog .Errorf ( "Failed to transform namespace %s. Error: %v" , namespace .GetName (), err )
129
+ klog .ErrorS ( err , "Failed to transform namespace" , "namespace" , namespace .GetName ())
130
130
return err
131
131
}
132
132
@@ -138,14 +138,14 @@ func (c *Controller) buildWorks(ctx context.Context, namespace *corev1.Namespace
138
138
// namespace only care about ClusterOverridePolicy
139
139
cops , _ , err := c .OverrideManager .ApplyOverridePolicies (clonedNamespaced , cluster .Name )
140
140
if err != nil {
141
- klog .Errorf ( "Failed to apply overrides for %s/%s/%s, err is: %v" , clonedNamespaced .GetKind (), clonedNamespaced . GetNamespace (), clonedNamespaced .GetName (), err )
141
+ klog .ErrorS ( err , "Failed to apply overrides for namespace" , "namespace" , clonedNamespaced .GetName (), "cluster" , cluster .GetName ())
142
142
ch <- fmt .Errorf ("sync namespace(%s) to cluster(%s) failed due to: %v" , clonedNamespaced .GetName (), cluster .GetName (), err )
143
143
return
144
144
}
145
145
146
146
annotations , err := binding .RecordAppliedOverrides (cops , nil , nil )
147
147
if err != nil {
148
- klog .Errorf ( "Failed to record appliedOverrides, Error: %v" , err )
148
+ klog .ErrorS ( err , "Failed to record appliedOverrides" )
149
149
ch <- fmt .Errorf ("sync namespace(%s) to cluster(%s) failed due to: %v" , clonedNamespaced .GetName (), cluster .GetName (), err )
150
150
return
151
151
}
@@ -186,7 +186,7 @@ func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
186
186
var requests []reconcile.Request
187
187
namespaceList := & corev1.NamespaceList {}
188
188
if err := c .Client .List (ctx , namespaceList ); err != nil {
189
- klog .Errorf ( "Failed to list namespace, error: %v" , err )
189
+ klog .ErrorS ( err , "Failed to list namespace" )
190
190
return nil
191
191
}
192
192
@@ -239,7 +239,7 @@ func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
239
239
if containsAllNamespace {
240
240
namespaceList := & corev1.NamespaceList {}
241
241
if err := c .Client .List (context .TODO (), namespaceList ); err != nil {
242
- klog .Errorf ( "Failed to list namespace, error: %v" , err )
242
+ klog .ErrorS ( err , "Failed to list namespace" )
243
243
return nil
244
244
}
245
245
0 commit comments