Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/AV-214603-master' i…
Browse files Browse the repository at this point in the history
…nto AV-214603-master
  • Loading branch information
pkoshtavmware committed Oct 4, 2024
2 parents afba360 + 72a34ad commit 118cf9f
Show file tree
Hide file tree
Showing 19 changed files with 1,923 additions and 404 deletions.
4 changes: 2 additions & 2 deletions ako-gateway-api/k8s/ako_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
resVer := meta.GetResourceVersion()
objects.SharedResourceVerInstanceLister().Save(key, resVer)
}
if IsValidGateway(key, gatewayObj) {
if valid, _ := IsValidGateway(key, gatewayObj); valid {
filteredGateways = append(filteredGateways, gatewayObj)
}
}
Expand Down Expand Up @@ -304,7 +304,7 @@ func (c *GatewayController) FullSyncK8s(sync bool) error {
resVer := meta.GetResourceVersion()
objects.SharedResourceVerInstanceLister().Save(key, resVer)
}
if IsHTTPRouteValid(key, httpRouteObj) {
if IsHTTPRouteConfigValid(key, httpRouteObj) {
filteredHTTPRoutes = append(filteredHTTPRoutes, httpRouteObj)
}
}
Expand Down
60 changes: 56 additions & 4 deletions ako-gateway-api/k8s/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ package k8s
import (
"fmt"
"reflect"
"sort"
"sync"
"time"

corev1 "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
Expand Down Expand Up @@ -500,13 +503,23 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
return
}
if !IsValidGateway(key, gw) {
valid, allowedRoutesAll := IsValidGateway(key, gw)
if !valid {
return
}
listRoutes, err := validateReferredHTTPRoute(key, allowedRoutesAll, *gw)
if err != nil {
utils.AviLog.Errorf("Validation of Referred HTTPRoutes Failed due to error : %s", err.Error())
}
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(gw))
bkt := utils.Bkt(namespace, numWorkers)
c.workqueue[bkt].AddRateLimited(key)
utils.AviLog.Debugf("key: %s, msg: ADD", key)
for _, route := range listRoutes {
key := lib.HTTPRoute + "/" + utils.ObjKey(route)
c.workqueue[bkt].AddRateLimited(key)
utils.AviLog.Debugf("key: %s, msg: UPDATE", key)
}
},
DeleteFunc: func(obj interface{}) {
if c.DisableSync {
Expand Down Expand Up @@ -542,13 +555,23 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
gw := obj.(*gatewayv1.Gateway)
if IsGatewayUpdated(oldGw, gw) {
key := lib.Gateway + "/" + utils.ObjKey(gw)
if !IsValidGateway(key, gw) {
valid, allowedRoutesAll := IsValidGateway(key, gw)
if !valid {
return
}
listRoutes, err := validateReferredHTTPRoute(key, allowedRoutesAll, *gw)
if err != nil {
utils.AviLog.Errorf("Validation of Referred HTTPRoutes Failed due to error : %s", err.Error())
}
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(gw))
bkt := utils.Bkt(namespace, numWorkers)
c.workqueue[bkt].AddRateLimited(key)
utils.AviLog.Debugf("key: %s, msg: UPDATE", key)
for _, route := range listRoutes {
key := lib.HTTPRoute + "/" + utils.ObjKey(route)
c.workqueue[bkt].AddRateLimited(key)
utils.AviLog.Debugf("key: %s, msg: UPDATE", key)
}
}
},
}
Expand Down Expand Up @@ -635,7 +658,7 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
utils.AviLog.Debugf("key: %s, msg: same resource version returning", key)
return
}
if !IsHTTPRouteValid(key, httpRoute) {
if !IsHTTPRouteConfigValid(key, httpRoute) {
return
}
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(httpRoute))
Expand Down Expand Up @@ -676,7 +699,7 @@ func (c *GatewayController) SetupGatewayApiEventHandlers(numWorkers uint32) {
newHTTPRoute := obj.(*gatewayv1.HTTPRoute)
if IsHTTPRouteUpdated(oldHTTPRoute, newHTTPRoute) {
key := lib.HTTPRoute + "/" + utils.ObjKey(newHTTPRoute)
if !IsHTTPRouteValid(key, newHTTPRoute) {
if !IsHTTPRouteConfigValid(key, newHTTPRoute) {
return
}
namespace, _, _ := cache.SplitMetaNamespaceKey(utils.ObjKey(newHTTPRoute))
Expand Down Expand Up @@ -714,3 +737,32 @@ func validateAviConfigMap(obj interface{}) (*corev1.ConfigMap, bool) {
}
return nil, false
}
func validateReferredHTTPRoute(key string, allowedRoutesAll bool, gateway gatewayv1.Gateway) ([]*gatewayv1.HTTPRoute, error) {

namespace := gateway.Namespace
if allowedRoutesAll {
namespace = metav1.NamespaceAll
}
hrObjs, err := akogatewayapilib.AKOControlConfig().GatewayApiInformers().HTTPRouteInformer.Lister().HTTPRoutes(namespace).List(labels.Set(nil).AsSelector())
httpRoutes := make([]*gatewayv1.HTTPRoute, 0)
if err != nil {
return nil, err
}
for _, httpRoute := range hrObjs {
for _, parentRef := range httpRoute.Spec.ParentRefs {
if parentRef.Name == gatewayv1.ObjectName(gateway.Name) {
if IsHTTPRouteConfigValid(key, httpRoute) {
httpRoutes = append(httpRoutes, httpRoute)
}
break
}
}
}
sort.Slice(httpRoutes, func(i, j int) bool {
if httpRoutes[i].GetCreationTimestamp().Unix() == httpRoutes[j].GetCreationTimestamp().Unix() {
return httpRoutes[i].Namespace+"/"+httpRoutes[i].Name < httpRoutes[j].Namespace+"/"+httpRoutes[j].Name
}
return httpRoutes[i].GetCreationTimestamp().Unix() < httpRoutes[j].GetCreationTimestamp().Unix()
})
return httpRoutes, nil
}
Loading

0 comments on commit 118cf9f

Please sign in to comment.