Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ test: ## Run tests.
.PHONY: toolchain
toolchain: ## Install developer toolchain
./hack/toolchain.sh
./scripts/gen_mocks.sh

##@ Deployment

Expand Down
12 changes: 9 additions & 3 deletions cmd/aws-application-networking-k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import (
anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
"github.com/aws/aws-application-networking-k8s/pkg/config"
"github.com/aws/aws-application-networking-k8s/pkg/k8s"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

var (
Expand Down Expand Up @@ -126,9 +128,13 @@ func main() {
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
}),
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "amazon-vpc-lattice.io",
Expand Down
3,709 changes: 0 additions & 3,709 deletions config/crds/bases/k8s-gateway-v1alpha2.yaml

This file was deleted.

11 changes: 5 additions & 6 deletions controllers/accesslogpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

Expand Down Expand Up @@ -96,9 +95,9 @@ func RegisterAccessLogPolicyController(

builder := ctrl.NewControllerManagedBy(mgr).
For(&anv1alpha1.AccessLogPolicy{}, pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &gwv1beta1.Gateway{}}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &gwv1beta1.HTTPRoute{}}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &gwv1alpha2.GRPCRoute{}}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{}))
Watches(&gwv1beta1.Gateway{}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&gwv1beta1.HTTPRoute{}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Comment on lines +98 to +99
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use gwv1 everywhere now? there are other places when we watch for beta version of gw and routes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For max compatibility and safety I don't think we will watch v1 version resource right away. (and actually that is not required to support v1 - this PR is already able to watch them.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you run any e2e tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I didn't and fixed the e2etest overall, e2etest will run on v1 (instead of v1beta1) resources to prove the controller is capable of handling them.

Watches(&gwv1alpha2.GRPCRoute{}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{}))

return builder.Complete(r)
}
Expand Down Expand Up @@ -334,13 +333,13 @@ func (r *accessLogPolicyReconciler) updateAccessLogPolicyStatus(
return nil
}

func (r *accessLogPolicyReconciler) findImpactedAccessLogPolicies(eventObj client.Object) []reconcile.Request {
func (r *accessLogPolicyReconciler) findImpactedAccessLogPolicies(ctx context.Context, eventObj client.Object) []reconcile.Request {
listOptions := &client.ListOptions{
Namespace: eventObj.GetNamespace(),
}

alps := &anv1alpha1.AccessLogPolicyList{}
err := r.client.List(context.TODO(), alps, listOptions)
err := r.client.List(ctx, alps, listOptions)
if err != nil {
r.log.Errorf("Failed to list all Access Log Policies, %s", err)
return []reconcile.Request{}
Expand Down
20 changes: 10 additions & 10 deletions controllers/eventhandlers/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ func NewEnqueueRequestGatewayEvent(log gwlog.Logger, client client.Client) handl

var ZeroTransitionTime = metav1.NewTime(time.Time{})

func (h *enqueueRequestsForGatewayEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForGatewayEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
gwNew := e.Object.(*gateway_api.Gateway)

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)
h.enqueueImpactedRoutes(ctx, queue)
}

func (h *enqueueRequestsForGatewayEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForGatewayEvent) Update(ctx context.Context, e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
gwOld := e.ObjectOld.(*gateway_api.Gateway)
gwNew := e.ObjectNew.(*gateway_api.Gateway)

Expand All @@ -54,20 +54,20 @@ func (h *enqueueRequestsForGatewayEvent) Update(e event.UpdateEvent, queue workq
if !equality.Semantic.DeepEqual(gwOld.Spec, gwNew.Spec) {
// initialize transition time
gwNew.Status.Conditions[0].LastTransitionTime = ZeroTransitionTime
h.enqueueImpactedRoutes(queue)
h.enqueueImpactedRoutes(ctx, queue)
}
}

func (h *enqueueRequestsForGatewayEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForGatewayEvent) Delete(ctx context.Context, e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
// TODO: delete gateway
}

func (h *enqueueRequestsForGatewayEvent) Generic(e event.GenericEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForGatewayEvent) Generic(ctx context.Context, e event.GenericEvent, queue workqueue.RateLimitingInterface) {

}

func (h *enqueueRequestsForGatewayEvent) enqueueImpactedRoutes(queue workqueue.RateLimitingInterface) {
routes, err := core.ListAllRoutes(context.TODO(), h.client)
func (h *enqueueRequestsForGatewayEvent) enqueueImpactedRoutes(ctx context.Context, queue workqueue.RateLimitingInterface) {
routes, err := core.ListAllRoutes(ctx, h.client)
if err != nil {
h.log.Errorf("Failed to list all routes, %s", err)
return
Expand All @@ -91,7 +91,7 @@ func (h *enqueueRequestsForGatewayEvent) enqueueImpactedRoutes(queue workqueue.R
}

gw := &gateway_api.Gateway{}
if err := h.client.Get(context.TODO(), gwName, gw); err != nil {
if err := h.client.Get(ctx, gwName, gw); err != nil {
h.log.Debugf("Ignoring Route with unknown parentRef %s-%s", route.Name(), route.Namespace())
continue
}
Expand All @@ -103,7 +103,7 @@ func (h *enqueueRequestsForGatewayEvent) enqueueImpactedRoutes(queue workqueue.R
Name: string(gw.Spec.GatewayClassName),
}

if err := h.client.Get(context.TODO(), gwClassName, gwClass); err != nil {
if err := h.client.Get(ctx, gwClassName, gwClass); err != nil {
h.log.Debugf("Ignoring Route with unknown Gateway %s-%s", route.Name(), route.Namespace())
continue
}
Expand Down
13 changes: 7 additions & 6 deletions controllers/eventhandlers/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ type enqueueRequestsForGatewayClassEvent struct {
client client.Client
}

func (h *enqueueRequestsForGatewayClassEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForGatewayClassEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
gwClassNew := e.Object.(*gateway_api.GatewayClass)
h.enqueueImpactedGateway(queue, gwClassNew)
h.enqueueImpactedGateway(ctx, queue, gwClassNew)
}

func (h *enqueueRequestsForGatewayClassEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForGatewayClassEvent) Update(ctx context.Context, e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
}

func (h *enqueueRequestsForGatewayClassEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForGatewayClassEvent) Delete(ctx context.Context, e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
}

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

func (h *enqueueRequestsForGatewayClassEvent) enqueueImpactedGateway(
ctx context.Context,
queue workqueue.RateLimitingInterface,
gwClass *gateway_api.GatewayClass,
) {
gwList := &gateway_api.GatewayList{}
err := h.client.List(context.TODO(), gwList)
err := h.client.List(ctx, gwList)
if err != nil {
h.log.Errorf("Error listing Gateways during GatewayClass event %s", err)
return
Expand Down
4 changes: 2 additions & 2 deletions controllers/eventhandlers/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func (h *policyEventHandler[T]) MapObjectToPolicy() handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(h.mapObjectToPolicy)
}

func (h *policyEventHandler[T]) mapObjectToPolicy(eventObj client.Object) []reconcile.Request {
func (h *policyEventHandler[T]) mapObjectToPolicy(ctx context.Context, eventObj client.Object) []reconcile.Request {
var requests []reconcile.Request
policies, err := policyhelper.GetAttachedPolicies(context.Background(), h.client, k8s.NamespacedName(eventObj), *new(T))
policies, err := policyhelper.GetAttachedPolicies(ctx, h.client, k8s.NamespacedName(eventObj), *new(T))
if err != nil {
h.log.Errorf("Failed calling k8s operation: %s", err.Error())
return requests
Expand Down
2 changes: 1 addition & 1 deletion controllers/eventhandlers/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMapObjectToPolicy(t *testing.T) {
return nil
})

reqs := h.mapObjectToPolicy(&gwv1alpha2.Gateway{
reqs := h.mapObjectToPolicy(context.Background(), &gwv1alpha2.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "gw-1",
Namespace: "default",
Expand Down
14 changes: 6 additions & 8 deletions controllers/eventhandlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@ func NewServiceEventHandler(log gwlog.Logger, client client.Client) *serviceEven
}

func (h *serviceEventHandler) MapToRoute(routeType core.RouteType) handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
return h.mapToRoute(obj, routeType)
return handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
return h.mapToRoute(ctx, obj, routeType)
})
}

func (h *serviceEventHandler) MapToServiceExport() handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
return h.mapToServiceExport(obj)
return handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
return h.mapToServiceExport(ctx, obj)
})
}

func (h *serviceEventHandler) mapToServiceExport(obj client.Object) []reconcile.Request {
func (h *serviceEventHandler) mapToServiceExport(ctx context.Context, obj client.Object) []reconcile.Request {
var requests []reconcile.Request

ctx := context.Background()
svc := h.mapToService(ctx, obj)
svcExport := h.mapper.ServiceToServiceExport(ctx, svc)
if svcExport != nil {
Expand All @@ -63,8 +62,7 @@ func (h *serviceEventHandler) mapToService(ctx context.Context, obj client.Objec
return nil
}

func (h *serviceEventHandler) mapToRoute(obj client.Object, routeType core.RouteType) []reconcile.Request {
ctx := context.Background()
func (h *serviceEventHandler) mapToRoute(ctx context.Context, obj client.Object, routeType core.RouteType) []reconcile.Request {
svc := h.mapToService(ctx, obj)
routes := h.mapper.ServiceToRoutes(ctx, svc, routeType)

Expand Down
4 changes: 2 additions & 2 deletions controllers/eventhandlers/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestServiceEventHandler_MapToRoute(t *testing.T) {
},
}
for _, obj := range objs {
reqs := h.mapToRoute(obj, core.HttpRouteType)
reqs := h.mapToRoute(context.Background(), obj, core.HttpRouteType)
assert.Len(t, reqs, 1)
assert.Equal(t, "valid-route", reqs[0].Name)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestServiceEventHandler_MapToServiceExport(t *testing.T) {
},
}
for _, obj := range objs {
reqs := h.mapToServiceExport(obj)
reqs := h.mapToServiceExport(context.Background(), obj)
assert.Len(t, reqs, 1)
assert.Equal(t, "test-service", reqs[0].Name)
}
Expand Down
7 changes: 3 additions & 4 deletions controllers/eventhandlers/serviceimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ func NewServiceImportEventHandler(log gwlog.Logger, client client.Client) *servi
}

func (h *serviceImportEventHandler) MapToRoute(routeType core.RouteType) handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
return h.mapToRoute(obj, routeType)
return handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
return h.mapToRoute(ctx, obj, routeType)
})
}

func (h *serviceImportEventHandler) mapToRoute(obj client.Object, routeType core.RouteType) []reconcile.Request {
ctx := context.Background()
func (h *serviceImportEventHandler) mapToRoute(ctx context.Context, obj client.Object, routeType core.RouteType) []reconcile.Request {
routes := h.mapper.ServiceImportToRoutes(ctx, obj.(*anv1alpha1.ServiceImport), routeType)

var requests []reconcile.Request
Expand Down
2 changes: 1 addition & 1 deletion controllers/eventhandlers/serviceimport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestServiceImportEventHandler_MapToRoute(t *testing.T) {
},
).AnyTimes()

reqs := h.mapToRoute(&anv1alpha1.ServiceImport{
reqs := h.mapToRoute(context.Background(), &anv1alpha1.ServiceImport{
ObjectMeta: metav1.ObjectMeta{
Name: "test-service",
Namespace: "ns1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func NewVpcAssociationPolicyEventHandler(log gwlog.Logger, client client.Client)
}

func (h *vpcAssociationPolicyEventHandler) MapToGateway() handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
return handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
if vap, ok := obj.(*v1alpha1.VpcAssociationPolicy); ok {
if gw := h.mapper.VpcAssociationPolicyToGateway(context.Background(), vap); gw != nil {
if gw := h.mapper.VpcAssociationPolicyToGateway(ctx, vap); gw != nil {
return []reconcile.Request{{NamespacedName: k8s.NamespacedName(gw)}}
}
}
Expand Down
Loading