Skip to content

Commit 67cbfa8

Browse files
committed
Improve error handling across kong & ingress-nginx
1 parent 6dc297a commit 67cbfa8

6 files changed

Lines changed: 20 additions & 10 deletions

File tree

pkg/i2gw/providers/common/converter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ func toHTTPRouteMatch(routePath networkingv1.HTTPIngressPath, path *field.Path,
362362
pmExact := gatewayv1.PathMatchExact
363363

364364
match := &gatewayv1.HTTPRouteMatch{Path: &gatewayv1.HTTPPathMatch{Value: &routePath.Path}}
365+
366+
if routePath.PathType == nil {
367+
return nil, field.Invalid(path.Child("pathType"), routePath.PathType, "pathType is required")
368+
}
369+
365370
switch *routePath.PathType {
366371
case networkingv1.PathTypePrefix:
367372
match.Path.Type = &pmPrefix

pkg/i2gw/providers/ingressnginx/canary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func canaryFeature(ingressResources i2gw.InputResources, gatewayResources *i2gw.
4747
key := types.NamespacedName{Namespace: path.ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
4848
httpRoute, ok := gatewayResources.HTTPRoutes[key]
4949
if !ok {
50-
panic("HTTPRoute not exists - this should never happen")
50+
return field.ErrorList{field.InternalError(nil, fmt.Errorf("HTTPRoute does not exist"))}
5151
}
5252

5353
patchHTTPRouteWithBackendRefs(&httpRoute, backendRefs)

pkg/i2gw/providers/kong/converter.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,35 @@ func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.Erro
5151
ingressList = append(ingressList, *ingress)
5252
}
5353

54-
globalErrs := field.ErrorList{}
54+
errorList := field.ErrorList{}
5555

5656
// Convert plain ingress resources to gateway resources, ignoring all
5757
// provider-specific features.
5858
gatewayResources, errs := common.ToGateway(ingressList, c.implementationSpecificOptions)
5959
if len(errs) > 0 {
60-
globalErrs = append(globalErrs, errs...)
60+
errorList = append(errorList, errs...)
6161
}
6262

6363
tcpGatewayResources, errs := crds.TCPIngressToGatewayAPI(storage.TCPIngresses)
6464
if len(errs) > 0 {
65-
globalErrs = append(globalErrs, errs...)
65+
errorList = append(errorList, errs...)
66+
}
67+
68+
if len(errorList) > 0 {
69+
return i2gw.GatewayResources{}, errorList
6670
}
6771

6872
gatewayResources, errs = i2gw.MergeGatewayResources(gatewayResources, tcpGatewayResources)
6973
if len(errs) > 0 {
70-
globalErrs = append(globalErrs, errs...)
74+
return i2gw.GatewayResources{}, errs
7175
}
7276

7377
for _, parseFeatureFunc := range c.featureParsers {
7478
// Apply the feature parsing function to the gateway resources, one by one.
7579
errs = parseFeatureFunc(i2gw.InputResources{Ingresses: ingressList}, &gatewayResources)
7680
// Append the parsing errors to the error list.
77-
globalErrs = append(globalErrs, errs...)
81+
errorList = append(errorList, errs...)
7882
}
7983

80-
return gatewayResources, globalErrs
84+
return gatewayResources, errorList
8185
}

pkg/i2gw/providers/kong/header_matching.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func headerMatchingFeature(ingressResources i2gw.InputResources, gatewayResource
4444
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
4545
httpRoute, ok := gatewayResources.HTTPRoutes[key]
4646
if !ok {
47-
panic("HTTPRoute does not exist - this should never happen")
47+
return field.ErrorList{field.InternalError(nil, fmt.Errorf("HTTPRoute does not exist"))}
4848
}
4949

5050
patchHTTPRouteHeaderMatching(&httpRoute, headerskeys, headersValues)

pkg/i2gw/providers/kong/method_matching.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func methodMatchingFeature(ingressResources i2gw.InputResources, gatewayResource
4242
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
4343
httpRoute, ok := gatewayResources.HTTPRoutes[key]
4444
if !ok {
45-
panic("HTTPRoute does not exist - this should never happen")
45+
return field.ErrorList{field.InternalError(nil, fmt.Errorf("HTTPRoute does not exist"))}
4646
}
4747
methods, errs := parseMethodsAnnotation(rule.Ingress.ObjectMeta.Namespace, rule.Ingress.ObjectMeta.Name, rule.Ingress.Annotations)
4848
if len(errs) != 0 {

pkg/i2gw/providers/kong/plugins.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package kong
1818

1919
import (
20+
"errors"
2021
"strings"
2122

2223
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
@@ -39,7 +40,7 @@ func pluginsFeature(ingressResources i2gw.InputResources, gatewayResources *i2gw
3940
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
4041
httpRoute, ok := gatewayResources.HTTPRoutes[key]
4142
if !ok {
42-
panic("HTTPRoute does not exist - this should never happen")
43+
return field.ErrorList{field.InternalError(nil, errors.New("HTTPRoute does not exist"))}
4344
}
4445
filters := parsePluginsAnnotation(rule.Ingress.Annotations)
4546
patchHTTPRoutePlugins(&httpRoute, filters)

0 commit comments

Comments
 (0)