Skip to content

Commit

Permalink
fix(MeshLoadBalancingStrategy): set all priorities equal if localityA…
Browse files Browse the repository at this point in the history
…ware is disabled (#11980)

We already set `priority: 1` for remote zones in
`fillRemoteMeshServices` so we need to explicitly set `priority: 0` if
we _don't_ want locality awareness.

Also fix an insufficient condition in an existing case, where we weren't
verifying that requests really go to all zones, only that it's OK if
they do.

Fixes #11968

Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont authored Nov 6, 2024
1 parent b42cf6a commit daed4c8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ func configureEndpoints(
}
}
}
if conf.LocalityAwareness != nil && pointer.Deref(conf.LocalityAwareness.Disabled) {
for _, cla := range endpoints {
for _, localityLbEndpoints := range cla.Endpoints {
if localityLbEndpoints.Locality != nil && localityLbEndpoints.Locality.Zone != localZone {
localityLbEndpoints.Priority = 0
}
}
}
}
return nil
}

Expand Down
38 changes: 36 additions & 2 deletions test/e2e_env/multizone/localityawarelb/meshmultizoneservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ spec:
testserver.WithMesh(meshName),
testserver.WithEchoArgs("echo", "--instance", "kube-test-server-1"),
)).
Install(democlient.Install(democlient.WithNamespace(namespace), democlient.WithMesh(meshName))).
SetupInGroup(multizone.KubeZone1, &group)

NewClusterSetup().
Expand Down Expand Up @@ -95,7 +96,9 @@ spec:
It("should fallback only to first zone", func() {
// given traffic to other zones
Eventually(responseFromInstance(multizone.KubeZone2), "30s", "1s").
MustPassRepeatedly(5).Should(Or(Equal("kube-test-server-1"), Equal("uni-test-server")))
Should(Equal("kube-test-server-1"))
Eventually(responseFromInstance(multizone.KubeZone2), "30s", "1s").
Should(Equal("uni-test-server"))

// when
policy := `
Expand All @@ -109,7 +112,7 @@ spec:
- targetRef:
kind: MeshMultiZoneService
labels:
kuma.io/display-name: test-server
kuma.io/display-name: test-server
default:
localityAwareness:
crossZone:
Expand All @@ -131,4 +134,35 @@ spec:
Eventually(responseFromInstance(multizone.KubeZone2), "30s", "1s").
MustPassRepeatedly(5).Should(Equal("kube-test-server-1"))
})

It("should be locality aware unless disabled", func() {
// given traffic only to the local zone
Eventually(responseFromInstance(multizone.KubeZone1), "30s", "1s").
MustPassRepeatedly(5).Should(Equal("kube-test-server-1"))

// when
policy := `
type: MeshLoadBalancingStrategy
name: mlb-mzms
mesh: mlb-mzms
spec:
targetRef:
kind: Mesh
to:
- targetRef:
kind: MeshMultiZoneService
labels:
kuma.io/display-name: test-server
default:
localityAwareness:
disabled: true
`
err := multizone.Global.Install(YamlUniversal(policy))

// then
Expect(err).ToNot(HaveOccurred())

Eventually(responseFromInstance(multizone.KubeZone1), "30s", "1s").
Should(Equal("uni-test-server"))
})
}

0 comments on commit daed4c8

Please sign in to comment.