Skip to content

Commit f41f891

Browse files
committed
Stash
1 parent a239242 commit f41f891

File tree

8 files changed

+120
-15
lines changed

8 files changed

+120
-15
lines changed

ako-gateway-api/k8s/ako_init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"k8s.io/client-go/tools/cache"
3434
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3535

36+
"github.com/google/uuid"
3637
akogatewayapilib "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/ako-gateway-api/lib"
3738
akogatewayapinodes "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/ako-gateway-api/nodes"
3839
akogatewayapistatus "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/ako-gateway-api/status"
@@ -244,7 +245,8 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
244245

245246
var filteredGatewayClasses []*gatewayv1.GatewayClass
246247
for _, gwClassObj := range gwClassObjs {
247-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClassObj)
248+
UUID := uuid.New()
249+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClassObj) + "-" + UUID.String()
248250
meta, err := meta.Accessor(gwClassObj)
249251
if err == nil {
250252
resVer := meta.GetResourceVersion()

ako-gateway-api/k8s/gateway_controller.go

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
package k8s
1616

1717
import (
18+
"context"
1819
"fmt"
1920
"reflect"
2021
"sort"
2122
"sync"
2223
"time"
2324

25+
"github.com/google/uuid"
2426
corev1 "k8s.io/api/core/v1"
2527
discovery "k8s.io/api/discovery/v1"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -50,6 +52,19 @@ type GatewayController struct {
5052
DisableSync bool
5153
}
5254

55+
type keyData struct {
56+
key string
57+
ctx context.Context
58+
}
59+
60+
func InitKeyData(key string) keyData {
61+
keyCtx := keyData{}
62+
keyCtx.key = key
63+
keyCtx.ctx = context.Background()
64+
// infralog.GetInfraLogger(infralog.WithInitService())
65+
return keyCtx
66+
}
67+
5368
func SharedGatewayController() *GatewayController {
5469
ctrlonce.Do(func() {
5570
controllerInstance = &GatewayController{
@@ -126,7 +141,8 @@ func (c *GatewayController) SetupEventHandlers(k8sinfo k8s.K8sinformers) {
126141
utils.AviLog.Debugf("Endpointslice Add event: Endpointslice does not have backing svc")
127142
return
128143
}
129-
key := utils.Endpointslices + "/" + namespace + "/" + svcName
144+
UUID := uuid.New()
145+
key := utils.Endpointslices + "/" + namespace + "/" + svcName + "-" + UUID.String()
130146
bkt := utils.Bkt(namespace, numWorkers)
131147
c.workqueue[bkt].AddRateLimited(key)
132148
utils.AviLog.Debugf("key: %s, msg: ADD", key)
@@ -155,7 +171,8 @@ func (c *GatewayController) SetupEventHandlers(k8sinfo k8s.K8sinformers) {
155171
utils.AviLog.Debugf("Endpointslice Delete event: Endpointslice does not have backing svc")
156172
return
157173
}
158-
key := utils.Endpointslices + "/" + namespace + "/" + svcName
174+
UUID := uuid.New()
175+
key := utils.Endpointslices + "/" + namespace + "/" + svcName + "-" + UUID.String()
159176
bkt := utils.Bkt(namespace, numWorkers)
160177
c.workqueue[bkt].AddRateLimited(key)
161178
utils.AviLog.Debugf("key: %s, msg: DELETE", key)
@@ -177,7 +194,8 @@ func (c *GatewayController) SetupEventHandlers(k8sinfo k8s.K8sinformers) {
177194
}
178195
svcName = svcNameOld
179196
}
180-
key := utils.Endpointslices + "/" + namespace + "/" + svcName
197+
UUID := uuid.New()
198+
key := utils.Endpointslices + "/" + namespace + "/" + svcName + "-" + UUID.String()
181199
bkt := utils.Bkt(namespace, numWorkers)
182200
c.workqueue[bkt].AddRateLimited(key)
183201
utils.AviLog.Debugf("key: %s, msg: UPDATE", key)
@@ -513,7 +531,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
513531
return
514532
}
515533
gw := obj.(*gatewayv1.Gateway)
516-
key := lib.Gateway + "/" + utils.ObjKey(gw)
534+
UUID := uuid.New()
535+
key := lib.Gateway + "/" + utils.ObjKey(gw) + "-" + UUID.String()
517536
ok, resVer := objects.SharedResourceVerInstanceLister().Get(key)
518537
if ok && resVer.(string) == gw.ResourceVersion {
519538
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
@@ -555,7 +574,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
555574
return
556575
}
557576
}
558-
key := lib.Gateway + "/" + utils.ObjKey(gw)
577+
UUID := uuid.New()
578+
key := lib.Gateway + "/" + utils.ObjKey(gw) + "-" + UUID.String()
559579
objects.SharedResourceVerInstanceLister().Delete(key)
560580
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(gw))
561581
bkt := utils.Bkt(namespace, numWorkers)
@@ -570,7 +590,9 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
570590
oldGw := old.(*gatewayv1.Gateway)
571591
gw := obj.(*gatewayv1.Gateway)
572592
if IsGatewayUpdated(oldGw, gw) {
573-
key := lib.Gateway + "/" + utils.ObjKey(gw)
593+
UUID := uuid.New()
594+
key := lib.Gateway + "/" + utils.ObjKey(gw) + "-" + UUID.String()
595+
574596
valid, allowedRoutesAll := IsValidGateway(key, gw)
575597
if !valid {
576598
return
@@ -599,7 +621,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
599621
return
600622
}
601623
gwClass := obj.(*gatewayv1.GatewayClass)
602-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass)
624+
UUID := uuid.New()
625+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass) + "-" + UUID.String()
603626
ok, resVer := objects.SharedResourceVerInstanceLister().Get(key)
604627
if ok && resVer.(string) == gwClass.ResourceVersion {
605628
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
@@ -635,7 +658,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
635658
if !akogatewayapilib.CheckGatewayClassController(controllerName) {
636659
return
637660
}
638-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass)
661+
UUID := uuid.New()
662+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass) + "-" + UUID.String()
639663
objects.SharedResourceVerInstanceLister().Delete(key)
640664
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(gwClass))
641665
bkt := utils.Bkt(namespace, numWorkers)
@@ -649,7 +673,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
649673
oldGwClass := old.(*gatewayv1.GatewayClass)
650674
gwClass := obj.(*gatewayv1.GatewayClass)
651675
if !reflect.DeepEqual(oldGwClass.Spec, gwClass.Spec) || gwClass.GetDeletionTimestamp() != nil {
652-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass)
676+
UUID := uuid.New()
677+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass) + "-" + UUID.String()
653678
if !IsGatewayClassValid(key, gwClass) {
654679
return
655680
}
@@ -668,7 +693,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
668693
return
669694
}
670695
httpRoute := obj.(*gatewayv1.HTTPRoute)
671-
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute)
696+
UUID := uuid.New()
697+
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute) + UUID.String()
672698
ok, resVer := objects.SharedResourceVerInstanceLister().Get(key)
673699
if ok && resVer.(string) == httpRoute.ResourceVersion {
674700
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
@@ -700,7 +726,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
700726
return
701727
}
702728
}
703-
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute)
729+
UUID := uuid.New()
730+
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute) + UUID.String()
704731
objects.SharedResourceVerInstanceLister().Delete(key)
705732
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(httpRoute))
706733
bkt := utils.Bkt(namespace, numWorkers)
@@ -715,7 +742,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
715742
oldHTTPRoute := old.(*gatewayv1.HTTPRoute)
716743
newHTTPRoute := obj.(*gatewayv1.HTTPRoute)
717744
if IsHTTPRouteUpdated(oldHTTPRoute, newHTTPRoute) {
718-
key := lib.HTTPRoute + "/" + utils.ObjKey(newHTTPRoute)
745+
UUID := uuid.New()
746+
key := lib.HTTPRoute + "/" + utils.ObjKey(newHTTPRoute) + UUID.String()
719747
if !IsHTTPRouteConfigValid(key, newHTTPRoute) {
720748
return
721749
}

cmd/ako-main/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func InitializeAKC() {
8080
utils.AviLog.Infof("AKO is running with version: %s", version)
8181

8282
// set the logger for k8s as AviLogger.
83-
klog.SetLogger(logr.New(&utils.AviLog))
83+
klog.SetLogger(logr.New(utils.AviLog))
8484

8585
// Check if we are running inside kubernetes. Hence try authenticating with service token
8686
cfg, err := rest.InClusterConfig()

cmd/test/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"strconv"
5+
"time"
6+
7+
"github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/pkg/utils"
8+
)
9+
10+
func main() {
11+
12+
for i := 0; i < 100; i++ {
13+
go func(i int) {
14+
utils.AviLog.WithContext(i).Infof("hello" + strconv.Itoa(i))
15+
}(i)
16+
}
17+
time.Sleep(1 * time.Second)
18+
}
19+
20+
func LoggerWithContext() {
21+
utils.AviLog.WithContext(1).Infof("hello" + strconv.Itoa(1))
22+
}
23+
24+
func Logger() {
25+
utils.AviLog.Infof("hello" + strconv.Itoa(1))
26+
}

cmd/test/main_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import "testing"
4+
5+
// func BenchmarkLogger(b *testing.B) {
6+
// for i := 0; i < b.N; i++ {
7+
// Logger()
8+
// }
9+
// }
10+
11+
func BenchmarkLoggerWithContext(b *testing.B) {
12+
for i := 0; i < b.N; i++ {
13+
LoggerWithContext()
14+
}
15+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/fatih/structs v1.1.0
1111
github.com/fsnotify/fsnotify v1.7.0
1212
github.com/go-logr/logr v1.2.4
13+
github.com/google/uuid v1.3.1
1314
github.com/gorilla/mux v1.8.0
1415
github.com/jinzhu/copier v0.3.5
1516
github.com/jupp0r/go-priority-queue v0.0.0-20160601094913-ab1073853bde
@@ -53,7 +54,6 @@ require (
5354
github.com/google/gnostic-models v0.6.8 // indirect
5455
github.com/google/go-cmp v0.6.0 // indirect
5556
github.com/google/gofuzz v1.2.0 // indirect
56-
github.com/google/uuid v1.3.1 // indirect
5757
github.com/imdario/mergo v0.3.16 // indirect
5858
github.com/josharian/intern v1.0.0 // indirect
5959
github.com/json-iterator/go v1.1.12 // indirect

pkg/utils/log.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,44 @@ type AviLogger struct {
4747
atom zap.AtomicLevel
4848
}
4949

50+
// type AviLoggerInterface interface {
51+
// logr.LogSink
52+
// WithContext(context.Context) LoggerInterface
53+
// }
54+
55+
// func NewAviLogger(sugar *zap.SugaredLogger, logger *zap.Logger, atom zap.AtomicLevel) AviLoggerInterface {
56+
// return AviLogger{sugar, logger, atom}
57+
// }
58+
59+
// type LoggerInterface interface {
60+
// Infof(string, ...interface{})
61+
// Info(...interface{})
62+
// Warnf(string, ...interface{})
63+
// Warn(...interface{})
64+
// Errorf(string, ...interface{})
65+
// Error(...interface{})
66+
// Debugf(string, ...interface{})
67+
// Debug(...interface{})
68+
// Fatal(...interface{})
69+
// Fatalf(string, ...interface{})
70+
// Named(string) *zap.SugaredLogger
71+
// With(...interface{}) *zap.SugaredLogger
72+
// SetLevel(string)
73+
// Enabled(int) bool
74+
// V(int) logr.LogSink
75+
// WithValues(...interface{}) logr.LogSink
76+
// WithName(string) logr.LogSink
77+
// }
78+
5079
// Init implements logr.LogSink.
5180
func (AviLogger) Init(info logr.RuntimeInfo) {
5281
// Not used
5382
}
5483

84+
func (aviLogger AviLogger) WithContext(traceID int) *zap.SugaredLogger {
85+
return aviLogger.sugar.With("trace-id", traceID)
86+
}
87+
5588
func (aviLogger *AviLogger) Infof(template string, args ...interface{}) {
5689
aviLogger.sugar.Infof(template, args...)
5790
}

pkg/utils/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ func Stringify(serialize interface{}) string {
295295
func ExtractNamespaceObjectName(key string) (string, string) {
296296
segments := strings.Split(key, "/")
297297
if len(segments) == 2 {
298+
segments[1] = strings.Split(segments[1], "-")[0]
298299
return segments[0], segments[1]
299300
}
300301
return "", ""

0 commit comments

Comments
 (0)