Skip to content

Commit e8b1740

Browse files
authored
Merge pull request #1016 from SomtochiAma/istio-crds
Add support for Istio load balancer settings
2 parents b57d393 + 5245045 commit e8b1740

2 files changed

Lines changed: 215 additions & 0 deletions

File tree

pkg/apis/istio/v1alpha3/destination_rule.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,144 @@ type LoadBalancerSettings struct {
243243
// Simple or ConsistentHash
244244
Simple SimpleLB `json:"simple,omitempty"`
245245
ConsistentHash *ConsistentHashLB `json:"consistentHash,omitempty"`
246+
// Locality load balancer settings, this will override mesh wide settings in entirety, meaning no merging would be performed
247+
// between this object and the object one in MeshConfig
248+
LocalityLbSetting *LocalityLbSetting `json:"localityLbSetting,omitempty"`
249+
}
250+
251+
// Locality-weighted load balancing allows administrators to control the
252+
// distribution of traffic to endpoints based on the localities of where the
253+
// traffic originates and where it will terminate. These localities are
254+
// specified using arbitrary labels that designate a hierarchy of localities in
255+
// {region}/{zone}/{sub-zone} form. For additional detail refer to
256+
// [Locality Weight](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/locality_weight)
257+
// The following example shows how to setup locality weights mesh-wide.
258+
//
259+
// Given a mesh with workloads and their service deployed to "us-west/zone1/*"
260+
// and "us-west/zone2/*". This example specifies that when traffic accessing a
261+
// service originates from workloads in "us-west/zone1/*", 80% of the traffic
262+
// will be sent to endpoints in "us-west/zone1/*", i.e the same zone, and the
263+
// remaining 20% will go to endpoints in "us-west/zone2/*". This setup is
264+
// intended to favor routing traffic to endpoints in the same locality.
265+
// A similar setting is specified for traffic originating in "us-west/zone2/*".
266+
//
267+
// ```yaml
268+
// distribute:
269+
// - from: us-west/zone1/*
270+
// to:
271+
// "us-west/zone1/*": 80
272+
// "us-west/zone2/*": 20
273+
// - from: us-west/zone2/*
274+
// to:
275+
// "us-west/zone1/*": 20
276+
// "us-west/zone2/*": 80
277+
// ```
278+
//
279+
// If the goal of the operator is not to distribute load across zones and
280+
// regions but rather to restrict the regionality of failover to meet other
281+
// operational requirements an operator can set a 'failover' policy instead of
282+
// a 'distribute' policy.
283+
//
284+
// The following example sets up a locality failover policy for regions.
285+
// Assume a service resides in zones within us-east, us-west & eu-west
286+
// this example specifies that when endpoints within us-east become unhealthy
287+
// traffic should failover to endpoints in any zone or sub-zone within eu-west
288+
// and similarly us-west should failover to us-east.
289+
//
290+
// ```yaml
291+
// failover:
292+
// - from: us-east
293+
// to: eu-west
294+
// - from: us-west
295+
// to: us-east
296+
// ```
297+
// Locality load balancing settings.
298+
type LocalityLbSetting struct {
299+
// Explicitly specify loadbalancing weight across different zones and geographical locations.
300+
// Refer to [Locality weighted load balancing](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/locality_weight)
301+
// If empty, the locality weight is set according to the endpoints number within it.
302+
Distribute []Distribute `json:"distribute,omitempty"`
303+
// Optional: only one of distribute, failover or failoverPriority can be set.
304+
// Explicitly specify the region traffic will land on when endpoints in local region becomes unhealthy.
305+
// Should be used together with OutlierDetection to detect unhealthy endpoints.
306+
// Note: if no OutlierDetection specified, this will not take effect.
307+
Failover []Failover `json:"failover,omitempty"`
308+
// failoverPriority is an ordered list of labels used to sort endpoints to do priority based load balancing.
309+
// This is to support traffic failover across different groups of endpoints.
310+
// Suppose there are total N labels specified:
311+
//
312+
// 1. Endpoints matching all N labels with the client proxy have priority P(0) i.e. the highest priority.
313+
// 2. Endpoints matching the first N-1 labels with the client proxy have priority P(1) i.e. second highest priority.
314+
// 3. By extension of this logic, endpoints matching only the first label with the client proxy has priority P(N-1) i.e. second lowest priority.
315+
// 4. All the other endpoints have priority P(N) i.e. lowest priority.
316+
//
317+
// Note: For a label to be considered for match, the previous labels must match, i.e. nth label would be considered matched only if first n-1 labels match.
318+
//
319+
// It can be any label specified on both client and server workloads.
320+
// The following labels which have special semantic meaning are also supported:
321+
//
322+
// - `topology.istio.io/network` is used to match the network metadata of an endpoint, which can be specified by pod/namespace label `topology.istio.io/network`, sidecar env `ISTIO_META_NETWORK` or MeshNetworks.
323+
// - `topology.istio.io/cluster` is used to match the clusterID of an endpoint, which can be specified by pod label `topology.istio.io/cluster` or pod env `ISTIO_META_CLUSTER_ID`.
324+
// - `topology.kubernetes.io/region` is used to match the region metadata of an endpoint, which maps to Kubernetes node label `topology.kubernetes.io/region` or the deprecated label `failure-domain.beta.kubernetes.io/region`.
325+
// - `topology.kubernetes.io/zone` is used to match the zone metadata of an endpoint, which maps to Kubernetes node label `topology.kubernetes.io/zone` or the deprecated label `failure-domain.beta.kubernetes.io/zone`.
326+
// - `topology.istio.io/subzone` is used to match the subzone metadata of an endpoint, which maps to Istio node label `topology.istio.io/subzone`.
327+
//
328+
// The below topology config indicates the following priority levels:
329+
//
330+
// ```yaml
331+
// failoverPriority:
332+
// - "topology.istio.io/network"
333+
// - "topology.kubernetes.io/region"
334+
// - "topology.kubernetes.io/zone"
335+
// - "topology.istio.io/subzone"
336+
// ```
337+
//
338+
// 1. endpoints match same [network, region, zone, subzone] label with the client proxy have the highest priority.
339+
// 2. endpoints have same [network, region, zone] label but different [subzone] label with the client proxy have the second highest priority.
340+
// 3. endpoints have same [network, region] label but different [zone] label with the client proxy have the third highest priority.
341+
// 4. endpoints have same [network] but different [region] labels with the client proxy have the fourth highest priority.
342+
// 5. all the other endpoints have the same lowest priority.
343+
//
344+
// Optional: only one of distribute, failover or failoverPriority can be set.
345+
// And it should be used together with `OutlierDetection` to detect unhealthy endpoints, otherwise has no effect.
346+
FailoverPriority []string `json:"failover_priority,omitempty"`
347+
// enable locality load balancing, this is DestinationRule-level and will override mesh wide settings in entirety.
348+
// e.g. true means that turn on locality load balancing for this DestinationRule no matter what mesh wide settings is.
349+
Enabled bool `json:"enabled,omitempty"`
350+
}
351+
352+
// Describes how traffic originating in the 'from' zone or sub-zone is
353+
// distributed over a set of 'to' zones. Syntax for specifying a zone is
354+
// {region}/{zone}/{sub-zone} and terminal wildcards are allowed on any
355+
// segment of the specification. Examples:
356+
//
357+
// `*` - matches all localities
358+
//
359+
// `us-west/*` - all zones and sub-zones within the us-west region
360+
//
361+
// `us-west/zone-1/*` - all sub-zones within us-west/zone-1
362+
type Distribute struct {
363+
// Originating locality, '/' separated, e.g. 'region/zone/sub_zone'.
364+
From string `json:"from,omitempty"`
365+
// Map of upstream localities to traffic distribution weights. The sum of
366+
// all weights should be 100. Any locality not present will
367+
// receive no traffic.
368+
To map[string]uint32 `json:"to,omitempty"`
369+
}
370+
371+
// Specify the traffic failover policy across regions. Since zone and sub-zone
372+
// failover is supported by default this only needs to be specified for
373+
// regions when the operator needs to constrain traffic failover so that
374+
// the default behavior of failing over to any endpoint globally does not
375+
// apply. This is useful when failing over traffic across regions would not
376+
// improve service health or may need to be restricted for other reasons
377+
// like regulatory controls.
378+
type Failover struct {
379+
// Originating region.
380+
From string `json:"from,omitempty"`
381+
// Destination region the traffic will fail over to when endpoints in
382+
// the 'from' region becomes unhealthy.
383+
To string `json:"to,omitempty"`
246384
}
247385

248386
// Standard load balancing algorithms that require no tuning.

pkg/apis/istio/v1alpha3/zz_generated.deepcopy.go

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)