diff --git a/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml b/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml index 042feaaf8..44ea6d964 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml @@ -57,6 +57,7 @@ spec: description: |- Kind defines the kind of the route. Rule is the only supported kind. + If not defined, defaults to Rule. enum: - Rule type: string @@ -280,7 +281,6 @@ spec: More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax type: string required: - - kind - match type: object type: array diff --git a/docs/content/reference/dynamic-configuration/traefik.io_ingressroutes.yaml b/docs/content/reference/dynamic-configuration/traefik.io_ingressroutes.yaml index ccb374a94..cc41ee18c 100644 --- a/docs/content/reference/dynamic-configuration/traefik.io_ingressroutes.yaml +++ b/docs/content/reference/dynamic-configuration/traefik.io_ingressroutes.yaml @@ -57,6 +57,7 @@ spec: description: |- Kind defines the kind of the route. Rule is the only supported kind. + If not defined, defaults to Rule. enum: - Rule type: string @@ -280,7 +281,6 @@ spec: More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax type: string required: - - kind - match type: object type: array diff --git a/integration/fixtures/k8s/01-traefik-crd.yml b/integration/fixtures/k8s/01-traefik-crd.yml index 042feaaf8..44ea6d964 100644 --- a/integration/fixtures/k8s/01-traefik-crd.yml +++ b/integration/fixtures/k8s/01-traefik-crd.yml @@ -57,6 +57,7 @@ spec: description: |- Kind defines the kind of the route. Rule is the only supported kind. + If not defined, defaults to Rule. enum: - Rule type: string @@ -280,7 +281,6 @@ spec: More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#rulesyntax type: string required: - - kind - match type: object type: array diff --git a/pkg/provider/kubernetes/crd/fixtures/with_wrong_rule_kind.yml b/pkg/provider/kubernetes/crd/fixtures/with_empty_rule_kind.yml similarity index 100% rename from pkg/provider/kubernetes/crd/fixtures/with_wrong_rule_kind.yml rename to pkg/provider/kubernetes/crd/fixtures/with_empty_rule_kind.yml diff --git a/pkg/provider/kubernetes/crd/kubernetes_http.go b/pkg/provider/kubernetes/crd/kubernetes_http.go index 8f00ec238..c0faaddbf 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_http.go +++ b/pkg/provider/kubernetes/crd/kubernetes_http.go @@ -60,7 +60,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli } 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) continue } diff --git a/pkg/provider/kubernetes/crd/kubernetes_test.go b/pkg/provider/kubernetes/crd/kubernetes_test.go index b433662ae..e25357f51 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_test.go +++ b/pkg/provider/kubernetes/crd/kubernetes_test.go @@ -3114,8 +3114,8 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, { - desc: "Route with kind not of a rule type (empty kind) is ignored", - paths: []string{"services.yml", "with_wrong_rule_kind.yml"}, + desc: "Route with empty kind is allowed", + paths: []string{"services.yml", "with_empty_rule_kind.yml"}, expected: &dynamic.Configuration{ UDP: &dynamic.UDPConfiguration{ Routers: map[string]*dynamic.UDPRouter{}, @@ -3129,9 +3129,33 @@ func TestLoadIngressRoutes(t *testing.T) { ServersTransports: map[string]*dynamic.TCPServersTransport{}, }, HTTP: &dynamic.HTTPConfiguration{ - Routers: map[string]*dynamic.Router{}, - Middlewares: map[string]*dynamic.Middleware{}, - Services: map[string]*dynamic.Service{}, + Routers: map[string]*dynamic.Router{ + "default-test-route-02719a68b11e915a4b23": { + 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{}, }, }, diff --git a/pkg/provider/kubernetes/crd/traefikio/v1alpha1/ingressroute.go b/pkg/provider/kubernetes/crd/traefikio/v1alpha1/ingressroute.go index 1eef3a6eb..7e686562e 100644 --- a/pkg/provider/kubernetes/crd/traefikio/v1alpha1/ingressroute.go +++ b/pkg/provider/kubernetes/crd/traefikio/v1alpha1/ingressroute.go @@ -28,8 +28,9 @@ type Route struct { Match string `json:"match"` // Kind defines the kind of the route. // Rule is the only supported kind. + // If not defined, defaults to Rule. // +kubebuilder:validation:Enum=Rule - Kind string `json:"kind"` + Kind string `json:"kind,omitempty"` // Priority defines the router's priority. // More info: https://doc.traefik.io/traefik/v3.2/routing/routers/#priority Priority int `json:"priority,omitempty"`