@@ -21,25 +21,39 @@ import (
2121
2222 "github.com/stretchr/testify/require"
2323 corev1 "k8s.io/api/core/v1"
24+ networkingv1 "k8s.io/api/networking/v1"
2425 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526 "k8s.io/apimachinery/pkg/runtime"
2627 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2728 "sigs.k8s.io/controller-runtime/pkg/client/fake"
2829
2930 apisixv2 "github.com/apache/apisix-ingress-controller/api/v2"
31+ "github.com/apache/apisix-ingress-controller/internal/controller/config"
3032)
3133
3234func buildApisixRouteValidator (t * testing.T , objects ... runtime.Object ) * ApisixRouteCustomValidator {
3335 t .Helper ()
3436
3537 scheme := runtime .NewScheme ()
3638 require .NoError (t , clientgoscheme .AddToScheme (scheme ))
39+ require .NoError (t , networkingv1 .AddToScheme (scheme ))
3740 require .NoError (t , apisixv2 .AddToScheme (scheme ))
3841
39- builder := fake .NewClientBuilder ().WithScheme (scheme )
40- if len (objects ) > 0 {
41- builder = builder .WithRuntimeObjects (objects ... )
42+ managed := []runtime.Object {
43+ & networkingv1.IngressClass {
44+ ObjectMeta : metav1.ObjectMeta {
45+ Name : "apisix" ,
46+ Annotations : map [string ]string {
47+ "ingressclass.kubernetes.io/is-default-class" : "true" ,
48+ },
49+ },
50+ Spec : networkingv1.IngressClassSpec {
51+ Controller : config .ControllerConfig .ControllerName ,
52+ },
53+ },
4254 }
55+ allObjects := append (managed , objects ... )
56+ builder := fake .NewClientBuilder ().WithScheme (scheme ).WithRuntimeObjects (allObjects ... )
4357
4458 return NewApisixRouteCustomValidator (builder .Build ())
4559}
@@ -51,6 +65,7 @@ func TestApisixRouteValidator_MissingHTTPService(t *testing.T) {
5165 Namespace : "default" ,
5266 },
5367 Spec : apisixv2.ApisixRouteSpec {
68+ IngressClassName : "apisix" ,
5469 HTTP : []apisixv2.ApisixRouteHTTP {{
5570 Name : "rule" ,
5671 Backends : []apisixv2.ApisixRouteHTTPBackend {{
@@ -75,6 +90,7 @@ func TestApisixRouteValidator_MissingPluginSecret(t *testing.T) {
7590 Namespace : "default" ,
7691 },
7792 Spec : apisixv2.ApisixRouteSpec {
93+ IngressClassName : "apisix" ,
7894 HTTP : []apisixv2.ApisixRouteHTTP {{
7995 Name : "rule" ,
8096 Backends : []apisixv2.ApisixRouteHTTPBackend {{
@@ -106,6 +122,7 @@ func TestApisixRouteValidator_MissingStreamService(t *testing.T) {
106122 Namespace : "default" ,
107123 },
108124 Spec : apisixv2.ApisixRouteSpec {
125+ IngressClassName : "apisix" ,
109126 Stream : []apisixv2.ApisixRouteStream {{
110127 Name : "stream" ,
111128 Protocol : "TCP" ,
@@ -131,6 +148,7 @@ func TestApisixRouteValidator_NoWarnings(t *testing.T) {
131148 Namespace : "default" ,
132149 },
133150 Spec : apisixv2.ApisixRouteSpec {
151+ IngressClassName : "apisix" ,
134152 HTTP : []apisixv2.ApisixRouteHTTP {{
135153 Name : "rule" ,
136154 Backends : []apisixv2.ApisixRouteHTTPBackend {{
0 commit comments