Skip to content

Commit 487b903

Browse files
committed
chore: unified logger print
Signed-off-by: ashing <[email protected]>
1 parent d9ae07a commit 487b903

File tree

11 files changed

+27
-27
lines changed

11 files changed

+27
-27
lines changed

internal/controller/apisixglobalrule_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"fmt"
2323

24-
"github.com/api7/gopkg/pkg/log"
2524
"github.com/go-logr/logr"
2625
networkingv1 "k8s.io/api/networking/v1"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -83,19 +82,19 @@ func (r *ApisixGlobalRuleReconciler) Reconcile(ctx context.Context, req ctrl.Req
8382
// get the ingress class
8483
ingressClass, err := GetIngressClass(tctx, r.Client, r.Log, globalRule.Spec.IngressClassName)
8584
if err != nil {
86-
log.Error(err, "failed to get IngressClass")
85+
r.Log.Error(err, "failed to get IngressClass")
8786
return ctrl.Result{}, err
8887
}
8988

9089
// process IngressClass parameters if they reference GatewayProxy
9190
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, &globalRule, ingressClass); err != nil {
92-
log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
91+
r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
9392
return ctrl.Result{}, err
9493
}
9594

9695
// Sync the global rule to APISIX
9796
if err := r.Provider.Update(ctx, tctx, &globalRule); err != nil {
98-
log.Error(err, "failed to sync global rule to provider")
97+
r.Log.Error(err, "failed to sync global rule to provider")
9998
// Update status with failure condition
10099
r.updateStatus(&globalRule, metav1.Condition{
101100
Type: string(apiv2.ConditionTypeAccepted),

internal/controller/apisixtls_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"fmt"
2323

24-
"github.com/api7/gopkg/pkg/log"
2524
"github.com/go-logr/logr"
2625
corev1 "k8s.io/api/core/v1"
2726
networkingv1 "k8s.io/api/networking/v1"
@@ -115,7 +114,7 @@ func (r *ApisixTlsReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
115114
// get the ingress class
116115
ingressClass, err := GetIngressClass(tctx, r.Client, r.Log, tls.Spec.IngressClassName)
117116
if err != nil {
118-
log.Error(err, "failed to get IngressClass")
117+
r.Log.Error(err, "failed to get IngressClass")
119118
r.updateStatus(&tls, metav1.Condition{
120119
Type: string(apiv2.ConditionTypeAccepted),
121120
Status: metav1.ConditionFalse,
@@ -129,7 +128,7 @@ func (r *ApisixTlsReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
129128

130129
// process IngressClass parameters if they reference GatewayProxy
131130
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, &tls, ingressClass); err != nil {
132-
log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
131+
r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
133132
r.updateStatus(&tls, metav1.Condition{
134133
Type: string(apiv2.ConditionTypeAccepted),
135134
Status: metav1.ConditionFalse,
@@ -143,7 +142,7 @@ func (r *ApisixTlsReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
143142

144143
// process ApisixTls validation
145144
if err := r.processApisixTls(ctx, tctx, &tls); err != nil {
146-
log.Error(err, "failed to process ApisixTls")
145+
r.Log.Error(err, "failed to process ApisixTls")
147146
r.updateStatus(&tls, metav1.Condition{
148147
Type: string(apiv2.ConditionTypeAccepted),
149148
Status: metav1.ConditionFalse,
@@ -156,7 +155,7 @@ func (r *ApisixTlsReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
156155
}
157156

158157
if err := r.Provider.Update(ctx, tctx, &tls); err != nil {
159-
log.Error(err, "failed to sync apisix tls to provider")
158+
r.Log.Error(err, "failed to sync apisix tls to provider")
160159
// Update status with failure condition
161160
r.updateStatus(&tls, metav1.Condition{
162161
Type: string(apiv2.ConditionTypeAccepted),

internal/controller/gateway_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"fmt"
2424
"reflect"
2525

26-
"github.com/api7/gopkg/pkg/log"
2726
"github.com/go-logr/logr"
2827
corev1 "k8s.io/api/core/v1"
2928
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -432,12 +431,12 @@ func (r *GatewayReconciler) processListenerConfig(tctx *provider.TranslateContex
432431
Namespace: ns,
433432
Name: string(ref.Name),
434433
}, &secret); err != nil {
435-
log.Error(err, "failed to get secret", "namespace", ns, "name", ref.Name)
434+
r.Log.Error(err, "failed to get secret", "namespace", ns, "name", ref.Name)
436435
SetGatewayListenerConditionProgrammed(gateway, string(listener.Name), false, err.Error())
437436
SetGatewayListenerConditionResolvedRefs(gateway, string(listener.Name), false, err.Error())
438437
break
439438
}
440-
log.Info("Setting secret for listener", "listener", listener.Name, "secret", secret.Name, " namespace", ns)
439+
r.Log.Info("Setting secret for listener", "listener", listener.Name, "secret", secret.Name, " namespace", ns)
441440
tctx.Secrets[types.NamespacedName{Namespace: ns, Name: string(ref.Name)}] = &secret
442441
}
443442
}

internal/controller/ingress_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ func (r *IngressReconciler) processTLS(tctx *provider.TranslateContext, ingress
471471
Namespace: ingress.Namespace,
472472
Name: tls.SecretName,
473473
}, &secret); err != nil {
474-
log.Error(err, "failed to get secret", "namespace", ingress.Namespace, "name", tls.SecretName)
474+
r.Log.Error(err, "failed to get secret", "namespace", ingress.Namespace, "name", tls.SecretName)
475475
return err
476476
}
477477

internal/controller/ingressclass_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"fmt"
2323

24-
"github.com/api7/gopkg/pkg/log"
2524
"github.com/go-logr/logr"
2625
corev1 "k8s.io/api/core/v1"
2726
networkingv1 "k8s.io/api/networking/v1"
@@ -217,7 +216,7 @@ func (r *IngressClassReconciler) processInfrastructure(tctx *provider.TranslateC
217216
Namespace: namespace,
218217
Name: secretRef.Name,
219218
}, secret); err != nil {
220-
log.Error(err, "failed to get secret for gateway proxy", "namespace", namespace, "name", secretRef.Name)
219+
r.Log.Error(err, "failed to get secret for gateway proxy", "namespace", namespace, "name", secretRef.Name)
221220
return err
222221
}
223222
tctx.Secrets[client.ObjectKey{

internal/controller/utils.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,11 @@ func ParseRouteParentRefs(
380380
listenerName = string(listener.Name)
381381
ok, err := routeMatchesListenerAllowedRoutes(ctx, mgrc, route, listener.AllowedRoutes, gateway.Namespace, parentRef.Namespace)
382382
if err != nil {
383-
log.Warnf("failed matching listener %s to a route %s for gateway %s: %v",
384-
listener.Name, route.GetName(), gateway.Name, err,
383+
log.Warnw("failed matching listener to a route for gateway",
384+
zap.String("listener", string(listener.Name)),
385+
zap.String("route", route.GetName()),
386+
zap.String("gateway", gateway.Name),
387+
zap.Error(err),
385388
)
386389
}
387390
if !ok {
@@ -941,10 +944,10 @@ func ProcessGatewayProxy(r client.Client, tctx *provider.TranslateContext, gatew
941944
return err
942945
}
943946

944-
log.Info("found secret for GatewayProxy provider",
945-
"gateway", gateway.Name,
946-
"gatewayproxy", gatewayProxy.Name,
947-
"secret", secretRef.Name)
947+
log.Infow("found secret for GatewayProxy provider",
948+
zap.String("gateway", gateway.Name),
949+
zap.String("gatewayproxy", gatewayProxy.Name),
950+
zap.String("secret", secretRef.Name))
948951

949952
tctx.Secrets[k8stypes.NamespacedName{
950953
Namespace: ns,
@@ -1445,7 +1448,7 @@ func distinctRequests(requests []reconcile.Request) []reconcile.Request {
14451448
}
14461449

14471450
func addProviderEndpointsToTranslateContext(tctx *provider.TranslateContext, c client.Client, serviceNN k8stypes.NamespacedName) error {
1448-
log.Debugf("to process provider endpints by provider.service: %s", serviceNN)
1451+
log.Debugw("to process provider endpints by provider.service", zap.Any("service", serviceNN))
14491452
var (
14501453
service corev1.Service
14511454
)

internal/provider/adc/adc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func prepareSyncFile(resources any) (string, func(), error) {
395395
return "", nil, err
396396
}
397397

398-
log.Debugf("generated adc file, filename: %s, json: %s\n", tmpFile.Name(), string(data))
398+
log.Debugw("generated adc file", zap.String("filename", tmpFile.Name()), zap.String("json", string(data)))
399399

400400
return tmpFile.Name(), cleanup, nil
401401
}

internal/provider/adc/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (d *adcClient) getConfigsForGatewayProxy(tctx *provider.TranslateContext, g
116116
config.ServerAddrs = append(config.ServerAddrs, "http://"+net.JoinHostPort(node.Host, strconv.Itoa(node.Port)))
117117
}
118118

119-
log.Debugf("add server address to config.ServiceAddrs: %v", config.ServerAddrs)
119+
log.Debugw("add server address to config.ServiceAddrs", zap.Any("serverAddrs", config.ServerAddrs))
120120
}
121121

122122
return &config, nil

internal/provider/adc/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (e *DefaultADCExecutor) buildCmdError(runErr error, stdout, stderr []byte)
123123

124124
func (e *DefaultADCExecutor) handleOutput(output []byte) error {
125125
var result adctypes.SyncResult
126-
log.Debugf("adc output: %s", string(output))
126+
log.Debugw("adc output", zap.String("output", string(output)))
127127
if lines := bytes.Split(output, []byte{'\n'}); len(lines) > 0 {
128128
output = lines[len(lines)-1]
129129
}

internal/provider/adc/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *Store) Insert(name string, resourceTypes []string, resources adctypes.R
5555
s.cacheMap[name] = db
5656
targetCache = s.cacheMap[name]
5757
}
58-
log.Debugf("Inserting resources into cache for %s", name)
58+
log.Debugw("Inserting resources into cache for", zap.String("name", name))
5959
selector := &cache.KindLabelSelector{
6060
Kind: Labels[label.LabelKind],
6161
Name: Labels[label.LabelName],

0 commit comments

Comments
 (0)