Skip to content

Commit c057229

Browse files
committed
fix: r
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 2f0b86b commit c057229

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

internal/controller/gatewayproxy_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,16 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
136136
if providerService == nil {
137137
tctx.EndpointSlices[req.NamespacedName] = nil
138138
} else {
139-
if err := addProviderEndpointsToTranslateContext(tctx, r.Client, r.Log, k8stypes.NamespacedName{
139+
serviceNN := k8stypes.NamespacedName{
140140
Namespace: gp.Namespace,
141141
Name: providerService.Name,
142-
}); err != nil {
142+
}
143+
service := &corev1.Service{}
144+
if err := r.Get(ctx, serviceNN, service); err != nil {
145+
return reconcile.Result{}, err
146+
}
147+
tctx.Services[serviceNN] = service
148+
if err := resolveServiceEndpoints(tctx, r.Client, serviceNN, r.supportsEndpointSlice, nil); err != nil {
143149
return reconcile.Result{}, err
144150
}
145151
}

internal/provider/api7ee/provider.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import (
2323
"sync/atomic"
2424
"time"
2525

26-
"github.com/api7/gopkg/pkg/log"
2726
"github.com/go-logr/logr"
28-
"go.uber.org/zap"
2927
networkingv1 "k8s.io/api/networking/v1"
3028
networkingv1beta1 "k8s.io/api/networking/v1beta1"
3129
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -63,6 +61,7 @@ type api7eeProvider struct {
6361
startUpSync atomic.Bool
6462

6563
client *adcclient.Client
64+
log logr.Logger
6665
}
6766

6867
func New(log logr.Logger, updater status.Updater, readier readiness.ReadinessManager, opts ...provider.Option) (provider.Provider, error) {
@@ -84,6 +83,7 @@ func New(log logr.Logger, updater status.Updater, readier readiness.ReadinessMan
8483
updater: updater,
8584
readier: readier,
8685
syncCh: make(chan struct{}, 1),
86+
log: log.WithName("provider"),
8787
}, nil
8888
}
8989

@@ -92,7 +92,7 @@ func (d *api7eeProvider) Register(pathPrefix string, mux *http.ServeMux) {
9292
}
9393

9494
func (d *api7eeProvider) Update(ctx context.Context, tctx *provider.TranslateContext, obj client.Object) error {
95-
log.Debugw("updating object", zap.Any("object", obj))
95+
d.log.V(1).Info("updating object", "object", obj)
9696
var (
9797
result *translator.TranslateResult
9898
resourceTypes []string
@@ -179,15 +179,15 @@ func (d *api7eeProvider) Update(ctx context.Context, tctx *provider.TranslateCon
179179
}
180180

181181
if !d.startUpSync.Load() {
182-
log.Debugw("startup synchronization not completed, skip sync", zap.Any("object", obj))
182+
d.log.V(1).Info("startup synchronization not completed, skip sync", "object", obj)
183183
return d.client.UpdateConfig(ctx, task)
184184
}
185185

186186
return d.client.Update(ctx, task)
187187
}
188188

189189
func (d *api7eeProvider) Delete(ctx context.Context, obj client.Object) error {
190-
log.Debugw("deleting object", zap.Any("object", obj))
190+
d.log.V(1).Info("deleting object", "object", obj)
191191

192192
var resourceTypes []string
193193
var labels map[string]string
@@ -229,16 +229,16 @@ func (d *api7eeProvider) Start(ctx context.Context) error {
229229
d.readier.WaitReady(ctx, 5*time.Minute)
230230

231231
d.startUpSync.Store(true)
232-
log.Info("Performing startup synchronization")
232+
d.log.Info("Performing startup synchronization")
233233
if err := d.sync(ctx); err != nil {
234-
log.Warnw("failed to sync for startup", zap.Error(err))
234+
d.log.Error(err, "failed to sync for startup")
235235
}
236236

237237
initalSyncDelay := d.InitSyncDelay
238238
if initalSyncDelay > 0 {
239239
time.AfterFunc(initalSyncDelay, func() {
240240
if err := d.sync(ctx); err != nil {
241-
log.Error(err)
241+
d.log.Error(err, "failed to sync for startup")
242242
return
243243
}
244244
})
@@ -261,7 +261,7 @@ func (d *api7eeProvider) Start(ctx context.Context) error {
261261
}
262262
if synced {
263263
if err := d.sync(ctx); err != nil {
264-
log.Error(err)
264+
d.log.Error(err, "failed to sync for startup")
265265
}
266266
}
267267
}
@@ -283,7 +283,7 @@ func (d *api7eeProvider) sync(ctx context.Context) error {
283283
func (d *api7eeProvider) handleADCExecutionErrors(statusesMap map[string]types.ADCExecutionErrors) {
284284
statusUpdateMap := d.resolveADCExecutionErrors(statusesMap)
285285
d.handleStatusUpdate(statusUpdateMap)
286-
log.Debugw("handled ADC execution errors", zap.Any("status_record", statusesMap), zap.Any("status_update", statusUpdateMap))
286+
d.log.V(1).Info("handled ADC execution errors", "status_record", statusesMap, "status_update", statusUpdateMap)
287287
}
288288

289289
func (d *api7eeProvider) NeedLeaderElection() bool {

internal/provider/api7ee/status.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"fmt"
2222
"strings"
2323

24-
"github.com/api7/gopkg/pkg/log"
25-
"go.uber.org/zap"
2624
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2725
"sigs.k8s.io/controller-runtime/pkg/client"
2826
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
@@ -147,7 +145,7 @@ func (d *api7eeProvider) updateStatus(nnk types.NamespacedNameKind, condition me
147145
})
148146
case types.KindUDPRoute:
149147
parentRefs := d.client.ConfigManager.GetConfigRefsByResourceKey(nnk)
150-
log.Debugw("updating UDPRoute status", zap.Any("parentRefs", parentRefs))
148+
d.log.V(1).Info("updating UDPRoute status", "parentRefs", parentRefs)
151149
gatewayRefs := map[types.NamespacedNameKind]struct{}{}
152150
for _, parentRef := range parentRefs {
153151
if parentRef.Kind == types.KindGateway {
@@ -182,7 +180,7 @@ func (d *api7eeProvider) updateStatus(nnk types.NamespacedNameKind, condition me
182180
})
183181
case types.KindTCPRoute:
184182
parentRefs := d.client.ConfigManager.GetConfigRefsByResourceKey(nnk)
185-
log.Debugw("updating TCPRoute status", zap.Any("parentRefs", parentRefs))
183+
d.log.V(1).Info("updating TCPRoute status", "parentRefs", parentRefs)
186184
gatewayRefs := map[types.NamespacedNameKind]struct{}{}
187185
for _, parentRef := range parentRefs {
188186
if parentRef.Kind == types.KindGateway {
@@ -217,7 +215,7 @@ func (d *api7eeProvider) updateStatus(nnk types.NamespacedNameKind, condition me
217215
})
218216
case types.KindGRPCRoute:
219217
parentRefs := d.client.ConfigManager.GetConfigRefsByResourceKey(nnk)
220-
log.Debugw("updating GRPCRoute status", zap.Any("parentRefs", parentRefs))
218+
d.log.V(1).Info("updating GRPCRoute status", "parentRefs", parentRefs)
221219
gatewayRefs := map[types.NamespacedNameKind]struct{}{}
222220
for _, parentRef := range parentRefs {
223221
if parentRef.Kind == types.KindGateway {
@@ -279,7 +277,7 @@ func (d *api7eeProvider) handleEmptyFailedStatuses(
279277
) {
280278
resource, err := d.client.GetResources(configName)
281279
if err != nil {
282-
log.Errorw("failed to get resources from store", zap.String("configName", configName), zap.Error(err))
280+
d.log.Error(err, "failed to get resources from store", "configName", configName)
283281
return
284282
}
285283

@@ -297,7 +295,7 @@ func (d *api7eeProvider) handleEmptyFailedStatuses(
297295

298296
globalRules, err := d.client.ListGlobalRules(configName)
299297
if err != nil {
300-
log.Errorw("failed to list global rules", zap.String("configName", configName), zap.Error(err))
298+
d.log.Error(err, "failed to list global rules", "configName", configName)
301299
return
302300
}
303301
for _, rule := range globalRules {
@@ -314,11 +312,10 @@ func (d *api7eeProvider) handleDetailedFailedStatuses(
314312
id := status.Event.ResourceID
315313
labels, err := d.client.GetResourceLabel(configName, status.Event.ResourceType, id)
316314
if err != nil {
317-
log.Errorw("failed to get resource label",
318-
zap.String("configName", configName),
319-
zap.String("resourceType", status.Event.ResourceType),
320-
zap.String("id", id),
321-
zap.Error(err),
315+
d.log.Error(err, "failed to get resource label",
316+
"configName", configName,
317+
"resourceType", status.Event.ResourceType,
318+
"id", id,
322319
)
323320
continue
324321
}

pkg/utils/endpoints.go

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

24-
"github.com/api7/gopkg/pkg/log"
25-
"go.uber.org/zap"
2624
corev1 "k8s.io/api/core/v1"
2725
discoveryv1 "k8s.io/api/discovery/v1"
2826
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2927
"k8s.io/utils/ptr"
28+
logf "sigs.k8s.io/controller-runtime/pkg/log"
3029
)
3130

31+
var log = logf.Log.WithName("endpoints")
32+
3233
// ConvertEndpointsToEndpointSlice converts a Kubernetes Endpoints object to one
3334
// or more EndpointSlice objects, supporting IPv4/IPv6 dual stack.
3435
// This function is used to provide backward compatibility for Kubernetes 1.18 clusters that don't
@@ -140,7 +141,7 @@ func ConvertEndpointsToEndpointSlice(ep *corev1.Endpoints) []discoveryv1.Endpoin
140141
}
141142
}
142143

143-
log.Debugw("Converted Endpoints to EndpointSlices", zap.Any("endpointSlices", endpointSlices))
144+
log.V(1).Info("Converted Endpoints to EndpointSlices", "endpointSlices", endpointSlices)
144145

145146
return endpointSlices
146147
}

0 commit comments

Comments
 (0)