Skip to content

Commit

Permalink
upgrade dependencies including controller-runtime & k8s (kubernetes-s…
Browse files Browse the repository at this point in the history
…igs#2104)

* update dependencies version including controller-runtime & k8s & aws-sdk-go

* update to use admission/v1

* update to use IngressClassParametersReference

* update to use client.Object

* update to use context from controller-runtime

* update to use client.Object for eventHandlers

* update ec2 mocks

* minor style & test case fixes

* force to use ConfigMapsResourceLock

* update to use golang v1.16.3
  • Loading branch information
M00nF1sh authored Jun 29, 2021
1 parent 385b0d9 commit 5f7ca6d
Show file tree
Hide file tree
Showing 31 changed files with 2,634 additions and 559 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:experimental

FROM --platform=${BUILDPLATFORM} golang:1.15.0 AS base
FROM --platform=${BUILDPLATFORM} golang:1.16.3 AS base
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand Down
7 changes: 3 additions & 4 deletions controllers/elbv2/targetgroupbinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ type targetGroupBindingReconciler struct {
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

func (r *targetGroupBindingReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return runtime.HandleReconcileError(r.reconcile(req), r.logger)
func (r *targetGroupBindingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return runtime.HandleReconcileError(r.reconcile(ctx, req), r.logger)
}

func (r *targetGroupBindingReconciler) reconcile(req ctrl.Request) error {
ctx := context.Background()
func (r *targetGroupBindingReconciler) reconcile(ctx context.Context, req ctrl.Request) error {
tgb := &elbv2api.TargetGroupBinding{}
if err := r.k8sClient.Get(ctx, req.NamespacedName, tgb); err != nil {
return client.IgnoreNotFound(err)
Expand Down
17 changes: 8 additions & 9 deletions controllers/ingress/eventhandlers/ingress_class_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"github.com/go-logr/logr"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/aws-load-balancer-controller/pkg/ingress"
Expand Down Expand Up @@ -37,7 +35,8 @@ type enqueueRequestsForIngressClassEvent struct {
}

func (h *enqueueRequestsForIngressClassEvent) Create(e event.CreateEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngresses(e.Meta)
ingClassNew := e.Object.(*networking.IngressClass)
h.enqueueImpactedIngresses(ingClassNew)
}

func (h *enqueueRequestsForIngressClassEvent) Update(e event.UpdateEvent, _ workqueue.RateLimitingInterface) {
Expand All @@ -52,18 +51,20 @@ func (h *enqueueRequestsForIngressClassEvent) Update(e event.UpdateEvent, _ work
return
}

h.enqueueImpactedIngresses(e.MetaNew)
h.enqueueImpactedIngresses(ingClassNew)
}

func (h *enqueueRequestsForIngressClassEvent) Delete(e event.DeleteEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngresses(e.Meta)
ingClassOld := e.Object.(*networking.IngressClass)
h.enqueueImpactedIngresses(ingClassOld)
}

func (h *enqueueRequestsForIngressClassEvent) Generic(e event.GenericEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngresses(e.Meta)
ingClass := e.Object.(*networking.IngressClass)
h.enqueueImpactedIngresses(ingClass)
}

func (h *enqueueRequestsForIngressClassEvent) enqueueImpactedIngresses(ingClass metav1.Object) {
func (h *enqueueRequestsForIngressClassEvent) enqueueImpactedIngresses(ingClass *networking.IngressClass) {
ingList := &networking.IngressList{}
if err := h.k8sClient.List(context.Background(), ingList,
client.MatchingFields{ingress.IndexKeyIngressClassRefName: ingClass.GetName()}); err != nil {
Expand All @@ -73,13 +74,11 @@ func (h *enqueueRequestsForIngressClassEvent) enqueueImpactedIngresses(ingClass

for index := range ingList.Items {
ing := &ingList.Items[index]
meta, _ := meta.Accessor(ing)

h.logger.V(1).Info("enqueue ingress for ingressClass event",
"ingressClass", ingClass.GetName(),
"ingress", k8s.NamespacedName(ing))
h.ingEventChan <- event.GenericEvent{
Meta: meta,
Object: ing,
}
}
Expand Down
14 changes: 6 additions & 8 deletions controllers/ingress/eventhandlers/ingress_class_params_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"github.com/go-logr/logr"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
elbv2api "sigs.k8s.io/aws-load-balancer-controller/apis/elbv2/v1beta1"
Expand Down Expand Up @@ -37,7 +35,8 @@ type enqueueRequestsForIngressClassParamsEvent struct {
}

func (h *enqueueRequestsForIngressClassParamsEvent) Create(e event.CreateEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngressClasses(e.Meta)
ingClassParamsNew := e.Object.(*elbv2api.IngressClassParams)
h.enqueueImpactedIngressClasses(ingClassParamsNew)
}

func (h *enqueueRequestsForIngressClassParamsEvent) Update(e event.UpdateEvent, _ workqueue.RateLimitingInterface) {
Expand All @@ -52,19 +51,20 @@ func (h *enqueueRequestsForIngressClassParamsEvent) Update(e event.UpdateEvent,
return
}

h.enqueueImpactedIngressClasses(e.MetaNew)
h.enqueueImpactedIngressClasses(ingClassParamsNew)
}

func (h *enqueueRequestsForIngressClassParamsEvent) Delete(e event.DeleteEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngressClasses(e.Meta)
ingClassParamsOld := e.Object.(*elbv2api.IngressClassParams)
h.enqueueImpactedIngressClasses(ingClassParamsOld)
}

func (h *enqueueRequestsForIngressClassParamsEvent) Generic(e event.GenericEvent, _ workqueue.RateLimitingInterface) {
// we don't have any generic event for secrets.
}

//
func (h *enqueueRequestsForIngressClassParamsEvent) enqueueImpactedIngressClasses(ingClassParams metav1.Object) {
func (h *enqueueRequestsForIngressClassParamsEvent) enqueueImpactedIngressClasses(ingClassParams *elbv2api.IngressClassParams) {
ingClassList := &networking.IngressClassList{}
if err := h.k8sClient.List(context.Background(), ingClassList,
client.MatchingFields{ingress.IndexKeyIngressClassParamsRefName: ingClassParams.GetName()}); err != nil {
Expand All @@ -73,13 +73,11 @@ func (h *enqueueRequestsForIngressClassParamsEvent) enqueueImpactedIngressClasse
}
for index := range ingClassList.Items {
ingClass := &ingClassList.Items[index]
meta, _ := meta.Accessor(ingClass)

h.logger.V(1).Info("enqueue ingressClass for ingressClassParams event",
"ingressClassParams", ingClassParams.GetName(),
"ingressClass", ingClass.GetName())
h.ingClassEventChan <- event.GenericEvent{
Meta: meta,
Object: ingClass,
}
}
Expand Down
16 changes: 6 additions & 10 deletions controllers/ingress/eventhandlers/secret_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
corev1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/aws-load-balancer-controller/pkg/ingress"
Expand Down Expand Up @@ -40,7 +38,8 @@ type enqueueRequestsForSecretEvent struct {
}

func (h *enqueueRequestsForSecretEvent) Create(e event.CreateEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedObjects(e.Meta)
secretNew := e.Object.(*corev1.Secret)
h.enqueueImpactedObjects(secretNew)
}

func (h *enqueueRequestsForSecretEvent) Update(e event.UpdateEvent, _ workqueue.RateLimitingInterface) {
Expand All @@ -55,18 +54,19 @@ func (h *enqueueRequestsForSecretEvent) Update(e event.UpdateEvent, _ workqueue.
return
}

h.enqueueImpactedObjects(e.MetaNew)
h.enqueueImpactedObjects(secretNew)
}

func (h *enqueueRequestsForSecretEvent) Delete(e event.DeleteEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedObjects(e.Meta)
secretOld := e.Object.(*corev1.Secret)
h.enqueueImpactedObjects(secretOld)
}

func (h *enqueueRequestsForSecretEvent) Generic(e event.GenericEvent, _ workqueue.RateLimitingInterface) {
// we don't have any generic event for secrets.
}

func (h *enqueueRequestsForSecretEvent) enqueueImpactedObjects(secret metav1.Object) {
func (h *enqueueRequestsForSecretEvent) enqueueImpactedObjects(secret *corev1.Secret) {
secretKey := k8s.NamespacedName(secret)

ingList := &networking.IngressList{}
Expand All @@ -78,13 +78,11 @@ func (h *enqueueRequestsForSecretEvent) enqueueImpactedObjects(secret metav1.Obj
}
for index := range ingList.Items {
ing := &ingList.Items[index]
meta, _ := meta.Accessor(ing)

h.logger.V(1).Info("enqueue ingress for secret event",
"secret", secretKey,
"ingress", k8s.NamespacedName(ing))
h.ingEventChan <- event.GenericEvent{
Meta: meta,
Object: ing,
}
}
Expand All @@ -98,13 +96,11 @@ func (h *enqueueRequestsForSecretEvent) enqueueImpactedObjects(secret metav1.Obj
}
for index := range svcList.Items {
svc := &svcList.Items[index]
meta, _ := meta.Accessor(svc)

h.logger.V(1).Info("enqueue service for secret event",
"secret", secretKey,
"service", k8s.NamespacedName(svc))
h.svcEventChan <- event.GenericEvent{
Meta: meta,
Object: svc,
}
}
Expand Down
17 changes: 8 additions & 9 deletions controllers/ingress/eventhandlers/service_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
corev1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/aws-load-balancer-controller/pkg/ingress"
Expand Down Expand Up @@ -38,7 +36,8 @@ type enqueueRequestsForServiceEvent struct {
}

func (h *enqueueRequestsForServiceEvent) Create(e event.CreateEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngresses(e.Meta)
svcNew := e.Object.(*corev1.Service)
h.enqueueImpactedIngresses(svcNew)
}

func (h *enqueueRequestsForServiceEvent) Update(e event.UpdateEvent, _ workqueue.RateLimitingInterface) {
Expand All @@ -55,18 +54,20 @@ func (h *enqueueRequestsForServiceEvent) Update(e event.UpdateEvent, _ workqueue
return
}

h.enqueueImpactedIngresses(e.MetaNew)
h.enqueueImpactedIngresses(svcNew)
}

func (h *enqueueRequestsForServiceEvent) Delete(e event.DeleteEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngresses(e.Meta)
svcOld := e.Object.(*corev1.Service)
h.enqueueImpactedIngresses(svcOld)
}

func (h *enqueueRequestsForServiceEvent) Generic(e event.GenericEvent, _ workqueue.RateLimitingInterface) {
h.enqueueImpactedIngresses(e.Meta)
svc := e.Object.(*corev1.Service)
h.enqueueImpactedIngresses(svc)
}

func (h *enqueueRequestsForServiceEvent) enqueueImpactedIngresses(svc metav1.Object) {
func (h *enqueueRequestsForServiceEvent) enqueueImpactedIngresses(svc *corev1.Service) {
ingList := &networking.IngressList{}
if err := h.k8sClient.List(context.Background(), ingList,
client.InNamespace(svc.GetNamespace()),
Expand All @@ -78,13 +79,11 @@ func (h *enqueueRequestsForServiceEvent) enqueueImpactedIngresses(svc metav1.Obj
svcKey := k8s.NamespacedName(svc)
for index := range ingList.Items {
ing := &ingList.Items[index]
meta, _ := meta.Accessor(ing)

h.logger.V(1).Info("enqueue ingress for service event",
"service", svcKey,
"ingress", k8s.NamespacedName(ing))
h.ingEventChan <- event.GenericEvent{
Meta: meta,
Object: ing,
}
}
Expand Down
19 changes: 8 additions & 11 deletions controllers/ingress/group_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
corev1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/record"
elbv2api "sigs.k8s.io/aws-load-balancer-controller/apis/elbv2/v1beta1"
Expand Down Expand Up @@ -106,13 +105,11 @@ type groupReconciler struct {
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

// Reconcile
func (r *groupReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return runtime.HandleReconcileError(r.reconcile(req), r.logger)
func (r *groupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return runtime.HandleReconcileError(r.reconcile(ctx, req), r.logger)
}

func (r *groupReconciler) reconcile(req ctrl.Request) error {
ctx := context.Background()
func (r *groupReconciler) reconcile(ctx context.Context, req ctrl.Request) error {
ingGroupID := ingress.DecodeGroupIDFromReconcileRequest(req)
ingGroup, err := r.groupLoader.Load(ctx, ingGroupID)
if err != nil {
Expand Down Expand Up @@ -229,36 +226,36 @@ func (r *groupReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager

func (r *groupReconciler) setupIndexes(ctx context.Context, fieldIndexer client.FieldIndexer, ingressClassResourceAvailable bool) error {
if err := fieldIndexer.IndexField(ctx, &networking.Ingress{}, ingress.IndexKeyServiceRefName,
func(obj k8sruntime.Object) []string {
func(obj client.Object) []string {
return r.referenceIndexer.BuildServiceRefIndexes(context.Background(), obj.(*networking.Ingress))
},
); err != nil {
return err
}
if err := fieldIndexer.IndexField(ctx, &networking.Ingress{}, ingress.IndexKeySecretRefName,
func(obj k8sruntime.Object) []string {
func(obj client.Object) []string {
return r.referenceIndexer.BuildSecretRefIndexes(context.Background(), obj.(*networking.Ingress))
},
); err != nil {
return err
}
if err := fieldIndexer.IndexField(ctx, &corev1.Service{}, ingress.IndexKeySecretRefName,
func(obj k8sruntime.Object) []string {
func(obj client.Object) []string {
return r.referenceIndexer.BuildSecretRefIndexes(context.Background(), obj.(*corev1.Service))
},
); err != nil {
return err
}
if ingressClassResourceAvailable {
if err := fieldIndexer.IndexField(ctx, &networking.IngressClass{}, ingress.IndexKeyIngressClassParamsRefName,
func(obj k8sruntime.Object) []string {
func(obj client.Object) []string {
return r.referenceIndexer.BuildIngressClassParamsRefIndexes(ctx, obj.(*networking.IngressClass))
},
); err != nil {
return err
}
if err := fieldIndexer.IndexField(ctx, &networking.Ingress{}, ingress.IndexKeyIngressClassRefName,
func(obj k8sruntime.Object) []string {
func(obj client.Object) []string {
return r.referenceIndexer.BuildIngressClassRefIndexes(ctx, obj.(*networking.Ingress))
},
); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions controllers/service/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ type serviceReconciler struct {
// +kubebuilder:rbac:groups="",resources=services/status,verbs=update;patch
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

func (r *serviceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return runtime.HandleReconcileError(r.reconcile(req), r.logger)
func (r *serviceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return runtime.HandleReconcileError(r.reconcile(ctx, req), r.logger)
}

func (r *serviceReconciler) reconcile(req ctrl.Request) error {
ctx := context.Background()
func (r *serviceReconciler) reconcile(ctx context.Context, req ctrl.Request) error {
svc := &corev1.Service{}
if err := r.k8sClient.Get(ctx, req.NamespacedName, svc); err != nil {
return client.IgnoreNotFound(err)
Expand Down
Loading

0 comments on commit 5f7ca6d

Please sign in to comment.