Skip to content

Commit a9c5209

Browse files
committed
fix: only watch L4RoutePolicy when its CRD is installed
The TCP/UDP/TLSRoute controllers watched L4RoutePolicy unconditionally, so upgrading the controller without applying the new CRD made the manager fail to start (the informer cannot be created for a missing kind), taking down all routing. Guard the watch with HasAPIResource so the controller starts without the CRD and enables L4RoutePolicy once it is installed and the pod restarts, matching how optional resources like EndpointSlice are handled.
1 parent d9a46f0 commit a9c5209

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

internal/controller/tcproute_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/apache/apisix-ingress-controller/internal/provider"
4646
"github.com/apache/apisix-ingress-controller/internal/types"
4747
"github.com/apache/apisix-ingress-controller/internal/utils"
48+
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
4849
)
4950

5051
// TCPRouteReconciler reconciles a TCPRoute object.
@@ -93,10 +94,15 @@ func (r *TCPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
9394
).
9495
Watches(&v1alpha1.GatewayProxy{},
9596
handler.EnqueueRequestsFromMapFunc(r.listTCPRoutesForGatewayProxy),
96-
).
97-
Watches(&v1alpha1.L4RoutePolicy{},
97+
)
98+
99+
// L4RoutePolicy is an optional CRD. Only watch it when installed so the
100+
// controller still starts if the CRD has not been applied yet (e.g. upgrades).
101+
if pkgutils.HasAPIResource(mgr, &v1alpha1.L4RoutePolicy{}) {
102+
bdr.Watches(&v1alpha1.L4RoutePolicy{},
98103
handler.EnqueueRequestsFromMapFunc(r.listTCPRoutesForL4RoutePolicy),
99104
)
105+
}
100106

101107
if GetEnableReferenceGrant() {
102108
bdr.Watches(&v1beta1.ReferenceGrant{},

internal/controller/tlsroute_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/apache/apisix-ingress-controller/internal/provider"
4646
"github.com/apache/apisix-ingress-controller/internal/types"
4747
"github.com/apache/apisix-ingress-controller/internal/utils"
48+
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
4849
)
4950

5051
// TLSRouteReconciler reconciles a TLSRoute object.
@@ -93,10 +94,15 @@ func (r *TLSRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
9394
).
9495
Watches(&v1alpha1.GatewayProxy{},
9596
handler.EnqueueRequestsFromMapFunc(r.listTLSRoutesForGatewayProxy),
96-
).
97-
Watches(&v1alpha1.L4RoutePolicy{},
97+
)
98+
99+
// L4RoutePolicy is an optional CRD. Only watch it when installed so the
100+
// controller still starts if the CRD has not been applied yet (e.g. upgrades).
101+
if pkgutils.HasAPIResource(mgr, &v1alpha1.L4RoutePolicy{}) {
102+
bdr.Watches(&v1alpha1.L4RoutePolicy{},
98103
handler.EnqueueRequestsFromMapFunc(r.listTLSRoutesForL4RoutePolicy),
99104
)
105+
}
100106

101107
if GetEnableReferenceGrant() {
102108
bdr.Watches(&v1beta1.ReferenceGrant{},

internal/controller/udproute_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/apache/apisix-ingress-controller/internal/provider"
4646
"github.com/apache/apisix-ingress-controller/internal/types"
4747
"github.com/apache/apisix-ingress-controller/internal/utils"
48+
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
4849
)
4950

5051
// UDPRouteReconciler reconciles a UDPRoute object.
@@ -93,10 +94,15 @@ func (r *UDPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
9394
).
9495
Watches(&v1alpha1.GatewayProxy{},
9596
handler.EnqueueRequestsFromMapFunc(r.listUDPRoutesForGatewayProxy),
96-
).
97-
Watches(&v1alpha1.L4RoutePolicy{},
97+
)
98+
99+
// L4RoutePolicy is an optional CRD. Only watch it when installed so the
100+
// controller still starts if the CRD has not been applied yet (e.g. upgrades).
101+
if pkgutils.HasAPIResource(mgr, &v1alpha1.L4RoutePolicy{}) {
102+
bdr.Watches(&v1alpha1.L4RoutePolicy{},
98103
handler.EnqueueRequestsFromMapFunc(r.listUDPRoutesForL4RoutePolicy),
99104
)
105+
}
100106

101107
if GetEnableReferenceGrant() {
102108
bdr.Watches(&v1beta1.ReferenceGrant{},

0 commit comments

Comments
 (0)