Skip to content

Commit 5f97041

Browse files
author
Doyoon Kim
authored
Upgrade gateway-api@v1.0.0 / controller-runtime@v0.16.3 (#503)
* Upgrade gateway-api@v1.0.0 / controller-runtime@v0.16.3
1 parent 5de8f32 commit 5f97041

File tree

80 files changed

+796
-5605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+796
-5605
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ test: ## Run tests.
7070
.PHONY: toolchain
7171
toolchain: ## Install developer toolchain
7272
./hack/toolchain.sh
73-
./scripts/gen_mocks.sh
7473

7574
##@ Deployment
7675

cmd/aws-application-networking-k8s/main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import (
4747
anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
4848
"github.com/aws/aws-application-networking-k8s/pkg/config"
4949
"github.com/aws/aws-application-networking-k8s/pkg/k8s"
50+
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
51+
"sigs.k8s.io/controller-runtime/pkg/webhook"
5052
)
5153

5254
var (
@@ -126,9 +128,13 @@ func main() {
126128
}
127129

128130
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
129-
Scheme: scheme,
130-
MetricsBindAddress: metricsAddr,
131-
Port: 9443,
131+
Scheme: scheme,
132+
Metrics: metricsserver.Options{
133+
BindAddress: metricsAddr,
134+
},
135+
WebhookServer: webhook.NewServer(webhook.Options{
136+
Port: 9443,
137+
}),
132138
HealthProbeBindAddress: probeAddr,
133139
LeaderElection: enableLeaderElection,
134140
LeaderElectionID: "amazon-vpc-lattice.io",

config/crds/bases/k8s-gateway-v1alpha2.yaml

Lines changed: 0 additions & 3709 deletions
This file was deleted.

controllers/accesslogpolicy_controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"sigs.k8s.io/controller-runtime/pkg/handler"
3535
"sigs.k8s.io/controller-runtime/pkg/predicate"
3636
"sigs.k8s.io/controller-runtime/pkg/reconcile"
37-
"sigs.k8s.io/controller-runtime/pkg/source"
3837
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
3938
gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
4039

@@ -96,9 +95,9 @@ func RegisterAccessLogPolicyController(
9695

9796
builder := ctrl.NewControllerManagedBy(mgr).
9897
For(&anv1alpha1.AccessLogPolicy{}, pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
99-
Watches(&source.Kind{Type: &gwv1beta1.Gateway{}}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
100-
Watches(&source.Kind{Type: &gwv1beta1.HTTPRoute{}}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
101-
Watches(&source.Kind{Type: &gwv1alpha2.GRPCRoute{}}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{}))
98+
Watches(&gwv1beta1.Gateway{}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
99+
Watches(&gwv1beta1.HTTPRoute{}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{})).
100+
Watches(&gwv1alpha2.GRPCRoute{}, handler.EnqueueRequestsFromMapFunc(r.findImpactedAccessLogPolicies), pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{}))
102101

103102
return builder.Complete(r)
104103
}
@@ -334,13 +333,13 @@ func (r *accessLogPolicyReconciler) updateAccessLogPolicyStatus(
334333
return nil
335334
}
336335

337-
func (r *accessLogPolicyReconciler) findImpactedAccessLogPolicies(eventObj client.Object) []reconcile.Request {
336+
func (r *accessLogPolicyReconciler) findImpactedAccessLogPolicies(ctx context.Context, eventObj client.Object) []reconcile.Request {
338337
listOptions := &client.ListOptions{
339338
Namespace: eventObj.GetNamespace(),
340339
}
341340

342341
alps := &anv1alpha1.AccessLogPolicyList{}
343-
err := r.client.List(context.TODO(), alps, listOptions)
342+
err := r.client.List(ctx, alps, listOptions)
344343
if err != nil {
345344
r.log.Errorf("Failed to list all Access Log Policies, %s", err)
346345
return []reconcile.Request{}

controllers/eventhandlers/gateway.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ func NewEnqueueRequestGatewayEvent(log gwlog.Logger, client client.Client) handl
3535

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

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

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

4343
// initialize transition time
4444
gwNew.Status.Conditions[0].LastTransitionTime = ZeroTransitionTime
45-
h.enqueueImpactedRoutes(queue)
45+
h.enqueueImpactedRoutes(ctx, queue)
4646
}
4747

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

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

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

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

6767
}
6868

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

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

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

controllers/eventhandlers/gatewayclass.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,27 @@ type enqueueRequestsForGatewayClassEvent struct {
2727
client client.Client
2828
}
2929

30-
func (h *enqueueRequestsForGatewayClassEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
30+
func (h *enqueueRequestsForGatewayClassEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
3131
gwClassNew := e.Object.(*gateway_api.GatewayClass)
32-
h.enqueueImpactedGateway(queue, gwClassNew)
32+
h.enqueueImpactedGateway(ctx, queue, gwClassNew)
3333
}
3434

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

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

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

4444
func (h *enqueueRequestsForGatewayClassEvent) enqueueImpactedGateway(
45+
ctx context.Context,
4546
queue workqueue.RateLimitingInterface,
4647
gwClass *gateway_api.GatewayClass,
4748
) {
4849
gwList := &gateway_api.GatewayList{}
49-
err := h.client.List(context.TODO(), gwList)
50+
err := h.client.List(ctx, gwList)
5051
if err != nil {
5152
h.log.Errorf("Error listing Gateways during GatewayClass event %s", err)
5253
return

controllers/eventhandlers/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func (h *policyEventHandler[T]) MapObjectToPolicy() handler.EventHandler {
2525
return handler.EnqueueRequestsFromMapFunc(h.mapObjectToPolicy)
2626
}
2727

28-
func (h *policyEventHandler[T]) mapObjectToPolicy(eventObj client.Object) []reconcile.Request {
28+
func (h *policyEventHandler[T]) mapObjectToPolicy(ctx context.Context, eventObj client.Object) []reconcile.Request {
2929
var requests []reconcile.Request
30-
policies, err := policyhelper.GetAttachedPolicies(context.Background(), h.client, k8s.NamespacedName(eventObj), *new(T))
30+
policies, err := policyhelper.GetAttachedPolicies(ctx, h.client, k8s.NamespacedName(eventObj), *new(T))
3131
if err != nil {
3232
h.log.Errorf("Failed calling k8s operation: %s", err.Error())
3333
return requests

controllers/eventhandlers/policy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestMapObjectToPolicy(t *testing.T) {
3939
return nil
4040
})
4141

42-
reqs := h.mapObjectToPolicy(&gwv1alpha2.Gateway{
42+
reqs := h.mapObjectToPolicy(context.Background(), &gwv1alpha2.Gateway{
4343
ObjectMeta: metav1.ObjectMeta{
4444
Name: "gw-1",
4545
Namespace: "default",

controllers/eventhandlers/service.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@ func NewServiceEventHandler(log gwlog.Logger, client client.Client) *serviceEven
2424
}
2525

2626
func (h *serviceEventHandler) MapToRoute(routeType core.RouteType) handler.EventHandler {
27-
return handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
28-
return h.mapToRoute(obj, routeType)
27+
return handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
28+
return h.mapToRoute(ctx, obj, routeType)
2929
})
3030
}
3131

3232
func (h *serviceEventHandler) MapToServiceExport() handler.EventHandler {
33-
return handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
34-
return h.mapToServiceExport(obj)
33+
return handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
34+
return h.mapToServiceExport(ctx, obj)
3535
})
3636
}
3737

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

41-
ctx := context.Background()
4241
svc := h.mapToService(ctx, obj)
4342
svcExport := h.mapper.ServiceToServiceExport(ctx, svc)
4443
if svcExport != nil {
@@ -63,8 +62,7 @@ func (h *serviceEventHandler) mapToService(ctx context.Context, obj client.Objec
6362
return nil
6463
}
6564

66-
func (h *serviceEventHandler) mapToRoute(obj client.Object, routeType core.RouteType) []reconcile.Request {
67-
ctx := context.Background()
65+
func (h *serviceEventHandler) mapToRoute(ctx context.Context, obj client.Object, routeType core.RouteType) []reconcile.Request {
6866
svc := h.mapToService(ctx, obj)
6967
routes := h.mapper.ServiceToRoutes(ctx, svc, routeType)
7068

controllers/eventhandlers/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestServiceEventHandler_MapToRoute(t *testing.T) {
7676
},
7777
}
7878
for _, obj := range objs {
79-
reqs := h.mapToRoute(obj, core.HttpRouteType)
79+
reqs := h.mapToRoute(context.Background(), obj, core.HttpRouteType)
8080
assert.Len(t, reqs, 1)
8181
assert.Equal(t, "valid-route", reqs[0].Name)
8282
}
@@ -124,7 +124,7 @@ func TestServiceEventHandler_MapToServiceExport(t *testing.T) {
124124
},
125125
}
126126
for _, obj := range objs {
127-
reqs := h.mapToServiceExport(obj)
127+
reqs := h.mapToServiceExport(context.Background(), obj)
128128
assert.Len(t, reqs, 1)
129129
assert.Equal(t, "test-service", reqs[0].Name)
130130
}

0 commit comments

Comments
 (0)