@@ -16,6 +16,7 @@ func buildTLSRoute(
16
16
gatewayNsNames []types.NamespacedName ,
17
17
services map [types.NamespacedName ]* apiv1.Service ,
18
18
npCfg * NginxProxy ,
19
+ refGrantResolver func (resource toResource ) bool ,
19
20
) * L4Route {
20
21
r := & L4Route {
21
22
Source : gtr ,
@@ -53,15 +54,14 @@ func buildTLSRoute(
53
54
return r
54
55
}
55
56
56
- cond , br := validateBackendRefTLSRoute (gtr , services , npCfg )
57
+ br , cond := validateBackendRefTLSRoute (gtr , services , npCfg , refGrantResolver )
57
58
58
59
r .Spec .BackendRef = br
59
60
r .Valid = true
60
61
r .Attachable = true
61
62
62
63
if cond != nil {
63
64
r .Conditions = append (r .Conditions , * cond )
64
- r .Valid = false
65
65
}
66
66
67
67
return r
@@ -70,12 +70,26 @@ func buildTLSRoute(
70
70
func validateBackendRefTLSRoute (gtr * v1alpha2.TLSRoute ,
71
71
services map [types.NamespacedName ]* apiv1.Service ,
72
72
npCfg * NginxProxy ,
73
- ) (* conditions.Condition , BackendRef ) {
73
+ refGrantResolver func (resource toResource ) bool ,
74
+ ) (BackendRef , * conditions.Condition ) {
74
75
// Length of BackendRefs and Rules is guaranteed to be one due to earlier check in buildTLSRoute
75
76
refPath := field .NewPath ("spec" ).Child ("rules" ).Index (0 ).Child ("backendRefs" ).Index (0 )
76
77
77
78
ref := gtr .Spec .Rules [0 ].BackendRefs [0 ]
78
79
80
+ if valid , cond := validateBackendRef (
81
+ ref ,
82
+ gtr .Namespace ,
83
+ refGrantResolver ,
84
+ refPath ,
85
+ ); ! valid {
86
+ backendRef := BackendRef {
87
+ Valid : false ,
88
+ }
89
+
90
+ return backendRef , & cond
91
+ }
92
+
79
93
ns := gtr .Namespace
80
94
if ref .Namespace != nil {
81
95
ns = string (* ref .Namespace )
@@ -86,48 +100,30 @@ func validateBackendRefTLSRoute(gtr *v1alpha2.TLSRoute,
86
100
Name : string (gtr .Spec .Rules [0 ].BackendRefs [0 ].Name ),
87
101
}
88
102
89
- backendRef := BackendRef {
90
- Valid : true ,
91
- }
92
- var cond * conditions.Condition
93
-
94
- if ref .Port == nil {
95
- valErr := field .Required (refPath .Child ("port" ), "port cannot be nil" )
96
- backendRef .Valid = false
97
- cond = helpers .GetPointer (staticConds .NewRouteBackendRefUnsupportedValue (valErr .Error ()))
98
-
99
- return cond , backendRef
100
- }
101
-
102
103
svcIPFamily , svcPort , err := getIPFamilyAndPortFromRef (
103
104
ref ,
104
105
svcNsName ,
105
106
services ,
106
107
refPath ,
107
108
)
108
109
109
- backendRef .ServicePort = svcPort
110
- backendRef .SvcNsName = svcNsName
110
+ backendRef := BackendRef {
111
+ SvcNsName : svcNsName ,
112
+ ServicePort : svcPort ,
113
+ Valid : true ,
114
+ }
111
115
112
116
if err != nil {
113
117
backendRef .Valid = false
114
- cond = helpers .GetPointer (staticConds .NewRouteBackendRefRefBackendNotFound (err .Error ()))
115
- } else if err := verifyIPFamily (npCfg , svcIPFamily ); err != nil {
116
- backendRef .Valid = false
117
- cond = helpers .GetPointer (staticConds .NewRouteInvalidIPFamily (err .Error ()))
118
- } else if ref .Group != nil && ! (* ref .Group == "core" || * ref .Group == "" ) {
119
- valErr := field .NotSupported (refPath .Child ("group" ), * ref .Group , []string {"core" , "" })
120
- backendRef .Valid = false
121
- cond = helpers .GetPointer (staticConds .NewRouteBackendRefInvalidKind (valErr .Error ()))
122
- } else if ref .Kind != nil && * ref .Kind != "Service" {
123
- valErr := field .NotSupported (refPath .Child ("kind" ), * ref .Kind , []string {"Service" })
124
- backendRef .Valid = false
125
- cond = helpers .GetPointer (staticConds .NewRouteBackendRefInvalidKind (valErr .Error ()))
126
- } else if ref .Namespace != nil && string (* ref .Namespace ) != gtr .Namespace {
127
- msg := "Cross-namespace routing is not supported"
118
+
119
+ return backendRef , helpers .GetPointer (staticConds .NewRouteBackendRefRefBackendNotFound (err .Error ()))
120
+ }
121
+
122
+ if err := verifyIPFamily (npCfg , svcIPFamily ); err != nil {
128
123
backendRef .Valid = false
129
- cond = helpers .GetPointer (staticConds .NewRouteBackendRefUnsupportedValue (msg ))
124
+
125
+ return backendRef , helpers .GetPointer (staticConds .NewRouteInvalidIPFamily (err .Error ()))
130
126
}
131
- // FIXME(sarthyparty): Add check for invalid weights, we removed checks to pass the conformance test
132
- return cond , backendRef
127
+
128
+ return backendRef , nil
133
129
}
0 commit comments