@@ -14,6 +14,7 @@ import (
1414 "k8s.io/apimachinery/pkg/runtime"
1515 "k8s.io/apimachinery/pkg/types"
1616 "k8s.io/client-go/tools/record"
17+ "k8s.io/klog/v2"
1718
1819 ctrl "sigs.k8s.io/controller-runtime"
1920 "sigs.k8s.io/controller-runtime/pkg/builder"
@@ -22,8 +23,6 @@ import (
2223 "sigs.k8s.io/controller-runtime/pkg/predicate"
2324 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2425
25- "github.com/go-logr/logr"
26-
2726 certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
2827
2928 v1alpha1 "github.com/openshift/cert-manager-operator/api/operator/v1alpha1"
@@ -41,7 +40,6 @@ type Reconciler struct {
4140
4241 ctx context.Context
4342 eventRecorder record.EventRecorder
44- log logr.Logger
4543 scheme * runtime.Scheme
4644}
4745
@@ -60,15 +58,14 @@ func New(mgr ctrl.Manager) (*Reconciler, error) {
6058 CtrlClient : c ,
6159 ctx : context .Background (),
6260 eventRecorder : mgr .GetEventRecorderFor (ControllerName ),
63- log : ctrl .Log .WithName (ControllerName ),
6461 scheme : mgr .GetScheme (),
6562 }, nil
6663}
6764
6865// SetupWithManager sets up the controller with the Manager.
6966func (r * Reconciler ) SetupWithManager (mgr ctrl.Manager ) error {
7067 mapFunc := func (ctx context.Context , obj client.Object ) []reconcile.Request {
71- r . log . V (4 ).Info ("received reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
68+ klog . V (4 ).InfoS ("received reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
7269
7370 objLabels := obj .GetLabels ()
7471 if objLabels != nil {
@@ -90,7 +87,10 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
9087 }
9188 key := strings .Split (value , "_" )
9289 if len (key ) != 2 {
93- r .log .Error (fmt .Errorf ("invalid label format" ), "%s label value(%s) not in expected format on %s resource" , IstiocsrResourceWatchLabelName , value , obj .GetName ())
90+ klog .ErrorS (fmt .Errorf ("invalid label format" ), "label value not in expected format" ,
91+ "labelName" , IstiocsrResourceWatchLabelName ,
92+ "labelValue" , value ,
93+ "resource" , obj .GetName ())
9494 return false
9595 }
9696 namespace = key [0 ]
@@ -109,7 +109,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
109109 }
110110 }
111111
112- r . log . V (4 ).Info ("object not of interest, ignoring reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
112+ klog . V (4 ).InfoS ("object not of interest, ignoring reconcile event" , "object" , fmt .Sprintf ("%T" , obj ), "name" , obj .GetName (), "namespace" , obj .GetNamespace ())
113113 return []reconcile.Request {}
114114 }
115115
@@ -160,7 +160,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
160160// Reconcile function to compare the state specified by the IstioCSR object against the actual cluster state,
161161// and to make the cluster state reflect the state specified by the user.
162162func (r * Reconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
163- r . log . V (1 ).Info ("reconciling" , "request" , req )
163+ klog . V (1 ).InfoS ("reconciling" , "request" , req )
164164
165165 // Fetch the istiocsr.openshift.operator.io CR
166166 istiocsr := & v1alpha1.IstioCSR {}
@@ -169,14 +169,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
169169 // NotFound errors, since they can't be fixed by an immediate
170170 // requeue (have to wait for a new notification), and can be processed
171171 // on deleted requests.
172- r . log . V (1 ).Info ("istiocsr.openshift.operator.io object not found, skipping reconciliation" , "request" , req )
172+ klog . V (1 ).InfoS ("istiocsr.openshift.operator.io object not found, skipping reconciliation" , "request" , req )
173173 return ctrl.Result {}, nil
174174 }
175175 return ctrl.Result {}, fmt .Errorf ("failed to fetch istiocsr.openshift.operator.io %q during reconciliation: %w" , req .NamespacedName , err )
176176 }
177177
178178 if ! istiocsr .DeletionTimestamp .IsZero () {
179- r . log . V (1 ).Info ("istiocsr.openshift.operator.io is marked for deletion" , "namespace" , req .NamespacedName )
179+ klog . V (1 ).InfoS ("istiocsr.openshift.operator.io is marked for deletion" , "namespace" , req .NamespacedName )
180180
181181 if requeue , err := r .cleanUp (istiocsr ); err != nil {
182182 return ctrl.Result {}, fmt .Errorf ("clean up failed for %q istiocsr.openshift.operator.io instance deletion: %w" , req .NamespacedName , err )
@@ -188,7 +188,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
188188 return ctrl.Result {}, err
189189 }
190190
191- r . log . V (1 ).Info ("removed finalizer, cleanup complete" , "request" , req .NamespacedName )
191+ klog . V (1 ).InfoS ("removed finalizer, cleanup complete" , "request" , req .NamespacedName )
192192 return ctrl.Result {}, nil
193193 }
194194
@@ -203,7 +203,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
203203func (r * Reconciler ) processReconcileRequest (istiocsr * v1alpha1.IstioCSR , req types.NamespacedName ) (ctrl.Result , error ) {
204204 istioCSRCreateRecon := false
205205 if ! containsProcessedAnnotation (istiocsr ) && reflect .DeepEqual (istiocsr .Status , v1alpha1.IstioCSRStatus {}) {
206- r . log . V (1 ).Info ("starting reconciliation of newly created istiocsr" , "namespace" , istiocsr .GetNamespace (), "name" , istiocsr .GetName ())
206+ klog . V (1 ).InfoS ("starting reconciliation of newly created istiocsr" , "namespace" , istiocsr .GetNamespace (), "name" , istiocsr .GetName ())
207207 istioCSRCreateRecon = true
208208 }
209209
@@ -217,13 +217,13 @@ func (r *Reconciler) processReconcileRequest(istiocsr *v1alpha1.IstioCSR, req ty
217217
218218 reconcileErr := r .reconcileIstioCSRDeployment (istiocsr , istioCSRCreateRecon )
219219 if reconcileErr != nil {
220- r . log . Error (reconcileErr , "failed to reconcile IstioCSR deployment" , "request" , req )
220+ klog . ErrorS (reconcileErr , "failed to reconcile IstioCSR deployment" , "request" , req )
221221 }
222222
223223 return common .HandleReconcileResult (
224224 & istiocsr .Status .ConditionalStatus ,
225225 reconcileErr ,
226- r . log .WithValues ("namespace" , istiocsr .GetNamespace (), "name" , istiocsr .GetName ()),
226+ klog . NewKlogr () .WithValues ("namespace" , istiocsr .GetNamespace (), "name" , istiocsr .GetName ()),
227227 func (prependErr error ) error {
228228 return r .updateCondition (istiocsr , prependErr )
229229 },
0 commit comments