Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(kuma-cp): add weights to xds.Cluster interface #6844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/plugins/policies/xds/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
type Cluster struct {
service string
name string
weight uint32
tags tags.Tags
mesh string
isExternalService bool
}

func (c *Cluster) Service() string { return c.service }
func (c *Cluster) Name() string { return c.name }
func (c *Cluster) Weight() uint32 { return c.weight }
func (c *Cluster) Tags() tags.Tags { return c.tags }

// Mesh returns a non-empty string only if the cluster is in a different mesh
Expand All @@ -41,7 +43,7 @@ type ClusterBuilder struct {
}

func NewClusterBuilder() *ClusterBuilder {
return &ClusterBuilder{}
return (&ClusterBuilder{}).WithWeight(1)
bartsmykla marked this conversation as resolved.
Show resolved Hide resolved
}

func (b *ClusterBuilder) Build() *Cluster {
Expand Down Expand Up @@ -75,6 +77,13 @@ func (b *ClusterBuilder) WithName(name string) *ClusterBuilder {
return b
}

func (b *ClusterBuilder) WithWeight(weight uint32) *ClusterBuilder {
b.opts = append(b.opts, newClusterOptFunc(func(cluster *Cluster) {
cluster.weight = weight
}))
return b
}

func (b *ClusterBuilder) WithMesh(mesh string) *ClusterBuilder {
b.opts = append(b.opts, newClusterOptFunc(func(cluster *Cluster) {
cluster.mesh = mesh
Expand Down
3 changes: 1 addition & 2 deletions pkg/xds/envoy/listeners/v3/tcp_proxy_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func (c *TcpProxyConfigurer) tcpProxy() *envoy_tcp.TcpProxy {
}

var weightedClusters []*envoy_tcp.TcpProxy_WeightedCluster_ClusterWeight
for _, cl := range c.Clusters {
cluster := cl.(*envoy_common.ClusterImpl)
for _, cluster := range c.Clusters {
weightedCluster := &envoy_tcp.TcpProxy_WeightedCluster_ClusterWeight{
Name: cluster.Name(),
Weight: cluster.Weight(),
Expand Down
1 change: 1 addition & 0 deletions pkg/xds/envoy/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type Cluster interface {
Service() string
Name() string
Weight() uint32
Mesh() string
Tags() tags.Tags
Hash() string
Expand Down