2023-06-21 16:39:53 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|