Skip to content

Commit 16f4328

Browse files
authored
fix: incorrect parameters in log message (#2613)
1 parent 50dda24 commit 16f4328

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

internal/controller/apisixconsumer_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ func (r *ApisixConsumerReconciler) processSpec(ctx context.Context, tctx *provid
209209
secret := &corev1.Secret{}
210210
if err := r.Get(ctx, namespacedName, secret); err != nil {
211211
if k8serrors.IsNotFound(err) {
212-
r.Log.Info("secret not found", "secret", namespacedName.String())
212+
r.Log.Info("secret not found", "secret", namespacedName)
213213
return nil
214214
} else {
215-
r.Log.Error(err, "failed to get secret", "secret", namespacedName.String())
215+
r.Log.Error(err, "failed to get secret", "secret", namespacedName)
216216
return err
217217
}
218218
}

internal/controller/apisixroute_controller.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
corev1 "k8s.io/api/core/v1"
2929
discoveryv1 "k8s.io/api/discovery/v1"
3030
networkingv1 "k8s.io/api/networking/v1"
31+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
3132
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3233
"k8s.io/apimachinery/pkg/runtime"
3334
k8stypes "k8s.io/apimachinery/pkg/types"
@@ -399,10 +400,11 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
399400
)
400401

401402
if err := r.Get(tctx, serviceNN, &service); err != nil {
402-
if err = client.IgnoreNotFound(err); err == nil {
403-
r.Log.Error(errors.New("service not found"), "Service", serviceNN)
403+
if k8serrors.IsNotFound(err) {
404+
r.Log.Info("service not found", "Service", serviceNN)
404405
return nil
405406
}
407+
r.Log.Error(err, "failed to get service", "Service", serviceNN)
406408
return err
407409
}
408410

@@ -426,7 +428,11 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
426428
}
427429

428430
if backend.ResolveGranularity == apiv2.ResolveGranularityService && service.Spec.ClusterIP == "" {
429-
r.Log.Error(errors.New("service has no ClusterIP"), "Service", serviceNN, "ResolveGranularity", backend.ResolveGranularity)
431+
r.Log.Error(errors.New("service has no ClusterIP"),
432+
"service missing ClusterIP",
433+
"Service", serviceNN,
434+
"ResolveGranularity", backend.ResolveGranularity,
435+
)
430436
return nil
431437
}
432438

@@ -440,11 +446,11 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
440446
}
441447
return false
442448
}) {
443-
if backend.ServicePort.Type == intstr.Int {
444-
r.Log.Error(errors.New("port not found in service"), "Service", serviceNN, "port", backend.ServicePort.IntValue())
445-
} else {
446-
r.Log.Error(errors.New("named port not found in service"), "Service", serviceNN, "port", backend.ServicePort.StrVal)
447-
}
449+
r.Log.Error(errors.New("service port not found"),
450+
"failed to match service port",
451+
"Service", serviceNN,
452+
"ServicePort", backend.ServicePort,
453+
)
448454
return nil
449455
}
450456
tctx.Services[serviceNN] = &service

internal/controller/httproute_controller.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
408408

409409
var httpRoute gatewayv1.HTTPRoute
410410
if err := r.Get(ctx, key, &httpRoute); err != nil {
411-
r.Log.Error(err, "failed to get HTTPRoute by HTTPRoutePolicy targetRef", "namespace", key.Namespace, "name", key.Name)
411+
r.Log.Error(errors.New("httproute not found"),
412+
"failed to get HTTPRoute rule for HTTPRoutePolicy targetRef",
413+
"httproute", key,
414+
)
412415
continue
413416
}
414417
if ref.SectionName != nil {
@@ -420,7 +423,11 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
420423
}
421424
}
422425
if !matchRuleName {
423-
r.Log.Error(errors.Errorf("failed to get HTTPRoute rule by HTTPRoutePolicy targetRef"), "namespace", key.Namespace, "name", key.Name, "sectionName", *ref.SectionName)
426+
r.Log.Error(errors.New("httproute section name not found"),
427+
"failed to get HTTPRoute rule by HTTPRoutePolicy targetRef",
428+
"httproute", key,
429+
"sectionName", *ref.SectionName,
430+
)
424431
continue
425432
}
426433
}

0 commit comments

Comments
 (0)