Skip to content

Commit

Permalink
fix(kuma-cp): change affinityTag field in MeshLoadBalancingStrategy t…
Browse files Browse the repository at this point in the history
…o optional



Signed-off-by: Marcin Skalski <[email protected]>
  • Loading branch information
Automaat authored Nov 8, 2023
1 parent a9a165b commit 0ba1eb9
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2151,8 +2151,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,8 +2151,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2355,8 +2355,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2171,8 +2171,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
2 changes: 0 additions & 2 deletions app/kumactl/cmd/install/testdata/install-crds.all.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3456,8 +3456,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3660,8 +3660,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
2 changes: 0 additions & 2 deletions docs/generated/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4126,8 +4126,6 @@ components:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type LocalityAwareness struct {

type LocalZone struct {
// AffinityTags list of tags for local zone load balancing.
AffinityTags []AffinityTag `json:"affinityTags"`
AffinityTags *[]AffinityTag `json:"affinityTags,omitempty"`
}

type AffinityTag struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ properties:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
common_api "github.com/kumahq/kuma/api/common/v1alpha1"
"github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/core/validators"
"github.com/kumahq/kuma/pkg/util/pointer"
)

func (r *MeshLoadBalancingStrategyResource) validate() error {
Expand Down Expand Up @@ -71,7 +72,7 @@ func validateLocalZone(localZone *LocalZone) validators.ValidationError {
}

var weightSpecified int
for idx, affinityTag := range localZone.AffinityTags {
for idx, affinityTag := range pointer.Deref(localZone.AffinityTags) {
path := validators.RootedAt("affinityTags").Index(idx)
if affinityTag.Key == "" {
verr.AddViolationAt(path.Field("key"), validators.MustNotBeEmpty)
Expand All @@ -82,7 +83,7 @@ func validateLocalZone(localZone *LocalZone) validators.ValidationError {
}
}

if weightSpecified > 0 && weightSpecified != len(localZone.AffinityTags) {
if weightSpecified > 0 && weightSpecified != len(pointer.Deref(localZone.AffinityTags)) {
verr.AddViolation("affinityTags", "all or none affinity tags should have weight")
}
return verr
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ spec:
- key
type: object
type: array
required:
- affinityTags
type: object
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,5 @@ func (p plugin) configureCluster(c *envoy_cluster.Cluster, config api.Conf) erro
}

func shouldUseLocalityWeightedLb(config api.Conf) bool {
return config.LocalityAwareness != nil && config.LocalityAwareness.LocalZone != nil && len(config.LocalityAwareness.LocalZone.AffinityTags) > 0
return config.LocalityAwareness != nil && config.LocalityAwareness.LocalZone != nil && len(pointer.Deref(config.LocalityAwareness.LocalZone.AffinityTags)) > 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
},
LocalityAwareness: &v1alpha1.LocalityAwareness{
LocalZone: &v1alpha1.LocalZone{
AffinityTags: []v1alpha1.AffinityTag{
AffinityTags: &[]v1alpha1.AffinityTag{
{
Key: "k8s.io/node",
Weight: pointer.To[uint32](9000),
Expand Down Expand Up @@ -520,7 +520,7 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
},
LocalityAwareness: &v1alpha1.LocalityAwareness{
LocalZone: &v1alpha1.LocalZone{
AffinityTags: []v1alpha1.AffinityTag{
AffinityTags: &[]v1alpha1.AffinityTag{
{
Key: "k8s.io/node",
Weight: pointer.To[uint32](9000),
Expand Down Expand Up @@ -649,7 +649,7 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
},
LocalityAwareness: &v1alpha1.LocalityAwareness{
LocalZone: &v1alpha1.LocalZone{
AffinityTags: []v1alpha1.AffinityTag{
AffinityTags: &[]v1alpha1.AffinityTag{
{
Key: "k8s.io/node",
Weight: pointer.To[uint32](9000),
Expand Down Expand Up @@ -721,7 +721,7 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
},
LocalityAwareness: &v1alpha1.LocalityAwareness{
LocalZone: &v1alpha1.LocalZone{
AffinityTags: []v1alpha1.AffinityTag{
AffinityTags: &[]v1alpha1.AffinityTag{
{
Key: "k8s.io/node",
Weight: pointer.To[uint32](9000),
Expand Down Expand Up @@ -853,7 +853,7 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
},
LocalityAwareness: &v1alpha1.LocalityAwareness{
LocalZone: &v1alpha1.LocalZone{
AffinityTags: []v1alpha1.AffinityTag{
AffinityTags: &[]v1alpha1.AffinityTag{
{
Key: "k8s.io/node",
Weight: pointer.To[uint32](9000),
Expand Down Expand Up @@ -1205,7 +1205,7 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
},
LocalityAwareness: &v1alpha1.LocalityAwareness{
LocalZone: &v1alpha1.LocalZone{
AffinityTags: []v1alpha1.AffinityTag{
AffinityTags: &[]v1alpha1.AffinityTag{
{
Key: "k8s.io/node",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func GetLocalityGroups(conf *api.Conf, inboundTags mesh_proto.MultiValueTagSet,
func getLocalLbGroups(conf *api.Conf, inboundTags mesh_proto.MultiValueTagSet) []LocalLbGroup {
var localGroups []LocalLbGroup
if conf.LocalityAwareness.LocalZone != nil {
rulesLen := len(conf.LocalityAwareness.LocalZone.AffinityTags)
for i, tag := range conf.LocalityAwareness.LocalZone.AffinityTags {
rulesLen := len(pointer.Deref(conf.LocalityAwareness.LocalZone.AffinityTags))
for i, tag := range pointer.Deref(conf.LocalityAwareness.LocalZone.AffinityTags) {
values := inboundTags.Values(tag.Key)
// when weights are not provided we are generating weights by ourselves
// the first rule has the highest priority which is 9 * 10^(number of rules - rules position -1)
Expand Down

0 comments on commit 0ba1eb9

Please sign in to comment.