2023-06-21 16:39:53 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-06-21 16:39:53 +00:00
|
|
|
|
|
|
|
package xds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-08-10 18:00:44 +00:00
|
|
|
"github.com/hashicorp/go-hclog"
|
2023-06-21 16:39:53 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
2023-08-10 18:00:44 +00:00
|
|
|
func groupedEndpoints(logger hclog.Logger, locality *structs.Locality, policy *structs.DiscoveryPrioritizeByLocality, csns structs.CheckServiceNodes) ([]structs.CheckServiceNodes, error) {
|
2023-06-21 16:39:53 +00:00
|
|
|
switch {
|
|
|
|
case policy == nil || policy.Mode == "" || policy.Mode == "none":
|
|
|
|
return []structs.CheckServiceNodes{csns}, nil
|
|
|
|
case policy.Mode == "failover":
|
2023-08-10 18:00:44 +00:00
|
|
|
log := logger.Named("locality")
|
|
|
|
return prioritizeByLocalityFailover(log, locality, csns), nil
|
2023-06-21 16:39:53 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unexpected priortize-by-locality mode %q", policy.Mode)
|
|
|
|
}
|
|
|
|
}
|