Skip to content

Commit 548e682

Browse files
chore: optimize the conflict log and webhook retry with error log detail (#29)
* feat: add session affinity for service * chore: update conflict with retry and webhook retry with error log detail * chore: webhook retry with error log detail * chore: optimize the conflict log and webhook retry with error log detail --------- Co-authored-by: hardy <[email protected]>
1 parent f1fdbe0 commit 548e682

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

internal/controller/common/kubeutil/apply.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"fmt"
3131

3232
"github.com/cisco-open/operator-tools/pkg/reconciler"
33+
apierrors "k8s.io/apimachinery/pkg/api/errors"
3334
"sigs.k8s.io/controller-runtime/pkg/client"
3435
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" // For OperationResult
3536
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -155,7 +156,11 @@ func ApplyObjectV2(ctx context.Context, k8sClient reconciler.ResourceReconciler,
155156
_, err := k8sClient.ReconcileResource(obj, reconciler.StatePresent)
156157
if err != nil {
157158
// Log the error if the apply operation fails.
158-
logger.Error(err, "Failed to apply object using Server-Side Apply")
159+
if apierrors.IsConflict(err) {
160+
logger.V(1).Info("Optimistic lock conflict detected when applying resource", "kind", gvk.Kind, "name", objKey.Name, "namespace", objKey.Namespace)
161+
} else {
162+
logger.Error(err, "Failed to apply object using Server-Side Apply", "kind", gvk.Kind, "name", objKey.Name, "namespace", objKey.Namespace)
163+
}
159164
return ApplyResult{Error: err}
160165
}
161166

pkg/webrecorder/recorder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ func (r *WebhookEventRecorder) sendEvent(data *WebhookEvent) {
229229
resp, err := r.httpClient.Do(req)
230230
if err != nil {
231231
r.logger.Error(err, "Failed to send webhook event", "url", r.webhookURL)
232-
// 快速失败:如果是连接拒绝或EOF,不再重试
233232
if isNetworkError(err) {
234233
r.logger.Info("Network error detected, skipping remaining retries", "error", err.Error())
235234
return
@@ -244,7 +243,7 @@ func (r *WebhookEventRecorder) sendEvent(data *WebhookEvent) {
244243

245244
// On successful send, check the status code.
246245
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
247-
r.logger.V(1).Info("Successfully sent event to webhook", "url", r.webhookURL, "status", resp.Status)
246+
r.logger.Info("Successfully sent event to webhook", "url", r.webhookURL, "status", resp.Status)
248247
return // Success, exit the function.
249248
}
250249

0 commit comments

Comments
 (0)