Skip to content
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

Use informer for startupTranslator #1075

Merged
merged 3 commits into from
Jul 12, 2023
Merged
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
31 changes: 14 additions & 17 deletions pkg/reconciler/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -204,26 +203,24 @@ 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))
}
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 kubernetesClient.CoreV1().Secrets(ns).Get(ctx, name, metav1.GetOptions{})
return secretInformer.Lister().Secrets(ns).Get(name)
Copy link
Member

Choose a reason for hiding this comment

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

Just to make sure, we are now using the filtered secretInformer instead of the unfiltered kubeclient. It seems that Kourier can have just the secret filtered here: https://github.com/knative-sandbox/net-kourier/blob/main/pkg/reconciler/informerfiltering/util.go#L44. So this should be fine, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think no problem.

Secrets for internal-encryption has networking.internal.knative.dev/certificate-uid label in serving repo and Secrets for DomainMapping BYO should be added networking.internal.knative.dev/certificate-uid by users so we just need to take care of the filtered secrets when users enabled the filtering.

},
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)

Expand Down Expand Up @@ -313,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)
}
Expand Down