Skip to content

Commit

Permalink
Update getReadyIngresses to load ingresses at startup
Browse files Browse the repository at this point in the history
Indeed, we can't use label selector as kourier class is not a label, but an annotation. As a result, kourier does not sync ingresses at startup
  • Loading branch information
norbjd authored and knative-prow-robot committed Jul 31, 2023
1 parent 5e4fd61 commit 9027208
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions config/300-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ spec:
value: "kourier-system"
- name: ENABLE_SECRET_INFORMER_FILTERING_BY_CERT_UID
value: "false"
- name: KUBE_API_BURST
value: "200"
- name: KUBE_API_QPS
value: "200"
ports:
- name: http2-xds
containerPort: 18000
Expand Down
21 changes: 11 additions & 10 deletions pkg/reconciler/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ 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 @@ -35,9 +34,10 @@ 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,6 +71,7 @@ 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 @@ -203,7 +204,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(ingressInformer.Lister())
ingressesToSync, err := getReadyIngresses(ctx, knativeClient.NetworkingV1alpha1())
if err != nil {
logger.Fatalw("Failed to fetch ready ingresses", zap.Error(err))
}
Expand Down Expand Up @@ -310,16 +311,16 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
return impl
}

func getReadyIngresses(ingressLister ingresslister.IngressLister) ([]*v1alpha1.Ingress, error) {
ingresses, err := ingressLister.List(labels.SelectorFromSet(map[string]string{
v1alpha1ingress.ClassAnnotationKey: config.KourierIngressClassName,
}))
func getReadyIngresses(ctx context.Context, knativeClient networkingClientSet.NetworkingV1alpha1Interface) ([]*v1alpha1.Ingress, error) {
ingresses, err := knativeClient.Ingresses("").List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
ingressesToWarm := make([]*v1alpha1.Ingress, 0, len(ingresses))
for _, ingress := range ingresses {
if ingress.GetDeletionTimestamp() == nil && // Ignore ingresses that are already marked for deletion.
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.
ingress.GetStatus().GetCondition(v1alpha1.IngressConditionNetworkConfigured).IsTrue() {
ingressesToWarm = append(ingressesToWarm, ingress)
}
Expand Down

0 comments on commit 9027208

Please sign in to comment.