Skip to content

Commit a629970

Browse files
committed
Change function signatures
1 parent caaff4e commit a629970

22 files changed

+199
-158
lines changed

ako-clean/cleanup.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func sanitzeAviCloud() error {
412412
Model: "cloud",
413413
}
414414
restLayer := rest.NewRestOperations(nil, true)
415-
return restLayer.AviRestOperateWrapper(aviClient, []*utils.RestOp{&restOp}, "aviCleanup")
415+
return restLayer.AviRestOperateWrapper(context.Background(), aviClient, []*utils.RestOp{&restOp}, "aviCleanup")
416416
}
417417

418418
func checkAndUpdateIPAM() error {
@@ -449,7 +449,7 @@ func checkAndUpdateIPAM() error {
449449
Model: "ipamdnsproviderprofile",
450450
}
451451
restLayer := rest.NewRestOperations(nil, true)
452-
return restLayer.AviRestOperateWrapper(aviClient, []*utils.RestOp{&restOp}, "aviCleanup")
452+
return restLayer.AviRestOperateWrapper(context.Background(), aviClient, []*utils.RestOp{&restOp}, "aviCleanup")
453453
}
454454

455455
func convertPemToDer(cert string) string {

ako-gateway-api/k8s/ako_init.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ func (c *GatewayController) publishAllParentVSKeysToRestLayer() {
385385
modelName := vsCacheKey.Namespace + "/" + vsCacheKey.Name
386386
delete(allModels, modelName)
387387
utils.AviLog.Infof("Model published in full sync %s", modelName)
388-
nodes.PublishKeyToRestLayer(modelName, "fullsync", sharedQueue)
388+
nodes.PublishKeyToRestLayer(context.Background(), "fullsync", modelName, sharedQueue)
389389

390390
}
391391
// Now also publish the newly generated models (if any)
392392
// Publish all the models to REST layer.
393393
utils.AviLog.Debugf("Newly generated models that do not exist in cache %s", utils.Stringify(allModels))
394394
for modelName := range allModels {
395-
nodes.PublishKeyToRestLayer(modelName, "fullsync", sharedQueue)
395+
nodes.PublishKeyToRestLayer(context.Background(), "fullsync", modelName, sharedQueue)
396396
}
397397
}
398398

@@ -428,14 +428,14 @@ func (c *GatewayController) FullSync() {
428428
}
429429

430430
func SyncFromNodesLayer(key interface{}, wg *sync.WaitGroup) error {
431-
keyStr, ok := key.(string)
431+
keyStr, ok := key.(akogatewayapilib.KeyContext)
432432
if !ok {
433433
utils.AviLog.Warnf("Unexpected object type: expected string, got %T", key)
434434
return nil
435435
}
436436
cache := avicache.SharedAviObjCache()
437437
restlayer := rest.NewRestOperations(cache)
438-
restlayer.DequeueNodes(keyStr)
438+
restlayer.DequeueNodes(keyStr.Ctx, keyStr.KeyStr)
439439
return nil
440440
}
441441

ako-gateway-api/k8s/gateway_controller.go

+24-25
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"sync"
2323
"time"
2424

25-
"github.com/google/uuid"
2625
corev1 "k8s.io/api/core/v1"
2726
discovery "k8s.io/api/discovery/v1"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -141,8 +140,8 @@ func (c *GatewayController) SetupEventHandlers(k8sinfo k8s.K8sinformers) {
141140
utils.AviLog.Debugf("Endpointslice Add event: Endpointslice does not have backing svc")
142141
return
143142
}
144-
UUID := uuid.New()
145-
key := utils.Endpointslices + "/" + namespace + "/" + svcName + "-" + UUID.String()
143+
144+
key := utils.Endpointslices + "/" + namespace + "/" + svcName
146145
bkt := utils.Bkt(namespace, numWorkers)
147146
c.workqueue[bkt].AddRateLimited(key)
148147
utils.AviLog.Debugf("key: %s, msg: ADD", key)
@@ -171,8 +170,8 @@ func (c *GatewayController) SetupEventHandlers(k8sinfo k8s.K8sinformers) {
171170
utils.AviLog.Debugf("Endpointslice Delete event: Endpointslice does not have backing svc")
172171
return
173172
}
174-
UUID := uuid.New()
175-
key := utils.Endpointslices + "/" + namespace + "/" + svcName + "-" + UUID.String()
173+
174+
key := utils.Endpointslices + "/" + namespace + "/" + svcName
176175
bkt := utils.Bkt(namespace, numWorkers)
177176
c.workqueue[bkt].AddRateLimited(key)
178177
utils.AviLog.Debugf("key: %s, msg: DELETE", key)
@@ -194,8 +193,8 @@ func (c *GatewayController) SetupEventHandlers(k8sinfo k8s.K8sinformers) {
194193
}
195194
svcName = svcNameOld
196195
}
197-
UUID := uuid.New()
198-
key := utils.Endpointslices + "/" + namespace + "/" + svcName + "-" + UUID.String()
196+
197+
key := utils.Endpointslices + "/" + namespace + "/" + svcName
199198
bkt := utils.Bkt(namespace, numWorkers)
200199
c.workqueue[bkt].AddRateLimited(key)
201200
utils.AviLog.Debugf("key: %s, msg: UPDATE", key)
@@ -531,8 +530,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
531530
return
532531
}
533532
gw := obj.(*gatewayv1.Gateway)
534-
UUID := uuid.New()
535-
key := lib.Gateway + "/" + utils.ObjKey(gw) + "-" + UUID.String()
533+
534+
key := lib.Gateway + "/" + utils.ObjKey(gw)
536535
ok, resVer := objects.SharedResourceVerInstanceLister().Get(key)
537536
if ok && resVer.(string) == gw.ResourceVersion {
538537
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
@@ -574,8 +573,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
574573
return
575574
}
576575
}
577-
UUID := uuid.New()
578-
key := lib.Gateway + "/" + utils.ObjKey(gw) + "-" + UUID.String()
576+
577+
key := lib.Gateway + "/" + utils.ObjKey(gw)
579578
objects.SharedResourceVerInstanceLister().Delete(key)
580579
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(gw))
581580
bkt := utils.Bkt(namespace, numWorkers)
@@ -590,8 +589,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
590589
oldGw := old.(*gatewayv1.Gateway)
591590
gw := obj.(*gatewayv1.Gateway)
592591
if IsGatewayUpdated(oldGw, gw) {
593-
UUID := uuid.New()
594-
key := lib.Gateway + "/" + utils.ObjKey(gw) + "-" + UUID.String()
592+
593+
key := lib.Gateway + "/" + utils.ObjKey(gw)
595594

596595
valid, allowedRoutesAll := IsValidGateway(key, gw)
597596
if !valid {
@@ -621,8 +620,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
621620
return
622621
}
623622
gwClass := obj.(*gatewayv1.GatewayClass)
624-
UUID := uuid.New()
625-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass) + "-" + UUID.String()
623+
624+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass)
626625
ok, resVer := objects.SharedResourceVerInstanceLister().Get(key)
627626
if ok && resVer.(string) == gwClass.ResourceVersion {
628627
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
@@ -658,8 +657,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
658657
if !akogatewayapilib.CheckGatewayClassController(controllerName) {
659658
return
660659
}
661-
UUID := uuid.New()
662-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass) + "-" + UUID.String()
660+
661+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass)
663662
objects.SharedResourceVerInstanceLister().Delete(key)
664663
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(gwClass))
665664
bkt := utils.Bkt(namespace, numWorkers)
@@ -673,8 +672,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
673672
oldGwClass := old.(*gatewayv1.GatewayClass)
674673
gwClass := obj.(*gatewayv1.GatewayClass)
675674
if !reflect.DeepEqual(oldGwClass.Spec, gwClass.Spec) || gwClass.GetDeletionTimestamp() != nil {
676-
UUID := uuid.New()
677-
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass) + "-" + UUID.String()
675+
676+
key := lib.GatewayClass + "/" + utils.ObjKey(gwClass)
678677
if !IsGatewayClassValid(key, gwClass) {
679678
return
680679
}
@@ -693,8 +692,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
693692
return
694693
}
695694
httpRoute := obj.(*gatewayv1.HTTPRoute)
696-
UUID := uuid.New()
697-
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute) + UUID.String()
695+
696+
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute)
698697
ok, resVer := objects.SharedResourceVerInstanceLister().Get(key)
699698
if ok && resVer.(string) == httpRoute.ResourceVersion {
700699
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
@@ -726,8 +725,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
726725
return
727726
}
728727
}
729-
UUID := uuid.New()
730-
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute) + UUID.String()
728+
729+
key := lib.HTTPRoute + "/" + utils.ObjKey(httpRoute)
731730
objects.SharedResourceVerInstanceLister().Delete(key)
732731
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(httpRoute))
733732
bkt := utils.Bkt(namespace, numWorkers)
@@ -742,8 +741,8 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
742741
oldHTTPRoute := old.(*gatewayv1.HTTPRoute)
743742
newHTTPRoute := obj.(*gatewayv1.HTTPRoute)
744743
if IsHTTPRouteUpdated(oldHTTPRoute, newHTTPRoute) {
745-
UUID := uuid.New()
746-
key := lib.HTTPRoute + "/" + utils.ObjKey(newHTTPRoute) + UUID.String()
744+
745+
key := lib.HTTPRoute + "/" + utils.ObjKey(newHTTPRoute)
747746
if !IsHTTPRouteConfigValid(key, newHTTPRoute) {
748747
return
749748
}

ako-gateway-api/lib/lib.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ package lib
1616

1717
import (
1818
"fmt"
19+
"sort"
1920

2021
"os"
2122
"strings"
2223

24+
cache2 "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/internal/cache"
2325
"k8s.io/apimachinery/pkg/util/intstr"
2426
"k8s.io/client-go/kubernetes"
2527
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2628

2729
"github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/internal/lib"
28-
"github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/internal/nodes"
2930
"github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/pkg/utils"
3031
)
3132

@@ -160,7 +161,7 @@ func IsListenerInvalid(gwStatus *gatewayv1.GatewayStatus, listenerIndex int) boo
160161
func VerifyHostnameSubdomainMatch(hostname string) bool {
161162
// Check if a hostname is valid or not by verifying if it has a prefix that
162163
// matches any of the sub-domains.
163-
subDomains := nodes.GetDefaultSubDomain()
164+
subDomains := GetDefaultSubDomain()
164165
if len(subDomains) == 0 {
165166
// No IPAM DNS configured, we simply pass the hostname
166167
return true
@@ -187,3 +188,24 @@ func ProtocolToRoute(proto string) string {
187188
return innerMap[proto]
188189

189190
}
191+
192+
func GetDefaultSubDomain() []string {
193+
cache := cache2.SharedAviObjCache()
194+
cloud, ok := cache.CloudKeyCache.AviCacheGet(utils.CloudName)
195+
if !ok || cloud == nil {
196+
utils.AviLog.Warnf("Cloud object %s not found in cache", utils.CloudName)
197+
return nil
198+
}
199+
cloudProperty, ok := cloud.(*cache2.AviCloudPropertyCache)
200+
if !ok {
201+
utils.AviLog.Warnf("Cloud property object not found")
202+
return nil
203+
}
204+
205+
if len(cloudProperty.NSIpamDNS) > 0 {
206+
sort.Strings(cloudProperty.NSIpamDNS)
207+
} else {
208+
return nil
209+
}
210+
return cloudProperty.NSIpamDNS
211+
}

ako-gateway-api/lib/types.go

+5
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ func NewKeyContextWithTraceID(key string, ctx context.Context) KeyContext {
4848
return KeyContext{KeyStr: key,
4949
Ctx: logger.SetTraceID(ctx, getNewTraceId())}
5050
}
51+
52+
func NewKeyContext(key string, ctx context.Context) KeyContext {
53+
return KeyContext{KeyStr: key,
54+
Ctx: ctx}
55+
}

ako-gateway-api/nodes/dequeue_ingestion.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func DequeueIngestion(key string, fullsync bool) {
115115
objects.SharedAviGraphLister().Save(modelName, nil)
116116
if !fullsync {
117117
sharedQueue := utils.SharedWorkQueue().GetQueueByName(utils.GraphLayer)
118-
nodes.PublishKeyToRestLayer(modelName, key, sharedQueue)
118+
nodes.PublishKeyToRestLayer(ctx, key, modelName, sharedQueue)
119119
return
120120
}
121121
}
@@ -150,7 +150,7 @@ func DequeueIngestion(key string, fullsync bool) {
150150
modelChanged := saveAviModel(modelName, model.AviObjectGraph, key)
151151
if modelChanged && !fullsync {
152152
sharedQueue := utils.SharedWorkQueue().GetQueueByName(utils.GraphLayer)
153-
nodes.PublishKeyToRestLayer(modelName, key, sharedQueue)
153+
nodes.PublishKeyToRestLayer(ctx, key, modelName, sharedQueue)
154154
}
155155
}
156156
}
@@ -209,7 +209,7 @@ func handleGateway(namespace, name string, fullsync bool, key string) {
209209
objects.SharedAviGraphLister().Save(modelName, nil)
210210
if !fullsync {
211211
sharedQueue := utils.SharedWorkQueue().GetQueueByName(utils.GraphLayer)
212-
nodes.PublishKeyToRestLayer(modelName, key, sharedQueue)
212+
nodes.PublishKeyToRestLayer(context.Background(), key, modelName, sharedQueue)
213213
}
214214
}
215215
return
@@ -223,7 +223,7 @@ func handleGateway(namespace, name string, fullsync bool, key string) {
223223
objects.SharedAviGraphLister().Save(modelName, nil)
224224
if !fullsync {
225225
sharedQueue := utils.SharedWorkQueue().GetQueueByName(utils.GraphLayer)
226-
nodes.PublishKeyToRestLayer(modelName, key, sharedQueue)
226+
nodes.PublishKeyToRestLayer(context.Background(), key, modelName, sharedQueue)
227227
}
228228
return
229229
}
@@ -239,7 +239,7 @@ func handleGateway(namespace, name string, fullsync bool, key string) {
239239
modelChanged := saveAviModel(modelName, aviModelGraph.AviObjectGraph, key)
240240
if modelChanged && !fullsync {
241241
sharedQueue := utils.SharedWorkQueue().GetQueueByName(utils.GraphLayer)
242-
nodes.PublishKeyToRestLayer(modelName, key, sharedQueue)
242+
nodes.PublishKeyToRestLayer(context.Background(), key, modelName, sharedQueue)
243243
}
244244
}
245245

@@ -291,7 +291,7 @@ func (o *AviObjectGraph) ProcessRouteDeletion(key, parentNsName string, routeMod
291291
ok := saveAviModel(modelName, o.AviObjectGraph, key)
292292
if ok && len(o.AviObjectGraph.GetOrderedNodes()) != 0 && !fullsync {
293293
sharedQueue := utils.SharedWorkQueue().GetQueueByName(utils.GraphLayer)
294-
nodes.PublishKeyToRestLayer(modelName, key, sharedQueue)
294+
nodes.PublishKeyToRestLayer(context.Background(), key, modelName, sharedQueue)
295295
}
296296

297297
}

ako-infra/avirest/networking_handler.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package avirest
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"strings"
@@ -183,7 +184,7 @@ func executeRestOp(key string, client *clients.AviClient, restOp *utils.RestOp,
183184
}
184185

185186
restLayer := rest.NewRestOperations(nil, true)
186-
err := restLayer.AviRestOperateWrapper(client, []*utils.RestOp{restOp}, key)
187+
err := restLayer.AviRestOperateWrapper(context.Background(), client, []*utils.RestOp{restOp}, key)
187188
if restOp.Err != nil {
188189
err = restOp.Err
189190
}

internal/k8s/ako_init.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ func (c *AviController) FullSyncK8s(sync bool) error {
881881
// Publish vrfcontext model now, this has to be processed first
882882
vrfModelName = lib.GetModelName(lib.GetTenant(), lib.GetVrf())
883883
utils.AviLog.Infof("Processing model for vrf context in full sync: %s", vrfModelName)
884-
nodes.PublishKeyToRestLayer(vrfModelName, "fullsync", sharedQueue)
884+
nodes.PublishKeyToRestLayer(context.Background(), "fullsync", vrfModelName, sharedQueue)
885885
utils.AviLog.Infof("Processing done for VRF")
886886
} else {
887887
utils.AviLog.Warnf("AKO is not primary instance, skipping vrf context publish in full sync.")
@@ -1354,26 +1354,26 @@ func (c *AviController) publishAllParentVSKeysToRestLayer() {
13541354
if strings.HasPrefix(vsCacheKey.Name, shardVsPrefix) {
13551355
delete(allModels, modelName)
13561356
utils.AviLog.Infof("Model published L7 VS during namespace based sync: %s", modelName)
1357-
nodes.PublishKeyToRestLayer(modelName, "fullsync", sharedQueue)
1357+
nodes.PublishKeyToRestLayer(context.Background(), "fullsync", modelName, sharedQueue)
13581358
}
13591359
}
13601360
// For namespace based syncs, the L4 VSes would be named: clusterName + "--" + namespace
13611361
if strings.HasPrefix(vsCacheKey.Name, lib.GetNamePrefix()+syncNamespace) {
13621362
delete(allModels, modelName)
13631363
utils.AviLog.Infof("Model published L4 VS during namespace based sync: %s", modelName)
1364-
nodes.PublishKeyToRestLayer(modelName, "fullsync", sharedQueue)
1364+
nodes.PublishKeyToRestLayer(context.Background(), "fullsync", modelName, sharedQueue)
13651365
}
13661366
} else {
13671367
delete(allModels, modelName)
13681368
utils.AviLog.Infof("Model published in full sync %s", modelName)
1369-
nodes.PublishKeyToRestLayer(modelName, "fullsync", sharedQueue)
1369+
nodes.PublishKeyToRestLayer(context.Background(), "fullsync", modelName, sharedQueue)
13701370
}
13711371
}
13721372
// Now also publish the newly generated models (if any)
13731373
// Publish all the models to REST layer.
13741374
utils.AviLog.Debugf("Newly generated models that do not exist in cache %s", utils.Stringify(allModels))
13751375
for modelName := range allModels {
1376-
nodes.PublishKeyToRestLayer(modelName, "fullsync", sharedQueue)
1376+
nodes.PublishKeyToRestLayer(context.Background(), "fullsync", modelName, sharedQueue)
13771377
}
13781378
}
13791379

@@ -1513,7 +1513,7 @@ func SyncFromNodesLayer(key interface{}, wg *sync.WaitGroup) error {
15131513
}
15141514
cache := avicache.SharedAviObjCache()
15151515
restlayer := rest.NewRestOperations(cache)
1516-
restlayer.DequeueNodes(keyStr)
1516+
restlayer.DequeueNodes(context.Background(), keyStr)
15171517
return nil
15181518
}
15191519

0 commit comments

Comments
 (0)