Skip to content

Commit 01fac95

Browse files
committed
improve logging
1 parent 37eb983 commit 01fac95

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pkg/targetgroupbinding/resource_manager.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (m *defaultResourceManager) Cleanup(ctx context.Context, tgb *elbv2api.Targ
122122
}
123123

124124
func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context, tgb *elbv2api.TargetGroupBinding) (string, string, bool, error) {
125+
tgbScopedLogger := m.logger.WithValues("tgb", k8s.NamespacedName(tgb))
125126
svcKey := buildServiceReferenceKey(tgb, tgb.Spec.ServiceRef)
126127

127128
targetHealthCondType := BuildTargetHealthPodConditionType(tgb)
@@ -152,7 +153,7 @@ func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context,
152153
oldCheckPoint := GetTGBReconcileCheckpoint(tgb)
153154

154155
if !containsPotentialReadyEndpoints && oldCheckPoint == newCheckPoint {
155-
m.logger.Info("Skipping targetgroupbinding reconcile", "TGB", k8s.NamespacedName(tgb), "calculated hash", newCheckPoint)
156+
tgbScopedLogger.Info("Skipping targetgroupbinding reconcile", "calculated hash", newCheckPoint)
156157
return newCheckPoint, oldCheckPoint, true, nil
157158
}
158159

@@ -167,7 +168,7 @@ func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context,
167168

168169
needNetworkingRequeue := false
169170
if err := m.networkingManager.ReconcileForPodEndpoints(ctx, tgb, endpoints); err != nil {
170-
m.logger.Error(err, "Requesting network requeue due to error from ReconcileForPodEndpoints")
171+
tgbScopedLogger.Error(err, "Requesting network requeue due to error from ReconcileForPodEndpoints")
171172
m.eventRecorder.Event(tgb, corev1.EventTypeWarning, k8s.TargetGroupBindingEventReasonFailedNetworkReconcile, err.Error())
172173
needNetworkingRequeue = true
173174
}
@@ -180,7 +181,7 @@ func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context,
180181
// 3. The next reconcile loop has no knowledge that it needs to deregister the pod ip, therefore it skips deregistering the removed pod ip.
181182
err = m.updateTGBCheckPoint(ctx, tgb, "", oldCheckPoint)
182183
if err != nil {
183-
m.logger.Error(err, "Unable to update checkpoint before mutating change")
184+
tgbScopedLogger.Error(err, "Unable to update checkpoint before mutating change")
184185
return "", "", false, err
185186
}
186187
}
@@ -202,25 +203,26 @@ func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context,
202203
}
203204

204205
if anyPodNeedFurtherProbe {
205-
m.logger.Info("Requeue for target monitor target health")
206+
tgbScopedLogger.Info("Requeue for target monitor target health")
206207
return "", "", false, runtime.NewRequeueNeededAfter("monitor targetHealth", m.requeueDuration)
207208
}
208209

209210
if containsPotentialReadyEndpoints {
210-
m.logger.Info("Requeue for potentially ready endpoints")
211+
tgbScopedLogger.Info("Requeue for potentially ready endpoints")
211212
return "", "", false, runtime.NewRequeueNeededAfter("monitor potential ready endpoints", m.requeueDuration)
212213
}
213214

214215
if needNetworkingRequeue {
215-
m.logger.Info("Requeue for networking requeue")
216+
tgbScopedLogger.Info("Requeue for networking requeue")
216217
return "", "", false, runtime.NewRequeueNeededAfter("networking reconciliation", m.requeueDuration)
217218
}
218219

219-
m.logger.Info("Successful reconcile", "checkpoint", newCheckPoint, "TGB", k8s.NamespacedName(tgb))
220+
tgbScopedLogger.Info("Successful reconcile", "checkpoint", newCheckPoint)
220221
return newCheckPoint, oldCheckPoint, false, nil
221222
}
222223

223224
func (m *defaultResourceManager) reconcileWithInstanceTargetType(ctx context.Context, tgb *elbv2api.TargetGroupBinding) (string, string, bool, error) {
225+
tgbScopedLogger := m.logger.WithValues("tgb", k8s.NamespacedName(tgb))
224226
svcKey := buildServiceReferenceKey(tgb, tgb.Spec.ServiceRef)
225227
nodeSelector, err := backend.GetTrafficProxyNodeSelector(tgb)
226228
if err != nil {
@@ -246,7 +248,7 @@ func (m *defaultResourceManager) reconcileWithInstanceTargetType(ctx context.Con
246248
oldCheckPoint := GetTGBReconcileCheckpoint(tgb)
247249

248250
if newCheckPoint == oldCheckPoint {
249-
m.logger.Info("Skipping targetgroupbinding reconcile", "TGB", k8s.NamespacedName(tgb), "calculated hash", newCheckPoint)
251+
tgbScopedLogger.Info("Skipping targetgroupbinding reconcile", "calculated hash", newCheckPoint)
250252
return newCheckPoint, oldCheckPoint, true, nil
251253
}
252254

@@ -259,15 +261,15 @@ func (m *defaultResourceManager) reconcileWithInstanceTargetType(ctx context.Con
259261
_, unmatchedEndpoints, unmatchedTargets := matchNodePortEndpointWithTargets(endpoints, notDrainingTargets)
260262

261263
if err := m.networkingManager.ReconcileForNodePortEndpoints(ctx, tgb, endpoints); err != nil {
262-
m.logger.Error(err, "Requesting network requeue due to error from ReconcileForNodePortEndpoints")
264+
tgbScopedLogger.Error(err, "Requesting network requeue due to error from ReconcileForNodePortEndpoints")
263265
return "", "", false, err
264266
}
265267

266268
if len(unmatchedEndpoints) > 0 || len(unmatchedTargets) > 0 {
267269
// Same thought process, see the IP target registration code as to why we clear out the check point.
268270
err = m.updateTGBCheckPoint(ctx, tgb, "", oldCheckPoint)
269271
if err != nil {
270-
m.logger.Error(err, "Unable to update checkpoint before mutating change")
272+
tgbScopedLogger.Error(err, "Unable to update checkpoint before mutating change")
271273
return "", "", false, err
272274
}
273275
}
@@ -282,7 +284,7 @@ func (m *defaultResourceManager) reconcileWithInstanceTargetType(ctx context.Con
282284
return "", "", false, err
283285
}
284286
}
285-
m.logger.Info("Successful reconcile", "checkpoint", newCheckPoint)
287+
tgbScopedLogger.Info("Successful reconcile", "checkpoint", newCheckPoint)
286288
return newCheckPoint, oldCheckPoint, false, nil
287289
}
288290

0 commit comments

Comments
 (0)