Support invalid HTTPRoute status

Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
Kevin Pollet 2024-05-22 17:20:04 +02:00 committed by GitHub
parent 7fdb1ff8af
commit 0e215f9b61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 361 additions and 297 deletions

View file

@ -205,7 +205,6 @@ func (s *K8sConformanceSuite) TestK8sGatewayAPIConformance() {
tests.GatewayInvalidTLSConfiguration.ShortName, tests.GatewayInvalidTLSConfiguration.ShortName,
tests.HTTPRouteHostnameIntersection.ShortName, tests.HTTPRouteHostnameIntersection.ShortName,
tests.HTTPRouteListenerHostnameMatching.ShortName, tests.HTTPRouteListenerHostnameMatching.ShortName,
tests.HTTPRouteInvalidNonExistentBackendRef.ShortName,
tests.HTTPRouteInvalidReferenceGrant.ShortName, tests.HTTPRouteInvalidReferenceGrant.ShortName,
tests.HTTPRouteInvalidCrossNamespaceParentRef.ShortName, tests.HTTPRouteInvalidCrossNamespaceParentRef.ShortName,
tests.HTTPRouteInvalidParentRefNotMatchingSectionName.ShortName, tests.HTTPRouteInvalidParentRefNotMatchingSectionName.ShortName,
@ -213,7 +212,6 @@ func (s *K8sConformanceSuite) TestK8sGatewayAPIConformance() {
tests.HTTPRouteMatchingAcrossRoutes.ShortName, tests.HTTPRouteMatchingAcrossRoutes.ShortName,
tests.HTTPRoutePartiallyInvalidViaInvalidReferenceGrant.ShortName, tests.HTTPRoutePartiallyInvalidViaInvalidReferenceGrant.ShortName,
tests.HTTPRouteRedirectHostAndStatus.ShortName, tests.HTTPRouteRedirectHostAndStatus.ShortName,
tests.HTTPRouteInvalidBackendRefUnknownKind.ShortName,
tests.HTTPRoutePathMatchOrder.ShortName, tests.HTTPRoutePathMatchOrder.ShortName,
tests.HTTPRouteHeaderMatching.ShortName, tests.HTTPRouteHeaderMatching.ShortName,
tests.HTTPRouteReferenceGrant.ShortName, tests.HTTPRouteReferenceGrant.ShortName,

View file

@ -128,6 +128,10 @@ type WeightedRoundRobin struct {
type WRRService struct { type WRRService struct {
Name string `json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" export:"true"` Name string `json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" export:"true"`
Weight *int `json:"weight,omitempty" toml:"weight,omitempty" yaml:"weight,omitempty" export:"true"` Weight *int `json:"weight,omitempty" toml:"weight,omitempty" yaml:"weight,omitempty" export:"true"`
// Status defines an HTTP status code that should be returned when calling the service.
// This is required by the Gateway API implementation which expects specific HTTP status to be returned.
Status *int `json:"-" toml:"-" yaml:"-" label:"-" file:"-"`
} }
// SetDefaults Default values for a WRRService. // SetDefaults Default values for a WRRService.

View file

@ -2187,6 +2187,11 @@ func (in *WRRService) DeepCopyInto(out *WRRService) {
*out = new(int) *out = new(int)
**out = **in **out = **in
} }
if in.Status != nil {
in, out := &in.Status, &out.Status
*out = new(int)
**out = **in
}
return return
} }

View file

@ -38,7 +38,7 @@ spec:
rules: rules:
- matches: - matches:
- path: - path:
type: PathPrefix type: Unsupported
value: /bar value: /bar
backendRefs: backendRefs:
- name: whoami - name: whoami

View file

@ -843,46 +843,52 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li
return nil, nil return nil, nil
} }
var listenerConditions []metav1.Condition
routeStatuses := map[ktypes.NamespacedName]gatev1.RouteParentStatus{} routeStatuses := map[ktypes.NamespacedName]gatev1.RouteParentStatus{}
for _, route := range routes { for _, route := range routes {
routeNsName := ktypes.NamespacedName{Namespace: route.Namespace, Name: route.Name}
parentRef, ok := shouldAttach(gateway, listener, route.Namespace, route.Spec.CommonRouteSpec) parentRef, ok := shouldAttach(gateway, listener, route.Namespace, route.Spec.CommonRouteSpec)
if !ok { if !ok {
// TODO: to add an invalid HTTPRoute status when no parent is matching,
// we have to start the attachment evaluation from the route not from the listeners.
// This will fix the HTTPRouteInvalidParentRefNotMatchingSectionName test.
continue continue
} }
routeConditions := []metav1.Condition{
{
Type: string(gatev1.RouteConditionAccepted),
Status: metav1.ConditionTrue,
ObservedGeneration: route.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(gatev1.RouteReasonAccepted),
},
{
Type: string(gatev1.RouteConditionResolvedRefs),
Status: metav1.ConditionTrue,
ObservedGeneration: route.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(gatev1.RouteConditionResolvedRefs),
},
}
hostnames := matchingHostnames(listener, route.Spec.Hostnames) hostnames := matchingHostnames(listener, route.Spec.Hostnames)
if len(hostnames) == 0 && listener.Hostname != nil && *listener.Hostname != "" && len(route.Spec.Hostnames) > 0 { if len(hostnames) == 0 && listener.Hostname != nil && *listener.Hostname != "" && len(route.Spec.Hostnames) > 0 {
// TODO update the corresponding route parent status // TODO update the corresponding route parent status.
// https://gateway-api.sigs.k8s.io/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.TLSRoute // https://gateway-api.sigs.k8s.io/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.TLSRoute
continue continue
} }
hostRule, err := hostRule(hostnames) hostRule, err := hostRule(hostnames)
if err != nil { if err != nil {
listenerConditions = append(listenerConditions, metav1.Condition{ // TODO update the route status condition.
Type: string(gatev1.ListenerConditionResolvedRefs),
Status: metav1.ConditionFalse,
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Reason: "InvalidRouteHostname", // TODO check the spec if a proper reason is introduced at some point
Message: fmt.Sprintf("Skipping HTTPRoute %s: invalid hostname: %v", route.Name, err),
})
continue continue
} }
for _, routeRule := range route.Spec.Rules { for _, routeRule := range route.Spec.Rules {
rule, err := extractRule(routeRule, hostRule) rule, err := extractRule(routeRule, hostRule)
if err != nil { if err != nil {
// update "ResolvedRefs" status true with "UnsupportedPathOrHeaderType" reason // TODO update the route status condition.
listenerConditions = append(listenerConditions, metav1.Condition{
Type: string(gatev1.ListenerConditionResolvedRefs),
Status: metav1.ConditionFalse,
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Reason: "UnsupportedPathOrHeaderType", // TODO check the spec if a proper reason is introduced at some point
Message: fmt.Sprintf("Skipping HTTPRoute %s: cannot generate rule: %v", route.Name, err),
})
continue continue
} }
@ -893,7 +899,7 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li
} }
if listener.Protocol == gatev1.HTTPSProtocolType && listener.TLS != nil { if listener.Protocol == gatev1.HTTPSProtocolType && listener.TLS != nil {
// TODO support let's encrypt // TODO support let's encrypt.
router.TLS = &dynamic.RouterTLSConfig{} router.TLS = &dynamic.RouterTLSConfig{}
} }
@ -901,33 +907,13 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li
routerName := route.Name + "-" + gateway.Name + "-" + ep routerName := route.Name + "-" + gateway.Name + "-" + ep
routerKey, err := makeRouterKey(router.Rule, makeID(route.Namespace, routerName)) routerKey, err := makeRouterKey(router.Rule, makeID(route.Namespace, routerName))
if err != nil { if err != nil {
// update "ResolvedRefs" status true with "DroppedRoutes" reason // TODO update the route status condition.
listenerConditions = append(listenerConditions, metav1.Condition{
Type: string(gatev1.ListenerConditionResolvedRefs),
Status: metav1.ConditionFalse,
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Reason: "InvalidRouterKey", // Should never happen
Message: fmt.Sprintf("Skipping HTTPRoute %s: cannot make router's key with rule %s: %v", route.Name, router.Rule, err),
})
// TODO update the RouteStatus condition / deduplicate conditions on listener
continue continue
} }
middlewares, err := p.loadMiddlewares(listener, route.Namespace, routerKey, routeRule.Filters) middlewares, err := p.loadMiddlewares(listener, route.Namespace, routerKey, routeRule.Filters)
if err != nil { if err != nil {
// update "ResolvedRefs" status true with "InvalidFilters" reason // TODO update the route status condition.
listenerConditions = append(listenerConditions, metav1.Condition{
Type: string(gatev1.ListenerConditionResolvedRefs),
Status: metav1.ConditionFalse,
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Reason: "InvalidFilters", // TODO check the spec if a proper reason is introduced at some point
Message: fmt.Sprintf("Cannot load HTTPRoute filter %s/%s: %v", route.Namespace, route.Name, err),
})
// TODO update the RouteStatus condition / deduplicate conditions on listener
continue continue
} }
@ -948,32 +934,35 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li
if len(routeRule.BackendRefs) == 1 && isInternalService(routeRule.BackendRefs[0].BackendRef) { if len(routeRule.BackendRefs) == 1 && isInternalService(routeRule.BackendRefs[0].BackendRef) {
router.Service = string(routeRule.BackendRefs[0].Name) router.Service = string(routeRule.BackendRefs[0].Name)
} else { } else {
wrrService, subServices, err := p.loadServices(client, route.Namespace, routeRule.BackendRefs) var wrr dynamic.WeightedRoundRobin
if err != nil { for _, backendRef := range routeRule.BackendRefs {
// update "ResolvedRefs" status true with "DroppedRoutes" reason weight := ptr.To(int(ptr.Deref(backendRef.Weight, 1)))
listenerConditions = append(listenerConditions, metav1.Condition{
Type: string(gatev1.ListenerConditionResolvedRefs),
Status: metav1.ConditionFalse,
ObservedGeneration: gateway.Generation,
LastTransitionTime: metav1.Now(),
Reason: "InvalidBackendRefs", // TODO check the spec if a proper reason is introduced at some point
Message: fmt.Sprintf("Cannot load HTTPRoute service %s/%s: %v", route.Namespace, route.Name, err),
})
// TODO update the RouteStatus condition / deduplicate conditions on listener name, svc, errCondition := p.loadHTTPService(client, route, backendRef)
if errCondition != nil {
routeConditions = appendCondition(routeConditions, *errCondition)
wrr.Services = append(wrr.Services, dynamic.WRRService{
Name: name,
Weight: weight,
Status: ptr.To(500),
})
continue continue
} }
for svcName, svc := range subServices {
if svc != nil { if svc != nil {
conf.HTTP.Services[svcName] = svc conf.HTTP.Services[name] = svc
}
} }
serviceName := provider.Normalize(routerKey + "-wrr") wrr.Services = append(wrr.Services, dynamic.WRRService{
conf.HTTP.Services[serviceName] = wrrService Name: name,
Weight: weight,
})
}
router.Service = serviceName wrrName := provider.Normalize(routerKey + "-wrr")
conf.HTTP.Services[wrrName] = &dynamic.Service{Weighted: &wrr}
router.Service = wrrName
} }
rt := &router rt := &router
@ -983,159 +972,85 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li
conf.HTTP.Routers[routerKey] = rt conf.HTTP.Routers[routerKey] = rt
} }
routeStatuses[ktypes.NamespacedName{Namespace: route.Namespace, Name: route.Name}] = gatev1.RouteParentStatus{ routeStatuses[routeNsName] = gatev1.RouteParentStatus{
ParentRef: parentRef, ParentRef: parentRef,
ControllerName: controllerName, ControllerName: controllerName,
Conditions: []metav1.Condition{ Conditions: routeConditions,
{
Type: string(gatev1.RouteConditionAccepted),
Status: metav1.ConditionTrue,
ObservedGeneration: route.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(gatev1.RouteReasonAccepted),
},
{
Type: string(gatev1.RouteConditionResolvedRefs),
Status: metav1.ConditionTrue,
ObservedGeneration: route.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(gatev1.RouteConditionResolvedRefs),
},
},
} }
} }
return listenerConditions, routeStatuses return nil, routeStatuses
} }
// loadServices is generating a WRR service, even when there is only one target. // loadHTTPService returns a dynamic.Service config corresponding to the given gatev1.HTTPBackendRef.
func (p *Provider) loadServices(client Client, namespace string, backendRefs []gatev1.HTTPBackendRef) (*dynamic.Service, map[string]*dynamic.Service, error) { // Note that the returned dynamic.Service config can be nil (for cross-provider, internal services, and backendFunc).
services := map[string]*dynamic.Service{} func (p *Provider) loadHTTPService(client Client, route *gatev1.HTTPRoute, backendRef gatev1.HTTPBackendRef) (string, *dynamic.Service, *metav1.Condition) {
group := groupCore
wrrSvc := &dynamic.Service{ if backendRef.Group != nil && *backendRef.Group != "" {
Weighted: &dynamic.WeightedRoundRobin{ group = string(*backendRef.Group)
Services: []dynamic.WRRService{},
},
} }
for _, backendRef := range backendRefs { kind := ptr.Deref(backendRef.Kind, "Service")
if backendRef.Group == nil || backendRef.Kind == nil { namespace := ptr.Deref(backendRef.Namespace, gatev1.Namespace(route.Namespace))
// Should not happen as this is validated by kubernetes namespaceStr := string(namespace)
continue serviceName := provider.Normalize(makeID(namespaceStr, string(backendRef.Name)))
if group != groupCore || kind != "Service" {
// TODO support cross namespace through ReferencePolicy.
if namespaceStr != route.Namespace {
return serviceName, nil, &metav1.Condition{
Type: string(gatev1.RouteConditionResolvedRefs),
Status: metav1.ConditionFalse,
ObservedGeneration: route.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(gatev1.RouteReasonRefNotPermitted),
Message: fmt.Sprintf("Cannot load HTTPBackendRef %s/%s/%s/%s namespace not allowed", group, kind, namespace, backendRef.Name),
}
} }
if isInternalService(backendRef.BackendRef) { name, service, err := p.loadHTTPBackendRef(namespaceStr, backendRef)
return nil, nil, fmt.Errorf("traefik internal service %s is not allowed in a WRR loadbalancer", backendRef.BackendRef.Name)
}
weight := int(ptr.Deref(backendRef.Weight, 1))
if *backendRef.Group != "" && *backendRef.Group != groupCore && *backendRef.Kind != "Service" {
if backendRef.Namespace != nil && string(*backendRef.Namespace) != namespace {
// TODO: support backend reference grant.
return nil, nil, fmt.Errorf("unsupported HTTPBackendRef %s/%s/%s", *backendRef.Group, *backendRef.Kind, backendRef.Name)
}
name, service, err := p.loadHTTPBackendRef(namespace, backendRef)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("unable to load HTTPBackendRef %s/%s/%s: %w", *backendRef.Group, *backendRef.Kind, backendRef.Name, err) return serviceName, nil, &metav1.Condition{
} Type: string(gatev1.RouteConditionResolvedRefs),
Status: metav1.ConditionFalse,
services[name] = service ObservedGeneration: route.Generation,
wrrSvc.Weighted.Services = append(wrrSvc.Weighted.Services, dynamic.WRRService{Name: name, Weight: &weight}) LastTransitionTime: metav1.Now(),
continue Reason: string(gatev1.RouteReasonInvalidKind),
} Message: fmt.Sprintf("Cannot load HTTPBackendRef %s/%s/%s/%s: %s", group, kind, namespace, backendRef.Name, err),
lb := &dynamic.ServersLoadBalancer{}
lb.SetDefaults()
svc := dynamic.Service{LoadBalancer: lb}
// TODO support cross namespace through ReferencePolicy
service, exists, err := client.GetService(namespace, string(backendRef.Name))
if err != nil {
return nil, nil, err
}
if !exists {
return nil, nil, errors.New("service not found")
}
if len(service.Spec.Ports) > 1 && backendRef.Port == nil {
// If the port is unspecified and the backend is a Service
// object consisting of multiple port definitions, the route
// must be dropped from the Gateway. The controller should
// raise the "ResolvedRefs" condition on the Gateway with the
// "DroppedRoutes" reason. The gateway status for this route
// should be updated with a condition that describes the error
// more specifically.
log.Error().Msg("A multiple ports Kubernetes Service cannot be used if unspecified backendRef.Port")
continue
}
var portSpec corev1.ServicePort
var match bool
for _, p := range service.Spec.Ports {
if backendRef.Port == nil || p.Port == int32(*backendRef.Port) {
portSpec = p
match = true
break
} }
} }
if !match { return name, service, nil
return nil, nil, errors.New("service port not found")
}
endpoints, endpointsExists, endpointsErr := client.GetEndpoints(namespace, string(backendRef.Name))
if endpointsErr != nil {
return nil, nil, endpointsErr
}
if !endpointsExists {
return nil, nil, errors.New("endpoints not found")
}
if len(endpoints.Subsets) == 0 {
return nil, nil, errors.New("subset not found")
}
var port int32
var portStr string
for _, subset := range endpoints.Subsets {
for _, p := range subset.Ports {
if portSpec.Name == p.Name {
port = p.Port
break
}
} }
port := ptr.Deref(backendRef.Port, gatev1.PortNumber(0))
if port == 0 { if port == 0 {
return nil, nil, errors.New("cannot define a port") return serviceName, nil, &metav1.Condition{
} Type: string(gatev1.RouteConditionResolvedRefs),
Status: metav1.ConditionFalse,
protocol := getProtocol(portSpec) ObservedGeneration: route.Generation,
LastTransitionTime: metav1.Now(),
portStr = strconv.FormatInt(int64(port), 10) Reason: string(gatev1.RouteReasonUnsupportedProtocol),
for _, addr := range subset.Addresses { Message: fmt.Sprintf("Cannot load HTTPBackendRef %s/%s/%s/%s port is required", group, kind, namespace, backendRef.Name),
svc.LoadBalancer.Servers = append(svc.LoadBalancer.Servers, dynamic.Server{
URL: fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(addr.IP, portStr)),
})
} }
} }
serviceName := provider.Normalize(makeID(service.Namespace, service.Name) + "-" + portStr) portStr := strconv.FormatInt(int64(port), 10)
services[serviceName] = &svc serviceName = provider.Normalize(serviceName + "-" + portStr)
wrrSvc.Weighted.Services = append(wrrSvc.Weighted.Services, dynamic.WRRService{Name: serviceName, Weight: &weight}) lb, err := loadHTTPServers(client, namespaceStr, backendRef)
if err != nil {
return serviceName, nil, &metav1.Condition{
Type: string(gatev1.RouteConditionResolvedRefs),
Status: metav1.ConditionFalse,
ObservedGeneration: route.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(gatev1.RouteReasonBackendNotFound),
Message: fmt.Sprintf("Cannot load HTTPBackendRef %s/%s/%s/%s: %s", group, kind, namespace, backendRef.Name, err),
}
} }
if len(wrrSvc.Weighted.Services) == 0 { return serviceName, &dynamic.Service{LoadBalancer: lb}, nil
return nil, nil, errors.New("no service has been created")
}
return wrrSvc, services, nil
} }
func (p *Provider) loadHTTPBackendRef(namespace string, backendRef gatev1.HTTPBackendRef) (string, *dynamic.Service, error) { func (p *Provider) loadHTTPBackendRef(namespace string, backendRef gatev1.HTTPBackendRef) (string, *dynamic.Service, error) {
@ -1224,6 +1139,72 @@ func (p *Provider) loadHTTPRouteFilterExtensionRef(namespace string, extensionRe
return filterFunc(string(extensionRef.Name), namespace) return filterFunc(string(extensionRef.Name), namespace)
} }
// TODO support cross namespace through ReferencePolicy.
func loadHTTPServers(client Client, namespace string, backendRef gatev1.HTTPBackendRef) (*dynamic.ServersLoadBalancer, error) {
service, exists, err := client.GetService(namespace, string(backendRef.Name))
if err != nil {
return nil, fmt.Errorf("getting service: %w", err)
}
if !exists {
return nil, errors.New("service not found")
}
var portSpec corev1.ServicePort
var match bool
for _, p := range service.Spec.Ports {
if backendRef.Port == nil || p.Port == int32(*backendRef.Port) {
portSpec = p
match = true
break
}
}
if !match {
return nil, errors.New("service port not found")
}
endpoints, endpointsExists, err := client.GetEndpoints(namespace, string(backendRef.Name))
if err != nil {
return nil, fmt.Errorf("getting endpoints: %w", err)
}
if !endpointsExists {
return nil, errors.New("endpoints not found")
}
if len(endpoints.Subsets) == 0 {
return nil, errors.New("subset not found")
}
lb := &dynamic.ServersLoadBalancer{}
lb.SetDefaults()
var port int32
var portStr string
for _, subset := range endpoints.Subsets {
for _, p := range subset.Ports {
if portSpec.Name == p.Name {
port = p.Port
break
}
}
if port == 0 {
return nil, errors.New("cannot define a port")
}
protocol := getProtocol(portSpec)
portStr = strconv.FormatInt(int64(port), 10)
for _, addr := range subset.Addresses {
lb.Servers = append(lb.Servers, dynamic.Server{
URL: fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(addr.IP, portStr)),
})
}
}
return lb, nil
}
// loadTCPServices is generating a WRR service, even when there is only one target. // loadTCPServices is generating a WRR service, even when there is only one target.
func loadTCPServices(client Client, namespace string, backendRefs []gatev1.BackendRef) (*dynamic.TCPService, map[string]*dynamic.TCPService, error) { func loadTCPServices(client Client, namespace string, backendRefs []gatev1.BackendRef) (*dynamic.TCPService, map[string]*dynamic.TCPService, error) {
services := map[string]*dynamic.TCPService{} services := map[string]*dynamic.TCPService{}
@ -2325,3 +2306,14 @@ func pointerEquals[T comparable](p1, p2 *T) bool {
return val1 == val2 return val1 == val2
} }
func appendCondition(conditions []metav1.Condition, condition metav1.Condition) []metav1.Condition {
res := []metav1.Condition{condition}
for _, c := range conditions {
if c.Type != condition.Type {
res = append(res, c)
}
}
return res
}

View file

@ -196,9 +196,28 @@ func TestLoadHTTPRoutes(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{
"default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06": {
EntryPoints: []string{"web"},
Service: "default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06-wrr",
Rule: "Host(`foo.com`) && Path(`/bar`)",
RuleSyntax: "v3",
},
},
Middlewares: map[string]*dynamic.Middleware{}, Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{}, Services: map[string]*dynamic.Service{
"default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06-wrr": {
Weighted: &dynamic.WeightedRoundRobin{
Services: []dynamic.WRRService{
{
Name: "default-whoami-9000",
Weight: ptr.To(1),
Status: ptr.To(500),
},
},
},
},
},
ServersTransports: map[string]*dynamic.ServersTransport{}, ServersTransports: map[string]*dynamic.ServersTransport{},
}, },
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
@ -586,7 +605,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -680,7 +699,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -749,7 +768,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -809,7 +828,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -869,7 +888,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -935,7 +954,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -945,7 +964,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami2-8080", Name: "default-whoami2-8080",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1021,11 +1040,11 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
{ {
Name: "default-whoami2-8080", Name: "default-whoami2-8080",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1113,7 +1132,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1123,7 +1142,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1204,7 +1223,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1214,7 +1233,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1289,7 +1308,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1299,7 +1318,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1359,7 +1378,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1425,7 +1444,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1435,7 +1454,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "bar-whoami-bar-80", Name: "bar-whoami-bar-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1511,7 +1530,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "bar-whoami-bar-80", Name: "bar-whoami-bar-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1580,7 +1599,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1649,7 +1668,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1717,7 +1736,7 @@ func TestLoadHTTPRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1826,7 +1845,7 @@ func TestLoadHTTPRoutes_backendExtensionRef(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "whoami", Name: "whoami",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1875,7 +1894,7 @@ func TestLoadHTTPRoutes_backendExtensionRef(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "whoami", Name: "whoami",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -1911,9 +1930,28 @@ func TestLoadHTTPRoutes_backendExtensionRef(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{
"default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06": {
EntryPoints: []string{"web"},
Service: "default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06-wrr",
Rule: "Host(`foo.com`) && Path(`/bar`)",
RuleSyntax: "v3",
},
},
Middlewares: map[string]*dynamic.Middleware{}, Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{}, Services: map[string]*dynamic.Service{
"default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06-wrr": {
Weighted: &dynamic.WeightedRoundRobin{
Services: []dynamic.WRRService{
{
Name: "default-whoami",
Weight: ptr.To(1),
Status: ptr.To(500),
},
},
},
},
},
ServersTransports: map[string]*dynamic.ServersTransport{}, ServersTransports: map[string]*dynamic.ServersTransport{},
}, },
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
@ -1942,9 +1980,28 @@ func TestLoadHTTPRoutes_backendExtensionRef(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{
"default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06": {
EntryPoints: []string{"web"},
Service: "default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06-wrr",
Rule: "Host(`foo.com`) && Path(`/bar`)",
RuleSyntax: "v3",
},
},
Middlewares: map[string]*dynamic.Middleware{}, Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{}, Services: map[string]*dynamic.Service{
"default-http-app-1-my-gateway-web-1c0cf64bde37d9d0df06-wrr": {
Weighted: &dynamic.WeightedRoundRobin{
Services: []dynamic.WRRService{
{
Name: "default-whoami",
Weight: ptr.To(1),
Status: ptr.To(500),
},
},
},
},
},
ServersTransports: map[string]*dynamic.ServersTransport{}, ServersTransports: map[string]*dynamic.ServersTransport{},
}, },
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
@ -1989,11 +2046,11 @@ func TestLoadHTTPRoutes_backendExtensionRef(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "service@file", Name: "service@file",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2103,7 +2160,7 @@ func TestLoadHTTPRoutes_filterExtensionRef(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2170,7 +2227,7 @@ func TestLoadHTTPRoutes_filterExtensionRef(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2503,7 +2560,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2567,7 +2624,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2577,7 +2634,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-10000", Name: "default-whoamitcp-10000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2647,11 +2704,11 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-tcp-app-my-tcp-gateway-tcp-1-e3b0c44298fc1c149afb-wrr-0", Name: "default-tcp-app-my-tcp-gateway-tcp-1-e3b0c44298fc1c149afb-wrr-0",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
{ {
Name: "default-tcp-app-my-tcp-gateway-tcp-1-e3b0c44298fc1c149afb-wrr-1", Name: "default-tcp-app-my-tcp-gateway-tcp-1-e3b0c44298fc1c149afb-wrr-1",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2661,7 +2718,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2671,7 +2728,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-10000", Name: "default-whoamitcp-10000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2739,11 +2796,11 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "service@file", Name: "service@file",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2799,7 +2856,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Weighted: &dynamic.TCPWeightedRoundRobin{ Weighted: &dynamic.TCPWeightedRoundRobin{
Services: []dynamic.TCPWRRService{{ Services: []dynamic.TCPWRRService{{
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}}, }},
}, },
}, },
@ -2863,7 +2920,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2925,7 +2982,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -2935,7 +2992,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3003,7 +3060,7 @@ func TestLoadTCPRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3317,7 +3374,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3385,7 +3442,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3444,7 +3501,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3511,7 +3568,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3521,7 +3578,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-10000", Name: "default-whoamitcp-10000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3599,11 +3656,11 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "service@file", Name: "service@file",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3671,7 +3728,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3730,7 +3787,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3789,7 +3846,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3848,7 +3905,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3907,7 +3964,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3975,7 +4032,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -3985,7 +4042,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4056,7 +4113,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4115,11 +4172,11 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-tls-app-my-gateway-tcp-1-673acf455cb2dab0b43a-wrr-0", Name: "default-tls-app-my-gateway-tcp-1-673acf455cb2dab0b43a-wrr-0",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
{ {
Name: "default-tls-app-my-gateway-tcp-1-673acf455cb2dab0b43a-wrr-1", Name: "default-tls-app-my-gateway-tcp-1-673acf455cb2dab0b43a-wrr-1",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4129,7 +4186,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4139,7 +4196,7 @@ func TestLoadTLSRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-10000", Name: "default-whoamitcp-10000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4374,7 +4431,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4384,7 +4441,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4394,7 +4451,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4437,7 +4494,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4447,7 +4504,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4559,7 +4616,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4569,7 +4626,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4579,7 +4636,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4622,7 +4679,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4632,7 +4689,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4729,7 +4786,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4739,7 +4796,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4749,7 +4806,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4783,7 +4840,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4793,7 +4850,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4837,7 +4894,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4847,7 +4904,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4889,7 +4946,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "bar-whoami-bar-80", Name: "bar-whoami-bar-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4899,7 +4956,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "bar-whoami-bar-80", Name: "bar-whoami-bar-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4979,7 +5036,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4989,7 +5046,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -4999,7 +5056,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "bar-whoamitcp-bar-9000", Name: "bar-whoamitcp-bar-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -5046,7 +5103,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "bar-whoami-bar-80", Name: "bar-whoami-bar-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -5056,7 +5113,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "bar-whoami-bar-80", Name: "bar-whoami-bar-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -5114,7 +5171,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -5124,7 +5181,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.TCPWRRService{ Services: []dynamic.TCPWRRService{
{ {
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -5167,7 +5224,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -5177,7 +5234,7 @@ func TestLoadMixedRoutes(t *testing.T) {
Services: []dynamic.WRRService{ Services: []dynamic.WRRService{
{ {
Name: "default-whoami-80", Name: "default-whoami-80",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}, },
}, },
}, },
@ -5387,7 +5444,7 @@ func TestLoadRoutesWithReferenceGrants(t *testing.T) {
Weighted: &dynamic.TCPWeightedRoundRobin{ Weighted: &dynamic.TCPWeightedRoundRobin{
Services: []dynamic.TCPWRRService{{ Services: []dynamic.TCPWRRService{{
Name: "default-whoamitcp-9000", Name: "default-whoamitcp-9000",
Weight: func(i int) *int { return &i }(1), Weight: ptr.To(1),
}}, }},
}, },
}, },

View file

@ -222,6 +222,14 @@ func (m *Manager) getWRRServiceHandler(ctx context.Context, serviceName string,
balancer := wrr.New(config.Sticky, config.HealthCheck != nil) balancer := wrr.New(config.Sticky, config.HealthCheck != nil)
for _, service := range shuffle(config.Services, m.rand) { for _, service := range shuffle(config.Services, m.rand) {
if service.Status != nil {
serviceHandler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(*service.Status)
})
balancer.Add(service.Name, serviceHandler, service.Weight)
continue
}
serviceHandler, err := m.BuildHTTP(ctx, service.Name) serviceHandler, err := m.BuildHTTP(ctx, service.Name)
if err != nil { if err != nil {
return nil, err return nil, err