Skip to content

Commit 19b3434

Browse files
authored
feat: support skip gatewayapi v1alpha2 (#387)
1 parent f742479 commit 19b3434

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

internal/controller/consumer_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/apache/apisix-ingress-controller/internal/provider"
4545
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
4646
"github.com/apache/apisix-ingress-controller/internal/utils"
47+
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
4748
)
4849

4950
// ConsumerReconciler reconciles a Gateway object.
@@ -60,6 +61,10 @@ type ConsumerReconciler struct { //nolint:revive
6061

6162
// SetupWithManager sets up the controller with the Manager.
6263
func (r *ConsumerReconciler) SetupWithManager(mgr ctrl.Manager) error {
64+
if config.ControllerConfig.DisableGatewayAPI || !pkgutils.HasAPIResource(mgr, &gatewayv1.Gateway{}) {
65+
r.Log.Info("skipping Consumer controller setup as Gateway API is not available")
66+
return nil
67+
}
6368
return ctrl.NewControllerManagedBy(mgr).
6469
For(&v1alpha1.Consumer{},
6570
builder.WithPredicates(

internal/controller/gateway_controller.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/apache/apisix-ingress-controller/internal/provider"
4444
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
4545
"github.com/apache/apisix-ingress-controller/internal/utils"
46+
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
4647
)
4748

4849
// GatewayReconciler reconciles a Gateway object.
@@ -83,18 +84,6 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
8384
&gatewayv1.GRPCRoute{},
8485
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
8586
).
86-
Watches(
87-
&gatewayv1alpha2.TCPRoute{},
88-
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
89-
).
90-
Watches(
91-
&gatewayv1alpha2.TLSRoute{},
92-
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
93-
).
94-
Watches(
95-
&gatewayv1alpha2.UDPRoute{},
96-
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
97-
).
9887
Watches(
9988
&v1alpha1.GatewayProxy{},
10089
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForGatewayProxy),
@@ -110,6 +99,24 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
11099
builder.WithPredicates(referenceGrantPredicates(KindGateway)),
111100
)
112101
}
102+
if pkgutils.HasAPIResource(mgr, &gatewayv1alpha2.TCPRoute{}) {
103+
bdr.Watches(
104+
&gatewayv1alpha2.TCPRoute{},
105+
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
106+
)
107+
}
108+
if pkgutils.HasAPIResource(mgr, &gatewayv1alpha2.TLSRoute{}) {
109+
bdr.Watches(
110+
&gatewayv1alpha2.TLSRoute{},
111+
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
112+
)
113+
}
114+
if pkgutils.HasAPIResource(mgr, &gatewayv1alpha2.UDPRoute{}) {
115+
bdr.Watches(
116+
&gatewayv1alpha2.UDPRoute{},
117+
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
118+
)
119+
}
113120

114121
return bdr.Complete(r)
115122
}

0 commit comments

Comments
 (0)