Make the IngressRoute kind optional

This commit is contained in:
Shreyas Kirtane 2024-11-04 08:26:04 -07:00 committed by GitHub
parent e8ff825ed2
commit 97caf758ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 35 additions and 10 deletions

View file

@ -57,6 +57,7 @@ spec:
description: |- description: |-
Kind defines the kind of the route. Kind defines the kind of the route.
Rule is the only supported kind. Rule is the only supported kind.
If not defined, defaults to Rule.
enum: enum:
- Rule - Rule
type: string type: string
@ -280,7 +281,6 @@ spec:
More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax
type: string type: string
required: required:
- kind
- match - match
type: object type: object
type: array type: array

View file

@ -57,6 +57,7 @@ spec:
description: |- description: |-
Kind defines the kind of the route. Kind defines the kind of the route.
Rule is the only supported kind. Rule is the only supported kind.
If not defined, defaults to Rule.
enum: enum:
- Rule - Rule
type: string type: string
@ -280,7 +281,6 @@ spec:
More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax
type: string type: string
required: required:
- kind
- match - match
type: object type: object
type: array type: array

View file

@ -57,6 +57,7 @@ spec:
description: |- description: |-
Kind defines the kind of the route. Kind defines the kind of the route.
Rule is the only supported kind. Rule is the only supported kind.
If not defined, defaults to Rule.
enum: enum:
- Rule - Rule
type: string type: string
@ -280,7 +281,6 @@ spec:
More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax
type: string type: string
required: required:
- kind
- match - match
type: object type: object
type: array type: array

View file

@ -60,7 +60,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
} }
for _, route := range ingressRoute.Spec.Routes { for _, route := range ingressRoute.Spec.Routes {
if route.Kind != "Rule" { if len(route.Kind) > 0 && route.Kind != "Rule" {
logger.Error().Msgf("Unsupported match kind: %s. Only \"Rule\" is supported for now.", route.Kind) logger.Error().Msgf("Unsupported match kind: %s. Only \"Rule\" is supported for now.", route.Kind)
continue continue
} }

View file

@ -3114,8 +3114,8 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
}, },
{ {
desc: "Route with kind not of a rule type (empty kind) is ignored", desc: "Route with empty kind is allowed",
paths: []string{"services.yml", "with_wrong_rule_kind.yml"}, paths: []string{"services.yml", "with_empty_rule_kind.yml"},
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{}, Routers: map[string]*dynamic.UDPRouter{},
@ -3129,9 +3129,33 @@ func TestLoadIngressRoutes(t *testing.T) {
ServersTransports: map[string]*dynamic.TCPServersTransport{}, ServersTransports: map[string]*dynamic.TCPServersTransport{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{}, Routers: map[string]*dynamic.Router{
Middlewares: map[string]*dynamic.Middleware{}, "default-test-route-02719a68b11e915a4b23": {
Services: map[string]*dynamic.Service{}, EntryPoints: []string{"web"},
Service: "default-test-route-02719a68b11e915a4b23",
Rule: "/prefix",
Priority: 12,
},
},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"default-test-route-02719a68b11e915a4b23": {
LoadBalancer: &dynamic.ServersLoadBalancer{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
},
},
PassHostHeader: Bool(true),
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
},
},
},
ServersTransports: map[string]*dynamic.ServersTransport{}, ServersTransports: map[string]*dynamic.ServersTransport{},
}, },
}, },

View file

@ -28,8 +28,9 @@ type Route struct {
Match string `json:"match"` Match string `json:"match"`
// Kind defines the kind of the route. // Kind defines the kind of the route.
// Rule is the only supported kind. // Rule is the only supported kind.
// If not defined, defaults to Rule.
// +kubebuilder:validation:Enum=Rule // +kubebuilder:validation:Enum=Rule
Kind string `json:"kind"` Kind string `json:"kind,omitempty"`
// Priority defines the router's priority. // Priority defines the router's priority.
// More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#priority // More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#priority
Priority int `json:"priority,omitempty"` Priority int `json:"priority,omitempty"`