Skip to content

Update go to v1.22, controller-runtime dependency to v0.18.2, and kubernetes libs to v0.30.0 #3707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 24, 2024
Merged
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.21.9
1.22.3
2 changes: 2 additions & 0 deletions config/crd/bases/elbv2.k8s.aws_ingressclassparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/elbv2.k8s.aws_targetgroupbindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
Expand Down
1 change: 0 additions & 1 deletion config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
Expand Down
9 changes: 5 additions & 4 deletions controllers/elbv2/eventhandlers/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eventhandlers

import (
"context"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
Expand Down Expand Up @@ -32,13 +33,13 @@ type enqueueRequestsForEndpointsEvent struct {
}

// Create is called in response to an create event - e.g. Pod Creation.
func (h *enqueueRequestsForEndpointsEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointsEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
epNew := e.Object.(*corev1.Endpoints)
h.enqueueImpactedTargetGroupBindings(queue, epNew)
}

// Update is called in response to an update event - e.g. Pod Updated.
func (h *enqueueRequestsForEndpointsEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointsEvent) Update(ctx context.Context, e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
epOld := e.ObjectOld.(*corev1.Endpoints)
epNew := e.ObjectNew.(*corev1.Endpoints)
if !equality.Semantic.DeepEqual(epOld.Subsets, epNew.Subsets) {
Expand All @@ -47,14 +48,14 @@ func (h *enqueueRequestsForEndpointsEvent) Update(e event.UpdateEvent, queue wor
}

// Delete is called in response to a delete event - e.g. Pod Deleted.
func (h *enqueueRequestsForEndpointsEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointsEvent) Delete(ctx context.Context, e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
epOld := e.Object.(*corev1.Endpoints)
h.enqueueImpactedTargetGroupBindings(queue, epOld)
}

// Generic is called in response to an event of an unknown type or a synthetic event triggered as a cron or
// external trigger request - e.g. reconcile AutoScaling, or a WebHook.
func (h *enqueueRequestsForEndpointsEvent) Generic(event.GenericEvent, workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointsEvent) Generic(context.Context, event.GenericEvent, workqueue.RateLimitingInterface) {
}

func (h *enqueueRequestsForEndpointsEvent) enqueueImpactedTargetGroupBindings(queue workqueue.RateLimitingInterface, ep *corev1.Endpoints) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/elbv2/eventhandlers/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func Test_enqueueRequestsForEndpointsEvent_enqueueImpactedTargetGroupBindings(t
k8sClient: k8sClient,
logger: logr.New(&log.NullLogSink{}),
}
queue := controllertest.Queue{Interface: workqueue.New()}
queue := &controllertest.Queue{Interface: workqueue.New()}
h.enqueueImpactedTargetGroupBindings(queue, tt.args.eps)
gotRequests := testutils.ExtractCTRLRequestsFromQueue(queue)
assert.True(t, cmp.Equal(tt.wantRequests, gotRequests),
Expand Down
16 changes: 8 additions & 8 deletions controllers/elbv2/eventhandlers/endpointslices.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,36 @@ type enqueueRequestsForEndpointSlicesEvent struct {
}

// Create is called in response to an create event - e.g. EndpointSlice Creation.
func (h *enqueueRequestsForEndpointSlicesEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointSlicesEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
epNew := e.Object.(*discv1.EndpointSlice)
h.logger.V(1).Info("Create event for EndpointSlices", "name", epNew.Name)
h.enqueueImpactedTargetGroupBindings(queue, epNew)
h.enqueueImpactedTargetGroupBindings(ctx, queue, epNew)
}

// Update is called in response to an update event - e.g. EndpointSlice Updated.
func (h *enqueueRequestsForEndpointSlicesEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointSlicesEvent) Update(ctx context.Context, e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
epOld := e.ObjectOld.(*discv1.EndpointSlice)
epNew := e.ObjectNew.(*discv1.EndpointSlice)
h.logger.V(1).Info("Update event for EndpointSlices", "name", epNew.Name)
if !equality.Semantic.DeepEqual(epOld.Ports, epNew.Ports) || !equality.Semantic.DeepEqual(epOld.Endpoints, epNew.Endpoints) {
h.logger.V(1).Info("Enqueue EndpointSlice", "name", epNew.Name)
h.enqueueImpactedTargetGroupBindings(queue, epNew)
h.enqueueImpactedTargetGroupBindings(ctx, queue, epNew)
}
}

// Delete is called in response to a delete event - e.g. EndpointSlice Deleted.
func (h *enqueueRequestsForEndpointSlicesEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointSlicesEvent) Delete(ctx context.Context, e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
epOld := e.Object.(*discv1.EndpointSlice)
h.logger.V(1).Info("Deletion event for EndpointSlices", "name", epOld.Name)
h.enqueueImpactedTargetGroupBindings(queue, epOld)
h.enqueueImpactedTargetGroupBindings(ctx, queue, epOld)
}

// Generic is called in response to an event of an unknown type or a synthetic event triggered as a cron or
// external trigger request - e.g. reconcile AutoScaling, or a WebHook.
func (h *enqueueRequestsForEndpointSlicesEvent) Generic(event.GenericEvent, workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForEndpointSlicesEvent) Generic(context.Context, event.GenericEvent, workqueue.RateLimitingInterface) {
}

func (h *enqueueRequestsForEndpointSlicesEvent) enqueueImpactedTargetGroupBindings(queue workqueue.RateLimitingInterface, epSlice *discv1.EndpointSlice) {
func (h *enqueueRequestsForEndpointSlicesEvent) enqueueImpactedTargetGroupBindings(ctx context.Context, queue workqueue.RateLimitingInterface, epSlice *discv1.EndpointSlice) {
tgbList := &elbv2api.TargetGroupBindingList{}
svcName, present := epSlice.Labels[svcNameLabel]
if !present {
Expand Down
4 changes: 2 additions & 2 deletions controllers/elbv2/eventhandlers/endpointslices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func Test_enqueueRequestsForEndpointSlicesEvent_enqueueImpactedTargetGroupBindin
k8sClient: k8sClient,
logger: logr.New(&log.NullLogSink{}),
}
queue := controllertest.Queue{Interface: workqueue.New()}
h.enqueueImpactedTargetGroupBindings(queue, tt.args.epslice)
queue := &controllertest.Queue{Interface: workqueue.New()}
h.enqueueImpactedTargetGroupBindings(context.Background(), queue, tt.args.epslice)
gotRequests := testutils.ExtractCTRLRequestsFromQueue(queue)
assert.True(t, cmp.Equal(tt.wantRequests, gotRequests),
"diff", cmp.Diff(tt.wantRequests, gotRequests))
Expand Down
16 changes: 8 additions & 8 deletions controllers/elbv2/eventhandlers/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ type enqueueRequestsForNodeEvent struct {
}

// Create is called in response to an create event - e.g. Pod Creation.
func (h *enqueueRequestsForNodeEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForNodeEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
nodeNew := e.Object.(*corev1.Node)
h.enqueueImpactedTargetGroupBindings(queue, nil, nodeNew)
h.enqueueImpactedTargetGroupBindings(ctx, queue, nil, nodeNew)
}

// Update is called in response to an update event - e.g. Pod Updated.
func (h *enqueueRequestsForNodeEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForNodeEvent) Update(ctx context.Context, e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
nodeOld := e.ObjectOld.(*corev1.Node)
nodeNew := e.ObjectNew.(*corev1.Node)
h.enqueueImpactedTargetGroupBindings(queue, nodeOld, nodeNew)
h.enqueueImpactedTargetGroupBindings(ctx, queue, nodeOld, nodeNew)
}

// Delete is called in response to a delete event - e.g. Pod Deleted.
func (h *enqueueRequestsForNodeEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForNodeEvent) Delete(ctx context.Context, e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
nodeOld := e.Object.(*corev1.Node)
h.enqueueImpactedTargetGroupBindings(queue, nodeOld, nil)
h.enqueueImpactedTargetGroupBindings(ctx, queue, nodeOld, nil)
}

// Generic is called in response to an event of an unknown type or a synthetic event triggered as a cron or
// external trigger request - e.g. reconcile AutoScaling, or a WebHook.
func (h *enqueueRequestsForNodeEvent) Generic(e event.GenericEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForNodeEvent) Generic(context.Context, event.GenericEvent, workqueue.RateLimitingInterface) {
// nothing to do here
}

// enqueueImpactedTargetGroupBindings will enqueue all impacted TargetGroupBindings for node events.
func (h *enqueueRequestsForNodeEvent) enqueueImpactedTargetGroupBindings(queue workqueue.RateLimitingInterface, nodeOld *corev1.Node, nodeNew *corev1.Node) {
func (h *enqueueRequestsForNodeEvent) enqueueImpactedTargetGroupBindings(ctx context.Context, queue workqueue.RateLimitingInterface, nodeOld *corev1.Node, nodeNew *corev1.Node) {
var nodeKey types.NamespacedName
nodeOldSuitableAsTrafficProxy := false
nodeNewSuitableAsTrafficProxy := false
Expand Down
17 changes: 9 additions & 8 deletions controllers/elbv2/eventhandlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eventhandlers

import (
"context"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
Expand Down Expand Up @@ -30,34 +31,34 @@ type enqueueRequestsForServiceEvent struct {
}

// Create is called in response to an create event - e.g. Pod Creation.
func (h *enqueueRequestsForServiceEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForServiceEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
svcNew := e.Object.(*corev1.Service)
h.enqueueImpactedTargetGroupBindings(queue, svcNew)
h.enqueueImpactedTargetGroupBindings(ctx, queue, svcNew)
}

// Update is called in response to an update event - e.g. Pod Updated.
func (h *enqueueRequestsForServiceEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForServiceEvent) Update(ctx context.Context, e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
svcOld := e.ObjectOld.(*corev1.Service)
svcNew := e.ObjectNew.(*corev1.Service)
if !equality.Semantic.DeepEqual(svcOld.Spec.Ports, svcNew.Spec.Ports) {
h.enqueueImpactedTargetGroupBindings(queue, svcNew)
h.enqueueImpactedTargetGroupBindings(ctx, queue, svcNew)
}
}

// Delete is called in response to a delete event - e.g. Pod Deleted.
func (h *enqueueRequestsForServiceEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForServiceEvent) Delete(ctx context.Context, e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
svcOld := e.Object.(*corev1.Service)
h.enqueueImpactedTargetGroupBindings(queue, svcOld)
h.enqueueImpactedTargetGroupBindings(ctx, queue, svcOld)
}

// Generic is called in response to an event of an unknown type or a synthetic event triggered as a cron or
// external trigger request - e.g. reconcile AutoScaling, or a WebHook.
func (h *enqueueRequestsForServiceEvent) Generic(e event.GenericEvent, queue workqueue.RateLimitingInterface) {
func (h *enqueueRequestsForServiceEvent) Generic(context.Context, event.GenericEvent, workqueue.RateLimitingInterface) {
// nothing to do here
}

// enqueueImpactedEndpointBindings will enqueue all impacted TargetGroupBindings for service events.
func (h *enqueueRequestsForServiceEvent) enqueueImpactedTargetGroupBindings(queue workqueue.RateLimitingInterface, svc *corev1.Service) {
func (h *enqueueRequestsForServiceEvent) enqueueImpactedTargetGroupBindings(ctx context.Context, queue workqueue.RateLimitingInterface, svc *corev1.Service) {
tgbList := &elbv2api.TargetGroupBindingList{}
if err := h.k8sClient.List(context.Background(), tgbList,
client.InNamespace(svc.Namespace),
Expand Down
4 changes: 2 additions & 2 deletions controllers/elbv2/eventhandlers/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func Test_enqueueRequestsForServiceEvent_enqueueImpactedTargetGroupBindings(t *t
k8sClient: k8sClient,
logger: logr.New(&log.NullLogSink{}),
}
queue := controllertest.Queue{Interface: workqueue.New()}
h.enqueueImpactedTargetGroupBindings(queue, tt.args.svc)
queue := &controllertest.Queue{Interface: workqueue.New()}
h.enqueueImpactedTargetGroupBindings(context.Background(), queue, tt.args.svc)
gotRequests := testutils.ExtractCTRLRequestsFromQueue(queue)
assert.True(t, cmp.Equal(tt.wantRequests, gotRequests),
"diff", cmp.Diff(tt.wantRequests, gotRequests))
Expand Down
13 changes: 6 additions & 7 deletions controllers/elbv2/targetgroupbinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/aws-load-balancer-controller/pkg/runtime"
"sigs.k8s.io/aws-load-balancer-controller/pkg/targetgroupbinding"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/go-logr/logr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -167,9 +166,9 @@ func (r *targetGroupBindingReconciler) SetupWithManager(ctx context.Context, mgr
return ctrl.NewControllerManagedBy(mgr).
For(&elbv2api.TargetGroupBinding{}).
Named(controllerName).
Watches(&source.Kind{Type: &corev1.Service{}}, svcEventHandler).
Watches(&source.Kind{Type: &discv1.EndpointSlice{}}, epSliceEventsHandler).
Watches(&source.Kind{Type: &corev1.Node{}}, nodeEventsHandler).
Watches(&corev1.Service{}, svcEventHandler).
Watches(&discv1.EndpointSlice{}, epSliceEventsHandler).
Watches(&corev1.Node{}, nodeEventsHandler).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.maxConcurrentReconciles,
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(5*time.Millisecond, r.maxExponentialBackoffDelay)}).
Expand All @@ -180,9 +179,9 @@ func (r *targetGroupBindingReconciler) SetupWithManager(ctx context.Context, mgr
return ctrl.NewControllerManagedBy(mgr).
For(&elbv2api.TargetGroupBinding{}).
Named(controllerName).
Watches(&source.Kind{Type: &corev1.Service{}}, svcEventHandler).
Watches(&source.Kind{Type: &corev1.Endpoints{}}, epsEventsHandler).
Watches(&source.Kind{Type: &corev1.Node{}}, nodeEventsHandler).
Watches(&corev1.Service{}, svcEventHandler).
Watches(&corev1.Endpoints{}, epsEventsHandler).
Watches(&corev1.Node{}, nodeEventsHandler).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.maxConcurrentReconciles,
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(5*time.Millisecond, r.maxExponentialBackoffDelay)}).
Expand Down
29 changes: 15 additions & 14 deletions controllers/ingress/eventhandlers/ingress_class_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eventhandlers

import (
"context"

"github.com/go-logr/logr"
networking "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/equality"
Expand All @@ -15,8 +16,8 @@ import (
)

// NewEnqueueRequestsForIngressClassEvent constructs new enqueueRequestsForIngressClassEvent.
func NewEnqueueRequestsForIngressClassEvent(ingEventChan chan<- event.GenericEvent,
k8sClient client.Client, eventRecorder record.EventRecorder, logger logr.Logger) *enqueueRequestsForIngressClassEvent {
func NewEnqueueRequestsForIngressClassEvent(ingEventChan chan<- event.TypedGenericEvent[*networking.Ingress],
k8sClient client.Client, eventRecorder record.EventRecorder, logger logr.Logger) handler.TypedEventHandler[*networking.IngressClass] {
return &enqueueRequestsForIngressClassEvent{
ingEventChan: ingEventChan,
k8sClient: k8sClient,
Expand All @@ -25,23 +26,23 @@ func NewEnqueueRequestsForIngressClassEvent(ingEventChan chan<- event.GenericEve
}
}

var _ handler.EventHandler = (*enqueueRequestsForIngressClassEvent)(nil)
var _ handler.TypedEventHandler[*networking.IngressClass] = (*enqueueRequestsForIngressClassEvent)(nil)

type enqueueRequestsForIngressClassEvent struct {
ingEventChan chan<- event.GenericEvent
ingEventChan chan<- event.TypedGenericEvent[*networking.Ingress]
k8sClient client.Client
eventRecorder record.EventRecorder
logger logr.Logger
}

func (h *enqueueRequestsForIngressClassEvent) Create(e event.CreateEvent, _ workqueue.RateLimitingInterface) {
ingClassNew := e.Object.(*networking.IngressClass)
func (h *enqueueRequestsForIngressClassEvent) Create(ctx context.Context, e event.TypedCreateEvent[*networking.IngressClass], _ workqueue.RateLimitingInterface) {
ingClassNew := e.Object
h.enqueueImpactedIngresses(ingClassNew)
}

func (h *enqueueRequestsForIngressClassEvent) Update(e event.UpdateEvent, _ workqueue.RateLimitingInterface) {
ingClassOld := e.ObjectOld.(*networking.IngressClass)
ingClassNew := e.ObjectNew.(*networking.IngressClass)
func (h *enqueueRequestsForIngressClassEvent) Update(ctx context.Context, e event.TypedUpdateEvent[*networking.IngressClass], _ workqueue.RateLimitingInterface) {
ingClassOld := e.ObjectOld
ingClassNew := e.ObjectNew

// we only care below update event:
// 2. IngressClass spec updates
Expand All @@ -54,13 +55,13 @@ func (h *enqueueRequestsForIngressClassEvent) Update(e event.UpdateEvent, _ work
h.enqueueImpactedIngresses(ingClassNew)
}

func (h *enqueueRequestsForIngressClassEvent) Delete(e event.DeleteEvent, _ workqueue.RateLimitingInterface) {
ingClassOld := e.Object.(*networking.IngressClass)
func (h *enqueueRequestsForIngressClassEvent) Delete(ctx context.Context, e event.TypedDeleteEvent[*networking.IngressClass], _ workqueue.RateLimitingInterface) {
ingClassOld := e.Object
h.enqueueImpactedIngresses(ingClassOld)
}

func (h *enqueueRequestsForIngressClassEvent) Generic(e event.GenericEvent, _ workqueue.RateLimitingInterface) {
ingClass := e.Object.(*networking.IngressClass)
func (h *enqueueRequestsForIngressClassEvent) Generic(ctx context.Context, e event.TypedGenericEvent[*networking.IngressClass], _ workqueue.RateLimitingInterface) {
ingClass := e.Object
h.enqueueImpactedIngresses(ingClass)
}

Expand All @@ -78,7 +79,7 @@ func (h *enqueueRequestsForIngressClassEvent) enqueueImpactedIngresses(ingClass
h.logger.V(1).Info("enqueue ingress for ingressClass event",
"ingressClass", ingClass.GetName(),
"ingress", k8s.NamespacedName(ing))
h.ingEventChan <- event.GenericEvent{
h.ingEventChan <- event.TypedGenericEvent[*networking.Ingress]{
Object: ing,
}
}
Expand Down
Loading