Skip to content

Commit 466faec

Browse files
improved error logging and context handling issue
Signed-off-by: James Milligan <[email protected]>
1 parent 5ef6813 commit 466faec

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

webhooks/pod_webhook.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func (m *PodMutator) BackfillPermissions(ctx context.Context) {
5656
for i := 0; i < 5; i++ {
5757
// fetch all pods with the "openfeature.dev/enabled" annotation set to "true"
5858
podList := &corev1.PodList{}
59-
err := m.Client.List(context.Background(), podList, client.MatchingFields{"metadata.annotations.openfeature.dev/enabled": "true"})
59+
err := m.Client.List(ctx, podList, client.MatchingFields{"metadata.annotations.openfeature.dev/enabled": "true"})
6060
if err != nil {
6161
if !goErr.Is(err, &cache.ErrCacheNotStarted{}) {
62-
m.Log.Error(err, err.Error())
62+
m.Log.Error(err, "unable to list annotated pods", "webhook", "metadata.annotations.openfeature.dev/enabled")
6363
return
6464
}
6565
time.Sleep(1 * time.Second)
@@ -70,13 +70,22 @@ func (m *PodMutator) BackfillPermissions(ctx context.Context) {
7070
for _, pod := range podList.Items {
7171
m.Log.V(1).Info(fmt.Sprintf("backfilling permissions for pod %s/%s", pod.Namespace, pod.Name))
7272
if err := m.enableClusterRoleBinding(ctx, &pod); err != nil {
73-
m.Log.Error(err, err.Error())
73+
m.Log.Error(
74+
err,
75+
fmt.Sprintf("unable backfill permissions for pod %s/%s", pod.Namespace, pod.Name),
76+
"webhook",
77+
"metadata.annotations.openfeature.dev/enabled",
78+
)
7479
}
7580
}
7681
return
7782
}
7883
err := goErr.New("unable to backfill permissions for the flagd-kubernetes-sync role binding: timeout")
79-
m.Log.Error(err, err.Error())
84+
m.Log.Error(
85+
err,
86+
"webhook",
87+
"metadata.annotations.openfeature.dev/enabled",
88+
)
8089
}
8190

8291
// Handle injects the flagd sidecar (if the prerequisites are all met)

0 commit comments

Comments
 (0)