@@ -18,6 +18,7 @@ import (
1818 "k8s.io/apimachinery/pkg/types"
1919 "k8s.io/client-go/rest"
2020 "k8s.io/client-go/tools/record"
21+ "k8s.io/klog/v2"
2122
2223 ctrl "sigs.k8s.io/controller-runtime"
2324 "sigs.k8s.io/controller-runtime/pkg/builder"
@@ -27,8 +28,6 @@ import (
2728 "sigs.k8s.io/controller-runtime/pkg/predicate"
2829 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2930
30- "github.com/go-logr/logr"
31-
3231 certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
3332
3433 v1alpha1 "github.com/openshift/cert-manager-operator/api/operator/v1alpha1"
@@ -50,7 +49,6 @@ type Reconciler struct {
5049
5150 ctx context.Context
5251 eventRecorder record.EventRecorder
53- log logr.Logger
5452 scheme * runtime.Scheme
5553}
5654
@@ -116,15 +114,14 @@ func New(mgr ctrl.Manager) (*Reconciler, error) {
116114 ctrlClient : c ,
117115 ctx : context .Background (),
118116 eventRecorder : mgr .GetEventRecorderFor (ControllerName ),
119- log : ctrl .Log .WithName (ControllerName ),
120117 scheme : mgr .GetScheme (),
121118 }, nil
122119}
123120
124121// SetupWithManager sets up the controller with the Manager.
125122func (r * Reconciler ) SetupWithManager (mgr ctrl.Manager ) error {
126123 mapFunc := func (ctx context.Context , obj client.Object ) []reconcile.Request {
127- r . log . V (4 ).Info ("received reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
124+ klog . V (4 ).InfoS ("received reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
128125
129126 objLabels := obj .GetLabels ()
130127 if objLabels != nil {
@@ -146,7 +143,10 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
146143 }
147144 key := strings .Split (value , "_" )
148145 if len (key ) != 2 {
149- r .log .Error (fmt .Errorf ("invalid label format" ), "%s label value(%s) not in expected format on %s resource" , IstiocsrResourceWatchLabelName , value , obj .GetName ())
146+ klog .ErrorS (fmt .Errorf ("invalid label format" ), "label value not in expected format" ,
147+ "labelName" , IstiocsrResourceWatchLabelName ,
148+ "labelValue" , value ,
149+ "resource" , obj .GetName ())
150150 return false
151151 }
152152 namespace = key [0 ]
@@ -165,7 +165,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
165165 }
166166 }
167167
168- r . log . V (4 ).Info ("object not of interest, ignoring reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
168+ klog . V (4 ).InfoS ("object not of interest, ignoring reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
169169 return []reconcile.Request {}
170170 }
171171
@@ -214,7 +214,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
214214// Reconcile function to compare the state specified by the IstioCSR object against the actual cluster state,
215215// and to make the cluster state reflect the state specified by the user.
216216func (r * Reconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
217- r . log . V (1 ).Info ("reconciling" , "request" , req )
217+ klog . V (1 ).InfoS ("reconciling" , "request" , req )
218218
219219 // Fetch the istiocsr.openshift.operator.io CR
220220 istiocsr := & v1alpha1.IstioCSR {}
@@ -223,14 +223,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
223223 // NotFound errors, since they can't be fixed by an immediate
224224 // requeue (have to wait for a new notification), and can be processed
225225 // on deleted requests.
226- r . log . V (1 ).Info ("istiocsr.openshift.operator.io object not found, skipping reconciliation" , "request" , req )
226+ klog . V (1 ).InfoS ("istiocsr.openshift.operator.io object not found, skipping reconciliation" , "request" , req )
227227 return ctrl.Result {}, nil
228228 }
229229 return ctrl.Result {}, fmt .Errorf ("failed to fetch istiocsr.openshift.operator.io %q during reconciliation: %w" , req .NamespacedName , err )
230230 }
231231
232232 if ! istiocsr .DeletionTimestamp .IsZero () {
233- r . log . V (1 ).Info ("istiocsr.openshift.operator.io is marked for deletion" , "namespace" , req .NamespacedName )
233+ klog . V (1 ).InfoS ("istiocsr.openshift.operator.io is marked for deletion" , "namespace" , req .NamespacedName )
234234
235235 if requeue , err := r .cleanUp (istiocsr ); err != nil {
236236 return ctrl.Result {}, fmt .Errorf ("clean up failed for %q istiocsr.openshift.operator.io instance deletion: %w" , req .NamespacedName , err )
@@ -242,7 +242,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
242242 return ctrl.Result {}, err
243243 }
244244
245- r . log . V (1 ).Info ("removed finalizer, cleanup complete" , "request" , req .NamespacedName )
245+ klog . V (1 ).InfoS ("removed finalizer, cleanup complete" , "request" , req .NamespacedName )
246246 return ctrl.Result {}, nil
247247 }
248248
@@ -257,7 +257,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
257257func (r * Reconciler ) processReconcileRequest (istiocsr * v1alpha1.IstioCSR , req types.NamespacedName ) (ctrl.Result , error ) {
258258 istioCSRCreateRecon := false
259259 if ! containsProcessedAnnotation (istiocsr ) && reflect .DeepEqual (istiocsr .Status , v1alpha1.IstioCSRStatus {}) {
260- r . log . V (1 ).Info ("starting reconciliation of newly created istiocsr" , "namespace" , istiocsr .GetNamespace (), "name" , istiocsr .GetName ())
260+ klog . V (1 ).InfoS ("starting reconciliation of newly created istiocsr" , "namespace" , istiocsr .GetNamespace (), "name" , istiocsr .GetName ())
261261 istioCSRCreateRecon = true
262262 }
263263
@@ -271,14 +271,14 @@ func (r *Reconciler) processReconcileRequest(istiocsr *v1alpha1.IstioCSR, req ty
271271
272272 var errUpdate error = nil
273273 if err := r .reconcileIstioCSRDeployment (istiocsr , istioCSRCreateRecon ); err != nil {
274- r . log . Error (err , "failed to reconcile IstioCSR deployment" , "request" , req )
274+ klog . ErrorS (err , "failed to reconcile IstioCSR deployment" , "request" , req )
275275 if IsIrrecoverableError (err ) {
276276 // Set both conditions atomically before updating status
277277 degradedChanged := istiocsr .Status .SetCondition (v1alpha1 .Degraded , metav1 .ConditionTrue , v1alpha1 .ReasonFailed , fmt .Sprintf ("reconciliation failed with irrecoverable error not retrying: %v" , err ))
278278 readyChanged := istiocsr .Status .SetCondition (v1alpha1 .Ready , metav1 .ConditionFalse , v1alpha1 .ReasonReady , "" )
279279
280280 if degradedChanged || readyChanged {
281- r . log . V (2 ).Info ("updating istiocsr conditions on irrecoverable error" ,
281+ klog . V (2 ).InfoS ("updating istiocsr conditions on irrecoverable error" ,
282282 "namespace" , istiocsr .GetNamespace (),
283283 "name" , istiocsr .GetName (),
284284 "degradedChanged" , degradedChanged ,
@@ -293,7 +293,7 @@ func (r *Reconciler) processReconcileRequest(istiocsr *v1alpha1.IstioCSR, req ty
293293 readyChanged := istiocsr .Status .SetCondition (v1alpha1 .Ready , metav1 .ConditionFalse , v1alpha1 .ReasonInProgress , fmt .Sprintf ("reconciliation failed, retrying: %v" , err ))
294294
295295 if degradedChanged || readyChanged {
296- r . log . V (2 ).Info ("updating istiocsr conditions on recoverable error" ,
296+ klog . V (2 ).InfoS ("updating istiocsr conditions on recoverable error" ,
297297 "namespace" , istiocsr .GetNamespace (),
298298 "name" , istiocsr .GetName (),
299299 "degradedChanged" , degradedChanged ,
@@ -315,7 +315,7 @@ func (r *Reconciler) processReconcileRequest(istiocsr *v1alpha1.IstioCSR, req ty
315315 readyChanged := istiocsr .Status .SetCondition (v1alpha1 .Ready , metav1 .ConditionTrue , v1alpha1 .ReasonReady , "reconciliation successful" )
316316
317317 if degradedChanged || readyChanged {
318- r . log . V (2 ).Info ("updating istiocsr conditions on successful reconciliation" ,
318+ klog . V (2 ).InfoS ("updating istiocsr conditions on successful reconciliation" ,
319319 "namespace" , istiocsr .GetNamespace (),
320320 "name" , istiocsr .GetName (),
321321 "degradedChanged" , degradedChanged ,
0 commit comments