Skip to content

Commit

Permalink
Logging cleanup for event handlers, listener and rule manager, and li…
Browse files Browse the repository at this point in the history
…stener synthesizer. Added e2e-test and e2e-clean to make help output. (#410)

Co-authored-by: Shawn Kaplan <[email protected]>
  • Loading branch information
xWink and Shawn Kaplan authored Sep 26, 2023
1 parent d716a0f commit 0a3d875
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 367 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ manifest: ## Generate CRD manifest

e2e-test-namespace := "e2e-test"

## Run e2e tests against cluster pointed to by ~/.kube/config
.PHONY: e2e-test
e2e-test:
e2e-test: ## Run e2e tests against cluster pointed to by ~/.kube/config
@kubectl create namespace $(e2e-test-namespace) > /dev/null 2>&1 || true # ignore already exists error
cd test && go test \
-p 1 \
Expand All @@ -112,7 +111,7 @@ e2e-test:

.SILENT:
.PHONY: e2e-clean
e2e-clean:
e2e-clean: ## Delete eks resources created in the e2e test namespace
@echo -n "Cleaning up e2e tests... "
@kubectl delete namespace $(e2e-test-namespace) > /dev/null 2>&1
@kubectl create namespace $(e2e-test-namespace) > /dev/null 2>&1
Expand Down
22 changes: 9 additions & 13 deletions controllers/eventhandlers/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/aws/aws-application-networking-k8s/pkg/model/core"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"

"github.com/golang/glog"

"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -39,22 +37,21 @@ var ZeroTransitionTime = metav1.NewTime(time.Time{})

func (h *enqueueRequestsForGatewayEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
gwNew := e.Object.(*gateway_api.Gateway)
glog.V(2).Infof("Gateway Create and Spec is %v", gwNew.Spec)

h.log.Infof("Received Create event for Gateway %s-%s", gwNew.Name, gwNew.Namespace)

// initialize transition time
gwNew.Status.Conditions[0].LastTransitionTime = ZeroTransitionTime
h.enqueueImpactedRoutes(queue)
}

func (h *enqueueRequestsForGatewayEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
h.log.Info("Gateway Update ")

gwOld := e.ObjectOld.(*gateway_api.Gateway)
gwNew := e.ObjectNew.(*gateway_api.Gateway)

h.log.Infof("Received Update event for Gateway %s-%s", gwNew.GetName(), gwNew.GetNamespace())

if !equality.Semantic.DeepEqual(gwOld.Spec, gwNew.Spec) {
glog.V(2).Infof("Gateway Update old spec %v to new spec %v",
gwOld.Spec, gwNew.Spec)
// initialize transition time
gwNew.Status.Conditions[0].LastTransitionTime = ZeroTransitionTime
h.enqueueImpactedRoutes(queue)
Expand All @@ -75,10 +72,10 @@ func (h *enqueueRequestsForGatewayEvent) enqueueImpactedRoutes(queue workqueue.R
h.log.Errorf("Failed to list all routes, %s", err)
return
}
for _, route := range routes {

for _, route := range routes {
if len(route.Spec().ParentRefs()) <= 0 {
h.log.Infof("Ignore route no parentRefs %s", route.Name())
h.log.Debugf("Ignoring Route with no parentRef %s-%s", route.Name(), route.Namespace())
continue
}

Expand All @@ -95,7 +92,7 @@ func (h *enqueueRequestsForGatewayEvent) enqueueImpactedRoutes(queue workqueue.R

gw := &gateway_api.Gateway{}
if err := h.client.Get(context.TODO(), gwName, gw); err != nil {
h.log.Infof("Ignore Route with unknown parentRef %s", route.Name())
h.log.Debugf("Ignoring Route with unknown parentRef %s-%s", route.Name(), route.Namespace())
continue
}

Expand All @@ -107,19 +104,18 @@ func (h *enqueueRequestsForGatewayEvent) enqueueImpactedRoutes(queue workqueue.R
}

if err := h.client.Get(context.TODO(), gwClassName, gwClass); err != nil {
h.log.Infof("Ignore Route with unknown Gateway %s", route.Name())
h.log.Debugf("Ignoring Route with unknown Gateway %s-%s", route.Name(), route.Namespace())
continue
}

if gwClass.Spec.ControllerName == config.LatticeGatewayControllerName {
glog.V(2).Infof("Trigger Route from Gateway event, route %s", route.Name())
h.log.Debugf("Adding Route %s-%s to queue due to Gateway event", route.Name(), route.Namespace())
queue.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: route.Namespace(),
Name: route.Name(),
},
})
}

}
}
34 changes: 16 additions & 18 deletions controllers/eventhandlers/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eventhandlers

import (
"context"
"github.com/golang/glog"

"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
Expand All @@ -13,15 +12,18 @@ import (
gateway_api "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/aws/aws-application-networking-k8s/pkg/config"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"
)

func NewEnqueueRequestsForGatewayClassEvent(client client.Client) handler.EventHandler {
func NewEnqueueRequestsForGatewayClassEvent(log gwlog.Logger, client client.Client) handler.EventHandler {
return &enqueueRequestsForGatewayClassEvent{
log: log,
client: client,
}
}

type enqueueRequestsForGatewayClassEvent struct {
log gwlog.Logger
client client.Client
}

Expand All @@ -31,40 +33,36 @@ func (h *enqueueRequestsForGatewayClassEvent) Create(e event.CreateEvent, queue
}

func (h *enqueueRequestsForGatewayClassEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
glog.V(6).Info("GatwayClass, Update ")
}

func (h *enqueueRequestsForGatewayClassEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
glog.V(6).Info("GatewayClass, Delete")
}

func (h *enqueueRequestsForGatewayClassEvent) Generic(e event.GenericEvent, queue workqueue.RateLimitingInterface) {
}

func (h *enqueueRequestsForGatewayClassEvent) enqueueImpactedGateway(queue workqueue.RateLimitingInterface, gwclass *gateway_api.GatewayClass) {

func (h *enqueueRequestsForGatewayClassEvent) enqueueImpactedGateway(
queue workqueue.RateLimitingInterface,
gwClass *gateway_api.GatewayClass,
) {
gwList := &gateway_api.GatewayList{}

h.client.List(context.TODO(), gwList)
err := h.client.List(context.TODO(), gwList)
if err != nil {
h.log.Errorf("Error listing Gateways during GatewayClass event %s", err)
return
}

for _, gw := range gwList.Items {

if string(gw.Spec.GatewayClassName) == string(gwclass.Name) {

if gwclass.Spec.ControllerName == config.LatticeGatewayControllerName {
glog.V(6).Infof("Found matching gateway, %s\n", gw.Name)

if string(gw.Spec.GatewayClassName) == gwClass.Name {
if gwClass.Spec.ControllerName == config.LatticeGatewayControllerName {
h.log.Debugf("Found matching gateway, %s-%s", gw.Name, gw.Namespace)
queue.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: gw.Namespace,
Name: gw.Name,
},
})

}

}

}

}
2 changes: 1 addition & 1 deletion controllers/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func RegisterGatewayController(
stackMarshaller: stackMarshaller,
}

gwClassEventHandler := eventhandlers.NewEnqueueRequestsForGatewayClassEvent(mgrClient)
gwClassEventHandler := eventhandlers.NewEnqueueRequestsForGatewayClassEvent(log, mgrClient)
vpcAssociationPolicyEventHandler := eventhandlers.NewVpcAssociationPolicyEventHandler(log, mgrClient)
builder := ctrl.NewControllerManagedBy(mgr).
For(&gateway_api.Gateway{})
Expand Down
Loading

0 comments on commit 0a3d875

Please sign in to comment.