Skip to content

Commit d1e1972

Browse files
AlinsRanronething
authored andcommitted
fix: incorrect parameters in log message (#2613)
Signed-off-by: Ashing Zheng <[email protected]>
1 parent b044a31 commit d1e1972

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
@@ -226,10 +226,10 @@ func (r *ApisixConsumerReconciler) processSpec(ctx context.Context, tctx *provid
226226
secret := &corev1.Secret{}
227227
if err := r.Get(ctx, namespacedName, secret); err != nil {
228228
if k8serrors.IsNotFound(err) {
229-
r.Log.Info("secret not found", "secret", namespacedName.String())
229+
r.Log.Info("secret not found", "secret", namespacedName)
230230
return nil
231231
} else {
232-
r.Log.Error(err, "failed to get secret", "secret", namespacedName.String())
232+
r.Log.Error(err, "failed to get secret", "secret", namespacedName)
233233
return err
234234
}
235235
}

internal/controller/apisixroute_controller.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
discoveryv1 "k8s.io/api/discovery/v1"
3030
networkingv1 "k8s.io/api/networking/v1"
3131
networkingv1beta1 "k8s.io/api/networking/v1beta1"
32+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
3233
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3334
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3435
"k8s.io/apimachinery/pkg/runtime"
@@ -431,10 +432,11 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
431432
)
432433

433434
if err := r.Get(tctx, serviceNN, &service); err != nil {
434-
if err = client.IgnoreNotFound(err); err == nil {
435-
r.Log.Error(errors.New("service not found"), "Service", serviceNN)
435+
if k8serrors.IsNotFound(err) {
436+
r.Log.Info("service not found", "Service", serviceNN)
436437
return nil
437438
}
439+
r.Log.Error(err, "failed to get service", "Service", serviceNN)
438440
return err
439441
}
440442

@@ -458,7 +460,11 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
458460
}
459461

460462
if backend.ResolveGranularity == apiv2.ResolveGranularityService && service.Spec.ClusterIP == "" {
461-
r.Log.Error(errors.New("service has no ClusterIP"), "Service", serviceNN, "ResolveGranularity", backend.ResolveGranularity)
463+
r.Log.Error(errors.New("service has no ClusterIP"),
464+
"service missing ClusterIP",
465+
"Service", serviceNN,
466+
"ResolveGranularity", backend.ResolveGranularity,
467+
)
462468
return nil
463469
}
464470

@@ -472,11 +478,11 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
472478
}
473479
return false
474480
}) {
475-
if backend.ServicePort.Type == intstr.Int {
476-
r.Log.Error(errors.New("port not found in service"), "Service", serviceNN, "port", backend.ServicePort.IntValue())
477-
} else {
478-
r.Log.Error(errors.New("named port not found in service"), "Service", serviceNN, "port", backend.ServicePort.StrVal)
479-
}
481+
r.Log.Error(errors.New("service port not found"),
482+
"failed to match service port",
483+
"Service", serviceNN,
484+
"ServicePort", backend.ServicePort,
485+
)
480486
return nil
481487
}
482488
tctx.Services[serviceNN] = &service

internal/controller/httproute_controller.go

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

459459
var httpRoute gatewayv1.HTTPRoute
460460
if err := r.Get(ctx, key, &httpRoute); err != nil {
461-
r.Log.Error(err, "failed to get HTTPRoute by HTTPRoutePolicy targetRef", "namespace", key.Namespace, "name", key.Name)
461+
r.Log.Error(errors.New("httproute not found"),
462+
"failed to get HTTPRoute rule for HTTPRoutePolicy targetRef",
463+
"httproute", key,
464+
)
462465
continue
463466
}
464467
if ref.SectionName != nil {
@@ -470,7 +473,11 @@ func (r *HTTPRouteReconciler) listHTTPRouteByHTTPRoutePolicy(ctx context.Context
470473
}
471474
}
472475
if !matchRuleName {
473-
r.Log.Error(errors.Errorf("failed to get HTTPRoute rule by HTTPRoutePolicy targetRef"), "namespace", key.Namespace, "name", key.Name, "sectionName", *ref.SectionName)
476+
r.Log.Error(errors.New("httproute section name not found"),
477+
"failed to get HTTPRoute rule by HTTPRoutePolicy targetRef",
478+
"httproute", key,
479+
"sectionName", *ref.SectionName,
480+
)
474481
continue
475482
}
476483
}

0 commit comments

Comments
 (0)