From 2cc8ef2c219eb34ff0ef25c167873684ae40515f Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Tue, 11 Jul 2023 11:22:59 +0900 Subject: [PATCH 1/3] User informer to startupTranslator --- pkg/reconciler/ingress/controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/reconciler/ingress/controller.go b/pkg/reconciler/ingress/controller.go index 2d301cc94..6954fd29f 100644 --- a/pkg/reconciler/ingress/controller.go +++ b/pkg/reconciler/ingress/controller.go @@ -214,16 +214,16 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl // resources at startup. startupTranslator := generator.NewIngressTranslator( func(ns, name string) (*corev1.Secret, error) { - return kubernetesClient.CoreV1().Secrets(ns).Get(ctx, name, metav1.GetOptions{}) + return secretInformer.Lister().Secrets(ns).Get(name) }, func(ns, name string) (*corev1.Endpoints, error) { - return kubernetesClient.CoreV1().Endpoints(ns).Get(ctx, name, metav1.GetOptions{}) + return endpointsInformer.Lister().Endpoints(ns).Get(name) }, func(ns, name string) (*corev1.Service, error) { - return kubernetesClient.CoreV1().Services(ns).Get(ctx, name, metav1.GetOptions{}) + return serviceInformer.Lister().Services(ns).Get(name) }, func(name string) (*corev1.Namespace, error) { - return kubernetesClient.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{}) + return namespaceInformer.Lister().Get(name) }, impl.Tracker) From 03b4feb33f8b41fd18d206b287857c6464d4ba89 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Tue, 11 Jul 2023 12:28:19 +0900 Subject: [PATCH 2/3] remove comment --- pkg/reconciler/ingress/controller.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/reconciler/ingress/controller.go b/pkg/reconciler/ingress/controller.go index 6954fd29f..0a9d27aa6 100644 --- a/pkg/reconciler/ingress/controller.go +++ b/pkg/reconciler/ingress/controller.go @@ -210,8 +210,6 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl } logger.Infof("Priming the config with %d ingresses", len(ingressesToSync)) - // The startup translator uses clients instead of listeners to correctly list all - // resources at startup. startupTranslator := generator.NewIngressTranslator( func(ns, name string) (*corev1.Secret, error) { return secretInformer.Lister().Secrets(ns).Get(name) From c7628138b1f7041d4b14f401ed3a8e331aac48dc Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Tue, 11 Jul 2023 12:47:06 +0900 Subject: [PATCH 3/3] Do not use kubeClient for ingress --- pkg/reconciler/ingress/controller.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/reconciler/ingress/controller.go b/pkg/reconciler/ingress/controller.go index 0a9d27aa6..35070f4c6 100644 --- a/pkg/reconciler/ingress/controller.go +++ b/pkg/reconciler/ingress/controller.go @@ -25,6 +25,7 @@ import ( "go.uber.org/zap" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" v1 "k8s.io/client-go/informers/core/v1" @@ -34,10 +35,9 @@ import ( "knative.dev/net-kourier/pkg/generator" rconfig "knative.dev/net-kourier/pkg/reconciler/ingress/config" "knative.dev/networking/pkg/apis/networking/v1alpha1" - networkingClientSet "knative.dev/networking/pkg/client/clientset/versioned/typed/networking/v1alpha1" - knativeclient "knative.dev/networking/pkg/client/injection/client" ingressinformer "knative.dev/networking/pkg/client/injection/informers/networking/v1alpha1/ingress" v1alpha1ingress "knative.dev/networking/pkg/client/injection/reconciler/networking/v1alpha1/ingress" + ingresslister "knative.dev/networking/pkg/client/listers/networking/v1alpha1" netconfig "knative.dev/networking/pkg/config" "knative.dev/networking/pkg/status" kubeclient "knative.dev/pkg/client/injection/kube/client" @@ -71,7 +71,6 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl logger := logging.FromContext(ctx) kubernetesClient := kubeclient.Get(ctx) - knativeClient := knativeclient.Get(ctx) ingressInformer := ingressinformer.Get(ctx) endpointsInformer := endpointsinformer.Get(ctx) serviceInformer := serviceinformer.Get(ctx) @@ -204,7 +203,7 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl } // Get the current list of ingresses that are ready and seed the Envoy config with them. - ingressesToSync, err := getReadyIngresses(ctx, knativeClient.NetworkingV1alpha1()) + ingressesToSync, err := getReadyIngresses(ingressInformer.Lister()) if err != nil { logger.Fatalw("Failed to fetch ready ingresses", zap.Error(err)) } @@ -311,16 +310,16 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl return impl } -func getReadyIngresses(ctx context.Context, knativeClient networkingClientSet.NetworkingV1alpha1Interface) ([]*v1alpha1.Ingress, error) { - ingresses, err := knativeClient.Ingresses("").List(ctx, metav1.ListOptions{}) +func getReadyIngresses(ingressLister ingresslister.IngressLister) ([]*v1alpha1.Ingress, error) { + ingresses, err := ingressLister.List(labels.SelectorFromSet(map[string]string{ + v1alpha1ingress.ClassAnnotationKey: config.KourierIngressClassName, + })) if err != nil { return nil, err } - ingressesToWarm := make([]*v1alpha1.Ingress, 0, len(ingresses.Items)) - for i := range ingresses.Items { - ingress := &ingresses.Items[i] - if isKourierIngress(ingress) && - ingress.GetDeletionTimestamp() == nil && // Ignore ingresses that are already marked for deletion. + ingressesToWarm := make([]*v1alpha1.Ingress, 0, len(ingresses)) + for _, ingress := range ingresses { + if ingress.GetDeletionTimestamp() == nil && // Ignore ingresses that are already marked for deletion. ingress.GetStatus().GetCondition(v1alpha1.IngressConditionNetworkConfigured).IsTrue() { ingressesToWarm = append(ingressesToWarm, ingress) }