Skip to content

Commit e05bf61

Browse files
committed
fix test
1 parent 6a89a1f commit e05bf61

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed

internal/controller/apisixconsumer_controller.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/go-logr/logr"
2525
corev1 "k8s.io/api/core/v1"
2626
networkingv1 "k8s.io/api/networking/v1"
27+
networkingv1beta1 "k8s.io/api/networking/v1beta1"
2728
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/runtime"
@@ -114,6 +115,14 @@ func (r *ApisixConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Reque
114115

115116
// SetupWithManager sets up the controller with the Manager.
116117
func (r *ApisixConsumerReconciler) SetupWithManager(mgr ctrl.Manager) error {
118+
var icWatch client.Object
119+
switch r.ICGV.String() {
120+
case networkingv1beta1.SchemeGroupVersion.String():
121+
icWatch = &networkingv1beta1.IngressClass{}
122+
default:
123+
icWatch = &networkingv1.IngressClass{}
124+
}
125+
117126
return ctrl.NewControllerManagedBy(mgr).
118127
For(&apiv2.ApisixConsumer{},
119128
builder.WithPredicates(
@@ -127,7 +136,7 @@ func (r *ApisixConsumerReconciler) SetupWithManager(mgr ctrl.Manager) error {
127136
),
128137
).
129138
Watches(
130-
&networkingv1.IngressClass{},
139+
icWatch,
131140
handler.EnqueueRequestsFromMapFunc(r.listApisixConsumerForIngressClass),
132141
builder.WithPredicates(
133142
predicate.NewPredicateFuncs(matchesIngressController),
@@ -153,7 +162,12 @@ func (r *ApisixConsumerReconciler) checkIngressClass(obj client.Object) bool {
153162
}
154163

155164
func (r *ApisixConsumerReconciler) listApisixConsumerForGatewayProxy(ctx context.Context, obj client.Object) []reconcile.Request {
156-
return listIngressClassRequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixConsumerForIngressClass)
165+
switch r.ICGV.String() {
166+
case networkingv1beta1.SchemeGroupVersion.String():
167+
return listIngressClassV1beta1RequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixConsumerForIngressClass)
168+
default:
169+
return listIngressClassRequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixConsumerForIngressClass)
170+
}
157171
}
158172

159173
func (r *ApisixConsumerReconciler) listApisixConsumerForIngressClass(ctx context.Context, obj client.Object) []reconcile.Request {

internal/controller/apisixglobalrule_controller.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/go-logr/logr"
2525
networkingv1 "k8s.io/api/networking/v1"
26+
networkingv1beta1 "k8s.io/api/networking/v1beta1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -127,6 +128,12 @@ func (r *ApisixGlobalRuleReconciler) Reconcile(ctx context.Context, req ctrl.Req
127128

128129
// SetupWithManager sets up the controller with the Manager.
129130
func (r *ApisixGlobalRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
131+
var icWatch client.Object
132+
if r.ICGV.String() == networkingv1beta1.SchemeGroupVersion.String() {
133+
icWatch = &networkingv1beta1.IngressClass{}
134+
} else {
135+
icWatch = &networkingv1.IngressClass{}
136+
}
130137
return ctrl.NewControllerManagedBy(mgr).
131138
For(&apiv2.ApisixGlobalRule{},
132139
builder.WithPredicates(
@@ -140,7 +147,7 @@ func (r *ApisixGlobalRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
140147
),
141148
).
142149
Watches(
143-
&networkingv1.IngressClass{},
150+
icWatch,
144151
handler.EnqueueRequestsFromMapFunc(r.listGlobalRulesForIngressClass),
145152
builder.WithPredicates(
146153
predicate.NewPredicateFuncs(matchesIngressController),
@@ -160,7 +167,7 @@ func (r *ApisixGlobalRuleReconciler) checkIngressClass(obj client.Object) bool {
160167
return false
161168
}
162169

163-
return matchesIngressClass(context.Background(), r.Client, r.Log, globalRule.Spec.IngressClassName, r.ICGV.Version)
170+
return matchesIngressClass(context.Background(), r.Client, r.Log, globalRule.Spec.IngressClassName, r.ICGV.String())
164171
}
165172

166173
// listGlobalRulesForIngressClass list all global rules that use a specific ingress class
@@ -184,7 +191,12 @@ func (r *ApisixGlobalRuleReconciler) listGlobalRulesForIngressClass(ctx context.
184191
}
185192

186193
func (r *ApisixGlobalRuleReconciler) listGlobalRulesForGatewayProxy(ctx context.Context, obj client.Object) []reconcile.Request {
187-
return listIngressClassRequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listGlobalRulesForIngressClass)
194+
switch r.ICGV.String() {
195+
case networkingv1beta1.SchemeGroupVersion.String():
196+
return listIngressClassV1beta1RequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listGlobalRulesForIngressClass)
197+
default:
198+
return listIngressClassRequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listGlobalRulesForIngressClass)
199+
}
188200
}
189201

190202
// updateStatus updates the ApisixGlobalRule status with the given condition

internal/controller/apisixroute_controller.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ type ApisixRouteReconciler struct {
7272
func (r *ApisixRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
7373
// Check and store EndpointSlice API support
7474
r.supportsEndpointSlice = pkgutils.HasAPIResource(mgr, &discoveryv1.EndpointSlice{})
75+
var icWatch client.Object
76+
switch r.ICGV.String() {
77+
case networkingv1beta1.SchemeGroupVersion.String():
78+
icWatch = &networkingv1beta1.IngressClass{}
79+
default:
80+
icWatch = &networkingv1.IngressClass{}
81+
}
7582

7683
bdr := ctrl.NewControllerManagedBy(mgr).
7784
For(&apiv2.ApisixRoute{}).
@@ -84,7 +91,7 @@ func (r *ApisixRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
8491
),
8592
).
8693
Watches(
87-
&networkingv1beta1.IngressClass{},
94+
icWatch,
8895
handler.EnqueueRequestsFromMapFunc(r.listApisixRouteForIngressClass),
8996
builder.WithPredicates(
9097
predicate.NewPredicateFuncs(matchesIngressController),
@@ -587,8 +594,13 @@ func (r *ApisixRouteReconciler) listApisixRouteForIngressClass(ctx context.Conte
587594
)
588595
}
589596

590-
func (r *ApisixRouteReconciler) listApisixRouteForGatewayProxy(ctx context.Context, object client.Object) (requests []reconcile.Request) {
591-
return listIngressClassV1beta1RequestsForGatewayProxy(ctx, r.Client, object, r.Log, r.listApisixRouteForIngressClass)
597+
func (r *ApisixRouteReconciler) listApisixRouteForGatewayProxy(ctx context.Context, obj client.Object) (requests []reconcile.Request) {
598+
switch r.ICGV.String() {
599+
case networkingv1beta1.SchemeGroupVersion.String():
600+
return listIngressClassV1beta1RequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixRouteForIngressClass)
601+
default:
602+
return listIngressClassRequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixRouteForIngressClass)
603+
}
592604
}
593605

594606
func (r *ApisixRouteReconciler) listApisixRouteForApisixUpstream(ctx context.Context, object client.Object) (requests []reconcile.Request) {

internal/controller/apisixtls_controller.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/go-logr/logr"
2525
corev1 "k8s.io/api/core/v1"
2626
networkingv1 "k8s.io/api/networking/v1"
27+
networkingv1beta1 "k8s.io/api/networking/v1beta1"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"k8s.io/apimachinery/pkg/runtime"
2930
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -58,6 +59,13 @@ type ApisixTlsReconciler struct {
5859

5960
// SetupWithManager sets up the controller with the Manager.
6061
func (r *ApisixTlsReconciler) SetupWithManager(mgr ctrl.Manager) error {
62+
var icWatch client.Object
63+
switch r.ICGV.String() {
64+
case networkingv1beta1.SchemeGroupVersion.String():
65+
icWatch = &networkingv1beta1.IngressClass{}
66+
default:
67+
icWatch = &networkingv1.IngressClass{}
68+
}
6169
return ctrl.NewControllerManagedBy(mgr).
6270
For(&apiv2.ApisixTls{},
6371
builder.WithPredicates(
@@ -72,7 +80,7 @@ func (r *ApisixTlsReconciler) SetupWithManager(mgr ctrl.Manager) error {
7280
),
7381
).
7482
Watches(
75-
&networkingv1.IngressClass{},
83+
icWatch,
7684
handler.EnqueueRequestsFromMapFunc(r.listApisixTlsForIngressClass),
7785
builder.WithPredicates(
7886
predicate.NewPredicateFuncs(matchesIngressController),
@@ -284,5 +292,10 @@ func (r *ApisixTlsReconciler) listApisixTlsForIngressClass(ctx context.Context,
284292

285293
// listApisixTlsForGatewayProxy list all TLS that use a specific gateway proxy
286294
func (r *ApisixTlsReconciler) listApisixTlsForGatewayProxy(ctx context.Context, obj client.Object) []reconcile.Request {
287-
return listIngressClassRequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixTlsForIngressClass)
295+
switch r.ICGV.String() {
296+
case networkingv1beta1.SchemeGroupVersion.String():
297+
return listIngressClassV1beta1RequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixTlsForIngressClass)
298+
default:
299+
return listIngressClassRequestsForGatewayProxy(ctx, r.Client, obj, r.Log, r.listApisixTlsForIngressClass)
300+
}
288301
}

0 commit comments

Comments
 (0)