diff --git a/integration/k8s_conformance_test.go b/integration/k8s_conformance_test.go index 01dd4856b..6c6d99ee1 100644 --- a/integration/k8s_conformance_test.go +++ b/integration/k8s_conformance_test.go @@ -205,7 +205,6 @@ func (s *K8sConformanceSuite) TestK8sGatewayAPIConformance() { tests.GatewayInvalidTLSConfiguration.ShortName, tests.HTTPRouteHostnameIntersection.ShortName, tests.HTTPRouteListenerHostnameMatching.ShortName, - tests.HTTPRouteInvalidNonExistentBackendRef.ShortName, tests.HTTPRouteInvalidReferenceGrant.ShortName, tests.HTTPRouteInvalidCrossNamespaceParentRef.ShortName, tests.HTTPRouteInvalidParentRefNotMatchingSectionName.ShortName, @@ -213,7 +212,6 @@ func (s *K8sConformanceSuite) TestK8sGatewayAPIConformance() { tests.HTTPRouteMatchingAcrossRoutes.ShortName, tests.HTTPRoutePartiallyInvalidViaInvalidReferenceGrant.ShortName, tests.HTTPRouteRedirectHostAndStatus.ShortName, - tests.HTTPRouteInvalidBackendRefUnknownKind.ShortName, tests.HTTPRoutePathMatchOrder.ShortName, tests.HTTPRouteHeaderMatching.ShortName, tests.HTTPRouteReferenceGrant.ShortName, diff --git a/pkg/config/dynamic/http_config.go b/pkg/config/dynamic/http_config.go index 541f61b79..ecfd68c7e 100644 --- a/pkg/config/dynamic/http_config.go +++ b/pkg/config/dynamic/http_config.go @@ -128,6 +128,10 @@ type WeightedRoundRobin struct { type WRRService struct { 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"` + + // 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. diff --git a/pkg/config/dynamic/zz_generated.deepcopy.go b/pkg/config/dynamic/zz_generated.deepcopy.go index 63b159382..05436088b 100644 --- a/pkg/config/dynamic/zz_generated.deepcopy.go +++ b/pkg/config/dynamic/zz_generated.deepcopy.go @@ -2187,6 +2187,11 @@ func (in *WRRService) DeepCopyInto(out *WRRService) { *out = new(int) **out = **in } + if in.Status != nil { + in, out := &in.Status, &out.Status + *out = new(int) + **out = **in + } return } diff --git a/pkg/provider/kubernetes/gateway/fixtures/httproute/simple_with_bad_rule.yml b/pkg/provider/kubernetes/gateway/fixtures/httproute/simple_with_bad_rule.yml index 0ff70ee1a..d1e0842a2 100644 --- a/pkg/provider/kubernetes/gateway/fixtures/httproute/simple_with_bad_rule.yml +++ b/pkg/provider/kubernetes/gateway/fixtures/httproute/simple_with_bad_rule.yml @@ -38,7 +38,7 @@ spec: rules: - matches: - path: - type: PathPrefix + type: Unsupported value: /bar backendRefs: - name: whoami diff --git a/pkg/provider/kubernetes/gateway/kubernetes.go b/pkg/provider/kubernetes/gateway/kubernetes.go index e4fee7308..ce3c12fe6 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes.go +++ b/pkg/provider/kubernetes/gateway/kubernetes.go @@ -843,46 +843,52 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li return nil, nil } - var listenerConditions []metav1.Condition routeStatuses := map[ktypes.NamespacedName]gatev1.RouteParentStatus{} for _, route := range routes { + routeNsName := ktypes.NamespacedName{Namespace: route.Namespace, Name: route.Name} + parentRef, ok := shouldAttach(gateway, listener, route.Namespace, route.Spec.CommonRouteSpec) 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 } + 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) 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 continue } hostRule, err := hostRule(hostnames) if err != nil { - listenerConditions = append(listenerConditions, metav1.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), - }) + // TODO update the route status condition. continue } for _, routeRule := range route.Spec.Rules { rule, err := extractRule(routeRule, hostRule) if err != nil { - // update "ResolvedRefs" status true with "UnsupportedPathOrHeaderType" reason - 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), - }) + // TODO update the route status condition. continue } @@ -893,7 +899,7 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li } if listener.Protocol == gatev1.HTTPSProtocolType && listener.TLS != nil { - // TODO support let's encrypt + // TODO support let's encrypt. router.TLS = &dynamic.RouterTLSConfig{} } @@ -901,33 +907,13 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li routerName := route.Name + "-" + gateway.Name + "-" + ep routerKey, err := makeRouterKey(router.Rule, makeID(route.Namespace, routerName)) if err != nil { - // update "ResolvedRefs" status true with "DroppedRoutes" reason - 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 + // TODO update the route status condition. continue } middlewares, err := p.loadMiddlewares(listener, route.Namespace, routerKey, routeRule.Filters) if err != nil { - // update "ResolvedRefs" status true with "InvalidFilters" reason - 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 + // TODO update the route status condition. 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) { router.Service = string(routeRule.BackendRefs[0].Name) } else { - wrrService, subServices, err := p.loadServices(client, route.Namespace, routeRule.BackendRefs) - if err != nil { - // update "ResolvedRefs" status true with "DroppedRoutes" reason - 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), - }) + var wrr dynamic.WeightedRoundRobin + for _, backendRef := range routeRule.BackendRefs { + weight := ptr.To(int(ptr.Deref(backendRef.Weight, 1))) - // TODO update the RouteStatus condition / deduplicate conditions on listener - continue - } - - for svcName, svc := range subServices { - if svc != nil { - conf.HTTP.Services[svcName] = svc + 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 } + + if svc != nil { + conf.HTTP.Services[name] = svc + } + + wrr.Services = append(wrr.Services, dynamic.WRRService{ + Name: name, + Weight: weight, + }) } - serviceName := provider.Normalize(routerKey + "-wrr") - conf.HTTP.Services[serviceName] = wrrService + wrrName := provider.Normalize(routerKey + "-wrr") + conf.HTTP.Services[wrrName] = &dynamic.Service{Weighted: &wrr} - router.Service = serviceName + router.Service = wrrName } rt := &router @@ -983,159 +972,85 @@ func (p *Provider) gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, li conf.HTTP.Routers[routerKey] = rt } - routeStatuses[ktypes.NamespacedName{Namespace: route.Namespace, Name: route.Name}] = gatev1.RouteParentStatus{ + routeStatuses[routeNsName] = gatev1.RouteParentStatus{ ParentRef: parentRef, ControllerName: controllerName, - Conditions: []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), - }, - }, + Conditions: routeConditions, } } - return listenerConditions, routeStatuses + return nil, routeStatuses } -// loadServices is generating a WRR service, even when there is only one target. -func (p *Provider) loadServices(client Client, namespace string, backendRefs []gatev1.HTTPBackendRef) (*dynamic.Service, map[string]*dynamic.Service, error) { - services := map[string]*dynamic.Service{} - - wrrSvc := &dynamic.Service{ - Weighted: &dynamic.WeightedRoundRobin{ - Services: []dynamic.WRRService{}, - }, +// loadHTTPService returns a dynamic.Service config corresponding to the given gatev1.HTTPBackendRef. +// Note that the returned dynamic.Service config can be nil (for cross-provider, internal services, and backendFunc). +func (p *Provider) loadHTTPService(client Client, route *gatev1.HTTPRoute, backendRef gatev1.HTTPBackendRef) (string, *dynamic.Service, *metav1.Condition) { + group := groupCore + if backendRef.Group != nil && *backendRef.Group != "" { + group = string(*backendRef.Group) } - for _, backendRef := range backendRefs { - if backendRef.Group == nil || backendRef.Kind == nil { - // Should not happen as this is validated by kubernetes - continue - } + kind := ptr.Deref(backendRef.Kind, "Service") + namespace := ptr.Deref(backendRef.Namespace, gatev1.Namespace(route.Namespace)) + namespaceStr := string(namespace) + serviceName := provider.Normalize(makeID(namespaceStr, string(backendRef.Name))) - if isInternalService(backendRef.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) + 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), } - - name, service, err := p.loadHTTPBackendRef(namespace, backendRef) - if err != nil { - return nil, nil, fmt.Errorf("unable to load HTTPBackendRef %s/%s/%s: %w", *backendRef.Group, *backendRef.Kind, backendRef.Name, err) - } - - services[name] = service - wrrSvc.Weighted.Services = append(wrrSvc.Weighted.Services, dynamic.WRRService{Name: name, Weight: &weight}) - continue } - 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)) + name, service, err := p.loadHTTPBackendRef(namespaceStr, backendRef) 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 + return serviceName, nil, &metav1.Condition{ + Type: string(gatev1.RouteConditionResolvedRefs), + Status: metav1.ConditionFalse, + ObservedGeneration: route.Generation, + LastTransitionTime: metav1.Now(), + Reason: string(gatev1.RouteReasonInvalidKind), + Message: fmt.Sprintf("Cannot load HTTPBackendRef %s/%s/%s/%s: %s", group, kind, namespace, backendRef.Name, err), } } - if !match { - 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 - } - } - - if port == 0 { - return nil, nil, errors.New("cannot define a port") - } - - protocol := getProtocol(portSpec) - - portStr = strconv.FormatInt(int64(port), 10) - for _, addr := range subset.Addresses { - 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) - services[serviceName] = &svc - - wrrSvc.Weighted.Services = append(wrrSvc.Weighted.Services, dynamic.WRRService{Name: serviceName, Weight: &weight}) + return name, service, nil } - if len(wrrSvc.Weighted.Services) == 0 { - return nil, nil, errors.New("no service has been created") + port := ptr.Deref(backendRef.Port, gatev1.PortNumber(0)) + if port == 0 { + return serviceName, nil, &metav1.Condition{ + Type: string(gatev1.RouteConditionResolvedRefs), + Status: metav1.ConditionFalse, + ObservedGeneration: route.Generation, + LastTransitionTime: metav1.Now(), + Reason: string(gatev1.RouteReasonUnsupportedProtocol), + Message: fmt.Sprintf("Cannot load HTTPBackendRef %s/%s/%s/%s port is required", group, kind, namespace, backendRef.Name), + } } - return wrrSvc, services, nil + portStr := strconv.FormatInt(int64(port), 10) + serviceName = provider.Normalize(serviceName + "-" + portStr) + + 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), + } + } + + return serviceName, &dynamic.Service{LoadBalancer: lb}, nil } 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) } +// 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. func loadTCPServices(client Client, namespace string, backendRefs []gatev1.BackendRef) (*dynamic.TCPService, map[string]*dynamic.TCPService, error) { services := map[string]*dynamic.TCPService{} @@ -2325,3 +2306,14 @@ func pointerEquals[T comparable](p1, p2 *T) bool { 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 +} diff --git a/pkg/provider/kubernetes/gateway/kubernetes_test.go b/pkg/provider/kubernetes/gateway/kubernetes_test.go index c428828b2..371ea2251 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes_test.go +++ b/pkg/provider/kubernetes/gateway/kubernetes_test.go @@ -196,9 +196,28 @@ func TestLoadHTTPRoutes(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-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{}, + 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{}, }, TLS: &dynamic.TLSConfiguration{}, @@ -586,7 +605,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr.To(1), }, { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{}, }, HTTP: &dynamic.HTTPConfiguration{ - Routers: map[string]*dynamic.Router{}, - Middlewares: map[string]*dynamic.Middleware{}, - Services: map[string]*dynamic.Service{}, + 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{}, + 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{}, }, TLS: &dynamic.TLSConfiguration{}, @@ -1942,9 +1980,28 @@ func TestLoadHTTPRoutes_backendExtensionRef(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-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{}, + 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{}, }, TLS: &dynamic.TLSConfiguration{}, @@ -1989,11 +2046,11 @@ func TestLoadHTTPRoutes_backendExtensionRef(t *testing.T) { Services: []dynamic.WRRService{ { Name: "service@file", - Weight: func(i int) *int { return &i }(1), + Weight: ptr.To(1), }, { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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", - Weight: func(i int) *int { return &i }(1), + Weight: ptr.To(1), }, }, }, @@ -2661,7 +2718,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { 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{ { 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{ { Name: "service@file", - Weight: func(i int) *int { return &i }(1), + Weight: ptr.To(1), }, { 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{ Services: []dynamic.TCPWRRService{{ 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { Name: "service@file", - Weight: func(i int) *int { return &i }(1), + Weight: ptr.To(1), }, { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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", - Weight: func(i int) *int { return &i }(1), + Weight: ptr.To(1), }, }, }, @@ -4129,7 +4186,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ { 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{ Services: []dynamic.TCPWRRService{{ Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr.To(1), }}, }, }, diff --git a/pkg/server/service/service.go b/pkg/server/service/service.go index f44141f84..2a41836e3 100644 --- a/pkg/server/service/service.go +++ b/pkg/server/service/service.go @@ -222,6 +222,14 @@ func (m *Manager) getWRRServiceHandler(ctx context.Context, serviceName string, balancer := wrr.New(config.Sticky, config.HealthCheck != nil) 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) if err != nil { return nil, err