@@ -36,11 +36,6 @@ func ValidateHTTPRoute(
36
36
httproute * gatewayapi.HTTPRoute ,
37
37
managerClient client.Client ,
38
38
) (bool , string , error ) {
39
- // Validate that the route has valid parentRefs.
40
- if err := ValidateHTTPRouteParentRefs (httproute ); err != nil {
41
- return false , fmt .Sprintf ("HTTPRoute has invalid parentRefs: %s" , err ), nil
42
- }
43
-
44
39
// Check if route is managed by this controller. If not, we don't need to validate it.
45
40
routeIsManaged , err := ensureHTTPRouteIsManagedByController (ctx , httproute , managerClient )
46
41
if err != nil {
@@ -74,30 +69,25 @@ func ValidateHTTPRoute(
74
69
// Validation - HTTPRoute - Private Functions
75
70
// -----------------------------------------------------------------------------
76
71
77
- // ValidateHTTPRouteParentRefs checks the group/kind of each parentRef in spec and allows only
78
- // empty or `gateway.networking.k8s.io.Gateway`.
79
- func ValidateHTTPRouteParentRefs (httproute * gatewayapi.HTTPRoute ) error {
72
+ // parentRefIsGateway returns true if the group/kind of ParentReference is empty or gateway.networking.k8s.io/Gateway.
73
+ func parentRefIsGateway (parentRef gatewayapi.ParentReference ) bool {
80
74
const KindGateway = gatewayapi .Kind ("Gateway" )
81
75
82
- for parentRefIndex , parentRef := range httproute .Spec .ParentRefs {
83
- if parentRef .Group != nil && * parentRef .Group != "" && * parentRef .Group != gatewayapi .V1Group {
84
- return fmt .Errorf ("parentRefs[%d]: %s is not a supported group for httproute parentRefs, only %s is supported" ,
85
- parentRefIndex , * parentRef .Group , gatewayapi .V1Group )
86
- }
87
- if parentRef .Kind != nil && * parentRef .Kind != "" && * parentRef .Kind != KindGateway {
88
- return fmt .Errorf ("parentRefs[%d]: %s is not a supported kind for httproute parentRefs, only kind %s is supported" ,
89
- parentRefIndex , * parentRef .Kind , KindGateway )
90
- }
91
- }
92
-
93
- return nil
76
+ return (parentRef .Group == nil || (* parentRef .Group == "" || * parentRef .Group == gatewayapi .V1Group )) &&
77
+ (parentRef .Kind == nil || (* parentRef .Kind == "" || * parentRef .Kind == KindGateway ))
94
78
}
95
79
96
80
// ensureHTTPRouteIsManagedByController checks whether the provided HTTPRoute is managed by this controller implementation.
97
81
func ensureHTTPRouteIsManagedByController (ctx context.Context , httproute * gatewayapi.HTTPRoute , managerClient client.Client ) (bool , error ) {
98
82
// In order to be sure whether an HTTPRoute resource is managed by this
99
83
// controller we ignore references to Gateway resources that do not exist.
100
84
for _ , parentRef := range httproute .Spec .ParentRefs {
85
+ // Skip the parentRefs that are not Gateways because they cannot refer to the controller.
86
+ // https://github.com/Kong/kubernetes-ingress-controller/issues/5912
87
+ if ! parentRefIsGateway (parentRef ) {
88
+ continue
89
+ }
90
+
101
91
// Determine the namespace of the gateway referenced via parentRef. If no
102
92
// explicit namespace is provided, assume the namespace of the route.
103
93
namespace := httproute .Namespace
0 commit comments