Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion internal/controller/apisixconsumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ApisixConsumerReconciler struct {
Readier readiness.ReadinessManager

ICGV schema.GroupVersion
SupportsEndpointSlice bool // cache capability
}

// Reconcile FIXME: implement the reconcile logic (For now, it dose nothing other than directly accepting)
Expand Down Expand Up @@ -98,7 +99,7 @@ func (r *ApisixConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}
defer func() { r.updateStatus(ac, err) }()

if err = ProcessIngressClassParameters(tctx, r.Client, r.Log, ac, ingressClass); err != nil {
if err = ProcessIngressClassParameters(tctx, r.Client, r.Log, ac, ingressClass, r.SupportsEndpointSlice); err != nil {
r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
return ctrl.Result{}, client.IgnoreNotFound(err)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/apisixglobalrule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type ApisixGlobalRuleReconciler struct {
Readier readiness.ReadinessManager

ICGV schema.GroupVersion

SupportsEndpointSlice bool // cache capability
}

// Reconcile implements the reconciliation logic for ApisixGlobalRule
Expand Down Expand Up @@ -103,7 +105,7 @@ func (r *ApisixGlobalRuleReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

// process IngressClass parameters if they reference GatewayProxy
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, &globalRule, ingressClass); err != nil {
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, &globalRule, ingressClass, r.SupportsEndpointSlice); err != nil {
r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
return ctrl.Result{}, client.IgnoreNotFound(err)
}
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/apisixroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ type ApisixRouteReconciler struct {
Readier readiness.ReadinessManager

ICGV schema.GroupVersion
// supportsEndpointSlice indicates whether the cluster supports EndpointSlice API
supportsEndpointSlice bool
// SupportsEndpointSlice indicates whether the cluster supports EndpointSlice API
SupportsEndpointSlice bool
}

// SetupWithManager sets up the controller with the Manager.
func (r *ApisixRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Check and store EndpointSlice API support
r.supportsEndpointSlice = pkgutils.HasAPIResource(mgr, &discoveryv1.EndpointSlice{})
r.SupportsEndpointSlice = pkgutils.HasAPIResource(mgr, &discoveryv1.EndpointSlice{})
var icWatch client.Object
switch r.ICGV.String() {
case networkingv1beta1.SchemeGroupVersion.String():
Expand All @@ -86,7 +86,7 @@ func (r *ApisixRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
predicate.NewPredicateFuncs(TypePredicate[*corev1.Secret]()),
}

if !r.supportsEndpointSlice {
if !r.SupportsEndpointSlice {
eventFilters = append(eventFilters, predicate.NewPredicateFuncs(TypePredicate[*corev1.Endpoints]()))
}

Expand All @@ -109,7 +109,7 @@ func (r *ApisixRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
)

// Conditionally watch EndpointSlice or Endpoints based on cluster API support
bdr = watchEndpointSliceOrEndpoints(bdr, r.supportsEndpointSlice,
bdr = watchEndpointSliceOrEndpoints(bdr, r.SupportsEndpointSlice,
r.listApisixRoutesForService,
r.listApisixRoutesForEndpoints,
r.Log)
Expand Down Expand Up @@ -167,7 +167,7 @@ func (r *ApisixRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
defer func() { r.updateStatus(&ar, err) }()

if err = ProcessIngressClassParameters(tctx, r.Client, r.Log, &ar, ic); err != nil {
if err = ProcessIngressClassParameters(tctx, r.Client, r.Log, &ar, ic, r.SupportsEndpointSlice); err != nil {
r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ic.Name)
return ctrl.Result{}, client.IgnoreNotFound(err)
}
Expand Down Expand Up @@ -491,7 +491,7 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
// It specifies that the target pod's label should be a superset of the subset labels of the ApisixUpstream of the serviceName
subsetLabels := r.getSubsetLabels(tctx, serviceNN, backend.Subset)

if err := resolveServiceEndpoints(tctx, r.Client, serviceNN, r.supportsEndpointSlice, subsetLabels); err != nil {
if err := resolveServiceEndpoints(tctx, r.Client, serviceNN, r.SupportsEndpointSlice, subsetLabels); err != nil {
return types.ReasonError{
Reason: string(apiv2.ConditionReasonInvalidSpec),
Message: err.Error(),
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/apisixtls_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ApisixTlsReconciler struct {
Readier readiness.ReadinessManager

ICGV schema.GroupVersion
SupportsEndpointSlice bool // cache capability
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -135,7 +136,7 @@ func (r *ApisixTlsReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}

// process IngressClass parameters if they reference GatewayProxy
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, &tls, ingressClass); err != nil {
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, &tls, ingressClass, r.SupportsEndpointSlice); err != nil {
r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
r.updateStatus(&tls, metav1.Condition{
Type: string(apiv2.ConditionTypeAccepted),
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/consumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ConsumerReconciler struct { //nolint:revive

Updater status.Updater
Readier readiness.ReadinessManager
SupportsEndpointSlice bool // cache capability
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -219,7 +220,7 @@ func (r *ConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c

rk := utils.NamespacedNameKind(consumer)

if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway, rk); err != nil {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway, rk, r.SupportsEndpointSlice); err != nil {
r.Log.Error(err, "failed to process gateway proxy", "gateway", gateway)
statusErr = err
}
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type GatewayReconciler struct { //nolint:revive
Provider provider.Provider

Updater status.Updater

SupportsEndpointSlice bool //cache capability
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -412,7 +414,7 @@ func (r *GatewayReconciler) listReferenceGrantsForGateway(ctx context.Context, o
}

func (r *GatewayReconciler) processInfrastructure(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway) error {
return ProcessGatewayProxy(r.Client, r.Log, tctx, gateway, utils.NamespacedNameKind(gateway))
return ProcessGatewayProxy(r.Client, r.Log, tctx, gateway, utils.NamespacedNameKind(gateway), r.SupportsEndpointSlice)
}

func (r *GatewayReconciler) processListenerConfig(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway) {
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/gatewayproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ type GatewayProxyController struct {
Provider provider.Provider

ICGV schema.GroupVersion
// supportsEndpointSlice indicates whether the cluster supports EndpointSlice API
supportsEndpointSlice bool
// SupportsEndpointSlice indicates whether the cluster supports EndpointSlice API
SupportsEndpointSlice bool
supportsGateway bool
}

func (r *GatewayProxyController) SetupWithManager(mrg ctrl.Manager) error {
// Check and store EndpointSlice API support
r.supportsEndpointSlice = pkgutils.HasAPIResource(mrg, &discoveryv1.EndpointSlice{})
r.SupportsEndpointSlice = pkgutils.HasAPIResource(mrg, &discoveryv1.EndpointSlice{})
r.supportsGateway = pkgutils.HasAPIResource(mrg, &gatewayv1.Gateway{}) && !config.ControllerConfig.DisableGatewayAPI
var icWatch client.Object
switch r.ICGV.String() {
Expand All @@ -76,7 +76,7 @@ func (r *GatewayProxyController) SetupWithManager(mrg ctrl.Manager) error {
predicate.NewPredicateFuncs(TypePredicate[*corev1.Secret]()),
}

if !r.supportsEndpointSlice {
if !r.SupportsEndpointSlice {
eventFilters = append(eventFilters, predicate.NewPredicateFuncs(TypePredicate[*corev1.Endpoints]()))
}

Expand All @@ -95,7 +95,7 @@ func (r *GatewayProxyController) SetupWithManager(mrg ctrl.Manager) error {
)

// Conditionally watch EndpointSlice or Endpoints based on cluster API support
bdr = watchEndpointSliceOrEndpoints(bdr, r.supportsEndpointSlice,
bdr = watchEndpointSliceOrEndpoints(bdr, r.SupportsEndpointSlice,
r.listGatewayProxiesForProviderEndpointSlice,
r.listGatewayProxiesForProviderEndpoints,
r.Log)
Expand Down Expand Up @@ -145,7 +145,7 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
return reconcile.Result{}, err
}
tctx.Services[serviceNN] = service
if err := resolveServiceEndpoints(tctx, r.Client, serviceNN, r.supportsEndpointSlice, nil); err != nil {
if err := resolveServiceEndpoints(tctx, r.Client, serviceNN, r.SupportsEndpointSlice, nil); err != nil {
return reconcile.Result{}, err
}
}
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/grpcroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type GRPCRouteReconciler struct { //nolint:revive

Updater status.Updater
Readier readiness.ReadinessManager

SupportsEndpointSlice bool // cache capability
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -196,7 +198,7 @@ func (r *GRPCRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
tctx.RouteParentRefs = gr.Spec.ParentRefs
rk := utils.NamespacedNameKind(gr)
for _, gateway := range gateways {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk); err != nil {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk, r.SupportsEndpointSlice); err != nil {
acceptStatus.status = false
acceptStatus.msg = err.Error()
}
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/httproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ type HTTPRouteReconciler struct { //nolint:revive
Updater status.Updater
Readier readiness.ReadinessManager

// supportsEndpointSlice indicates whether the cluster supports EndpointSlice API
supportsEndpointSlice bool
// SupportsEndpointSlice indicates whether the cluster supports EndpointSlice API
SupportsEndpointSlice bool
}

// SetupWithManager sets up the controller with the Manager.
func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.genericEvent = make(chan event.GenericEvent, 100)

// Check and store EndpointSlice API support
r.supportsEndpointSlice = pkgutils.HasAPIResource(mgr, &discoveryv1.EndpointSlice{})
r.SupportsEndpointSlice = pkgutils.HasAPIResource(mgr, &discoveryv1.EndpointSlice{})

eventFilters := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
}

if !r.supportsEndpointSlice {
if !r.SupportsEndpointSlice {
eventFilters = append(eventFilters, predicate.NewPredicateFuncs(TypePredicate[*corev1.Endpoints]()))
}

Expand All @@ -91,7 +91,7 @@ func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
WithEventFilter(predicate.Or(eventFilters...))

// Conditionally watch EndpointSlice or Endpoints based on cluster API support
bdr = watchEndpointSliceOrEndpoints(bdr, r.supportsEndpointSlice,
bdr = watchEndpointSliceOrEndpoints(bdr, r.SupportsEndpointSlice,
r.listHTTPRoutesByServiceRef,
r.listHTTPRoutesByServiceForEndpoints,
r.Log)
Expand Down Expand Up @@ -199,7 +199,7 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
tctx.RouteParentRefs = hr.Spec.ParentRefs
rk := utils.NamespacedNameKind(hr)
for _, gateway := range gateways {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk); err != nil {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk, r.SupportsEndpointSlice); err != nil {
acceptStatus.status = false
acceptStatus.msg = err.Error()
}
Expand Down Expand Up @@ -576,7 +576,7 @@ func (r *HTTPRouteReconciler) processHTTPRouteBackendRefs(tctx *provider.Transla
tctx.Services[targetNN] = &service

// Collect endpoints with EndpointSlice support
if err := resolveServiceEndpoints(tctx, r.Client, targetNN, r.supportsEndpointSlice, nil); err != nil {
if err := resolveServiceEndpoints(tctx, r.Client, targetNN, r.SupportsEndpointSlice, nil); err != nil {
r.Log.Error(err, "failed to collect endpoints", "Service", targetNN)
terr = err
continue
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ type IngressReconciler struct { //nolint:revive
Updater status.Updater
Readier readiness.ReadinessManager

// supportsEndpointSlice indicates whether the cluster supports EndpointSlice API
supportsEndpointSlice bool
// SupportsEndpointSlice indicates whether the cluster supports EndpointSlice API
SupportsEndpointSlice bool
}

// SetupWithManager sets up the controller with the Manager.
func (r *IngressReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.genericEvent = make(chan event.GenericEvent, 100)

// Check and store EndpointSlice API support
r.supportsEndpointSlice = pkgutils.HasAPIResource(mgr, &discoveryv1.EndpointSlice{})
r.SupportsEndpointSlice = pkgutils.HasAPIResource(mgr, &discoveryv1.EndpointSlice{})

eventFilters := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.AnnotationChangedPredicate{},
predicate.NewPredicateFuncs(TypePredicate[*corev1.Secret]()),
}

if !r.supportsEndpointSlice {
if !r.SupportsEndpointSlice {
eventFilters = append(eventFilters, predicate.NewPredicateFuncs(TypePredicate[*corev1.Endpoints]()))
}

Expand All @@ -101,7 +101,7 @@ func (r *IngressReconciler) SetupWithManager(mgr ctrl.Manager) error {
)

// Conditionally watch EndpointSlice or Endpoints based on cluster API support
bdr = watchEndpointSliceOrEndpoints(bdr, r.supportsEndpointSlice,
bdr = watchEndpointSliceOrEndpoints(bdr, r.SupportsEndpointSlice,
r.listIngressesByService,
r.listIngressesByEndpoints,
r.Log)
Expand Down Expand Up @@ -186,7 +186,7 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
})

// process IngressClass parameters if they reference GatewayProxy
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, ingress, ingressClass); err != nil {
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, ingress, ingressClass, r.SupportsEndpointSlice); err != nil {
r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name)
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -640,7 +640,7 @@ func (r *IngressReconciler) processBackendService(tctx *provider.TranslateContex
}

// Collect endpoints with EndpointSlice support
if err := resolveServiceEndpoints(tctx, r.Client, serviceNS, r.supportsEndpointSlice, nil); err != nil {
if err := resolveServiceEndpoints(tctx, r.Client, serviceNS, r.SupportsEndpointSlice, nil); err != nil {
r.Log.Error(err, "failed to collect endpoints", "namespace", namespace, "name", backendService.Name)
return err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/ingressclass_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type IngressClassReconciler struct {
Log logr.Logger

Provider provider.Provider
SupportsEndpointSlice bool // cache capability
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -96,7 +97,7 @@ func (r *IngressClassReconciler) Reconcile(ctx context.Context, req ctrl.Request
// Create a translate context
tctx := provider.NewDefaultTranslateContext(ctx)

if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, ingressClass, ingressClass); err != nil {
if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, ingressClass, ingressClass, r.SupportsEndpointSlice); err != nil {
r.Log.Error(err, "failed to process infrastructure for ingressclass", "ingressclass", ingressClass.GetName())
return ctrl.Result{}, client.IgnoreNotFound(err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/ingressclass_v1beta1_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type IngressClassV1beta1Reconciler struct {
Log logr.Logger

Provider provider.Provider
SupportsEndpointSlice bool // cache capability
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -239,7 +240,7 @@ func (r *IngressClassV1beta1Reconciler) processInfrastructure(tctx *provider.Tra
if err := addProviderEndpointsToTranslateContext(tctx, r.Client, r.Log, types.NamespacedName{
Namespace: gatewayProxy.GetNamespace(),
Name: service.Name,
}); err != nil {
}, r.SupportsEndpointSlice); err != nil {
return err
}
}
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/tcproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type TCPRouteReconciler struct { //nolint:revive

Updater status.Updater
Readier readiness.ReadinessManager

SupportsEndpointSlice bool //cache capability
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -269,7 +271,7 @@ func (r *TCPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
tctx.RouteParentRefs = tr.Spec.ParentRefs
rk := utils.NamespacedNameKind(tr)
for _, gateway := range gateways {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk); err != nil {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk, r.SupportsEndpointSlice); err != nil {
acceptStatus.status = false
acceptStatus.msg = err.Error()
}
Expand Down
5 changes: 4 additions & 1 deletion internal/controller/tlsroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type TLSRouteReconciler struct { //nolint:revive

Updater status.Updater
Readier readiness.ReadinessManager


SupportsEndpointSlice bool
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -269,7 +272,7 @@ func (r *TLSRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
tctx.RouteParentRefs = tr.Spec.ParentRefs
rk := utils.NamespacedNameKind(tr)
for _, gateway := range gateways {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk); err != nil {
if err := ProcessGatewayProxy(r.Client, r.Log, tctx, gateway.Gateway, rk, r.SupportsEndpointSlice); err != nil {
acceptStatus.status = false
acceptStatus.msg = err.Error()
}
Expand Down
Loading