-
Notifications
You must be signed in to change notification settings - Fork 813
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
Fix Rolling Update with Allocated GameServers #2420
Merged
markmandel
merged 18 commits into
googleforgames:main
from
WVerlaek:e2e-test-rolling-update
Mar 17, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0cf6565
e2e test to reproduce issue#2397
914910e
lint
7dba592
Fix: consider allocated replicas in rolling update
82609c9
Merge branch 'main' into e2e-test-rolling-update
markmandel 7829205
Merge branch 'main' into e2e-test-rolling-update
markmandel 088a1c8
Merge branch 'main' into e2e-test-rolling-update
9212fca
Fix test sometimes using empty fleet name
194f571
Cleanup
4431b6b
Merge branch 'main' into e2e-test-rolling-update
markmandel 8035a7c
Merge branch 'main' into e2e-test-rolling-update
2577696
Remove GetGameServer, refactor to use wait.PollUntil
f4ad90c
Reference fixture directly
cdc7d7e
Use require.NoError
a9b191e
Use require.Eventually
e67ceff
Use context + cancel instead of chan
452d292
Ctx first param
57bcd5f
Ignore wait timeout
6bf956c
Merge branch 'main' into e2e-test-rolling-update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,123 +222,187 @@ func TestFleetScaleUpEditAndScaleDown(t *testing.T) { | |
func TestFleetRollingUpdate(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
// Use scaleFleetPatch (true) or scaleFleetSubresource (false) | ||
fixtures := []bool{true, false} | ||
maxSurge := []string{"25%", "10%"} | ||
fixtures := []struct { | ||
// Use scaleFleetPatch (true) or scaleFleetSubresource (false) | ||
usePatch bool | ||
maxSurge string | ||
// If true, create and cycle GS Allocations when triggering a rolling update: | ||
// - Repeatedly allocate and shutdown GameServers (keeping ~50% of the Fleet in an Allocated state). | ||
// - Once 50% of the Fleet is Allocated, trigger the rolling update. | ||
// - Keep allocating/shutting down GameServers, to allocate in both the old and new GSSets. | ||
// - Verify the rolling update completes. | ||
// This simulates updating a Fleet that is live/in-use, and reproduces an issue where allocated GameServers | ||
// causes a rolling update to get stuck and keep the old GameServerSet up. | ||
cycleAllocations bool | ||
}{ | ||
{ | ||
usePatch: true, | ||
maxSurge: "25%", | ||
cycleAllocations: false, | ||
}, | ||
{ | ||
usePatch: true, | ||
maxSurge: "10%", | ||
cycleAllocations: false, | ||
}, | ||
{ | ||
usePatch: false, | ||
maxSurge: "25%", | ||
cycleAllocations: false, | ||
}, | ||
{ | ||
usePatch: false, | ||
maxSurge: "10%", | ||
cycleAllocations: false, | ||
}, | ||
{ | ||
usePatch: true, | ||
maxSurge: "25%", | ||
cycleAllocations: true, | ||
}, | ||
} | ||
for i := range fixtures { | ||
fixture := fixtures[i] | ||
t.Run(fmt.Sprintf("Use fleet Patch %t %s cycle %t", fixture.usePatch, fixture.maxSurge, fixture.cycleAllocations), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, usePatch := range fixtures { | ||
for _, maxSurgeParam := range maxSurge { | ||
usePatch := usePatch | ||
maxSurgeParam := maxSurgeParam | ||
t.Run(fmt.Sprintf("Use fleet Patch %t %s", usePatch, maxSurgeParam), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
client := framework.AgonesClient.AgonesV1() | ||
|
||
flt := defaultFleet(framework.Namespace) | ||
flt.ApplyDefaults() | ||
flt.Spec.Replicas = 1 | ||
rollingUpdatePercent := intstr.FromString(maxSurgeParam) | ||
flt.Spec.Strategy.RollingUpdate.MaxSurge = &rollingUpdatePercent | ||
flt.Spec.Strategy.RollingUpdate.MaxUnavailable = &rollingUpdatePercent | ||
|
||
flt, err := client.Fleets(framework.Namespace).Create(ctx, flt, metav1.CreateOptions{}) | ||
if assert.Nil(t, err) { | ||
defer client.Fleets(framework.Namespace).Delete(ctx, flt.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint:errcheck | ||
} | ||
client := framework.AgonesClient.AgonesV1() | ||
|
||
assert.Equal(t, int32(1), flt.Spec.Replicas) | ||
assert.Equal(t, maxSurgeParam, flt.Spec.Strategy.RollingUpdate.MaxSurge.StrVal) | ||
assert.Equal(t, maxSurgeParam, flt.Spec.Strategy.RollingUpdate.MaxUnavailable.StrVal) | ||
flt := defaultFleet(framework.Namespace) | ||
flt.ApplyDefaults() | ||
flt.Spec.Replicas = 1 | ||
rollingUpdatePercent := intstr.FromString(fixture.maxSurge) | ||
flt.Spec.Strategy.RollingUpdate.MaxSurge = &rollingUpdatePercent | ||
flt.Spec.Strategy.RollingUpdate.MaxUnavailable = &rollingUpdatePercent | ||
|
||
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas)) | ||
flt, err := client.Fleets(framework.Namespace).Create(ctx, flt, metav1.CreateOptions{}) | ||
require.NoError(t, err) | ||
defer client.Fleets(framework.Namespace).Delete(ctx, flt.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint:errcheck | ||
|
||
// scale up | ||
const targetScale = 8 | ||
if usePatch { | ||
flt = scaleFleetPatch(ctx, t, flt, targetScale) | ||
assert.Equal(t, int32(targetScale), flt.Spec.Replicas) | ||
} else { | ||
flt = scaleFleetSubresource(ctx, t, flt, targetScale) | ||
} | ||
assert.Equal(t, int32(1), flt.Spec.Replicas) | ||
assert.Equal(t, fixture.maxSurge, flt.Spec.Strategy.RollingUpdate.MaxSurge.StrVal) | ||
assert.Equal(t, fixture.maxSurge, flt.Spec.Strategy.RollingUpdate.MaxUnavailable.StrVal) | ||
|
||
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(targetScale)) | ||
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas)) | ||
|
||
flt, err = client.Fleets(framework.Namespace).Get(ctx, flt.ObjectMeta.GetName(), metav1.GetOptions{}) | ||
assert.NoError(t, err) | ||
// scale up | ||
const targetScale = 8 | ||
if fixture.usePatch { | ||
flt = scaleFleetPatch(ctx, t, flt, targetScale) | ||
assert.Equal(t, int32(targetScale), flt.Spec.Replicas) | ||
} else { | ||
flt = scaleFleetSubresource(ctx, t, flt, targetScale) | ||
} | ||
|
||
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(targetScale)) | ||
|
||
flt, err = client.Fleets(framework.Namespace).Get(ctx, flt.ObjectMeta.GetName(), metav1.GetOptions{}) | ||
require.NoError(t, err) | ||
|
||
cycleCtx, cancelCycle := context.WithCancel(ctx) | ||
defer cancelCycle() | ||
if fixture.cycleAllocations { | ||
// Repeatedly cycle allocations to keep ~half of the GameServers Allocated. Repeatedly Allocate and | ||
// delete such that both the old and new GSSet contain allocated GameServers. | ||
const halfScale = targetScale / 2 | ||
const period = 3 * time.Second | ||
go framework.CycleAllocations(cycleCtx, t, flt, period, period*halfScale) | ||
|
||
// Wait for at least half of the fleet to have be cycled (either Allocated or shutting down) | ||
// before updating the fleet. | ||
err = framework.WaitForFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { | ||
return fleet.Status.ReadyReplicas < halfScale | ||
}) | ||
} | ||
|
||
// Change ContainerPort to trigger creating a new GSSet | ||
// Change ContainerPort to trigger creating a new GSSet. Retry in case of a conflict. | ||
fltName := flt.GetName() | ||
require.Eventually(t, func() bool { | ||
flt, err = client.Fleets(framework.Namespace).Get(ctx, fltName, metav1.GetOptions{}) | ||
require.NoError(t, err) | ||
fltCopy := flt.DeepCopy() | ||
fltCopy.Spec.Template.Spec.Ports[0].ContainerPort++ | ||
flt, err = client.Fleets(framework.Namespace).Update(ctx, fltCopy, metav1.UpdateOptions{}) | ||
assert.NoError(t, err) | ||
return err == nil | ||
}, time.Minute, time.Second) | ||
|
||
selector := labels.SelectorFromSet(labels.Set{agonesv1.FleetNameLabel: flt.ObjectMeta.Name}) | ||
// New GSS was created | ||
err = wait.PollImmediate(1*time.Second, 30*time.Second, func() (bool, error) { | ||
gssList, err := framework.AgonesClient.AgonesV1().GameServerSets(framework.Namespace).List(ctx, | ||
metav1.ListOptions{LabelSelector: selector.String()}) | ||
if err != nil { | ||
return false, err | ||
} | ||
return len(gssList.Items) == 2, nil | ||
}) | ||
assert.NoError(t, err) | ||
// Check that total number of gameservers in the system does not exceed the RollingUpdate | ||
// parameters (creating no more than maxSurge, deleting maxUnavailable servers at a time) | ||
// Wait for old GSSet to be deleted | ||
err = wait.PollImmediate(1*time.Second, 5*time.Minute, func() (bool, error) { | ||
list, err := framework.AgonesClient.AgonesV1().GameServers(framework.Namespace).List(ctx, | ||
metav1.ListOptions{LabelSelector: selector.String()}) | ||
if err != nil { | ||
return false, err | ||
} | ||
selector := labels.SelectorFromSet(labels.Set{agonesv1.FleetNameLabel: flt.ObjectMeta.Name}) | ||
// New GSS was created | ||
err = wait.PollImmediate(1*time.Second, 30*time.Second, func() (bool, error) { | ||
gssList, err := framework.AgonesClient.AgonesV1().GameServerSets(framework.Namespace).List(ctx, | ||
metav1.ListOptions{LabelSelector: selector.String()}) | ||
if err != nil { | ||
return false, err | ||
} | ||
return len(gssList.Items) == 2, nil | ||
}) | ||
assert.NoError(t, err) | ||
// Check that total number of gameservers in the system does not exceed the RollingUpdate | ||
// parameters (creating no more than maxSurge, deleting maxUnavailable servers at a time) | ||
// Wait for old GSSet to be deleted | ||
err = wait.PollImmediate(1*time.Second, 5*time.Minute, func() (bool, error) { | ||
list, err := framework.AgonesClient.AgonesV1().GameServers(framework.Namespace).List(ctx, | ||
metav1.ListOptions{LabelSelector: selector.String()}) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
maxSurge, err := intstr.GetValueFromIntOrPercent(flt.Spec.Strategy.RollingUpdate.MaxSurge, int(flt.Spec.Replicas), true) | ||
assert.Nil(t, err) | ||
maxSurge, err := intstr.GetValueFromIntOrPercent(flt.Spec.Strategy.RollingUpdate.MaxSurge, int(flt.Spec.Replicas), true) | ||
assert.Nil(t, err) | ||
|
||
roundUp := false | ||
maxUnavailable, err := intstr.GetValueFromIntOrPercent(flt.Spec.Strategy.RollingUpdate.MaxUnavailable, int(flt.Spec.Replicas), roundUp) | ||
roundUp := false | ||
maxUnavailable, err := intstr.GetValueFromIntOrPercent(flt.Spec.Strategy.RollingUpdate.MaxUnavailable, int(flt.Spec.Replicas), roundUp) | ||
|
||
if maxUnavailable == 0 { | ||
maxUnavailable = 1 | ||
} | ||
// This difference is inevitable, also could be seen with Deployments and ReplicaSets | ||
shift := maxUnavailable | ||
assert.Nil(t, err) | ||
if maxUnavailable == 0 { | ||
maxUnavailable = 1 | ||
} | ||
// This difference is inevitable, also could be seen with Deployments and ReplicaSets | ||
shift := maxUnavailable | ||
assert.Nil(t, err) | ||
|
||
expectedTotal := targetScale + maxSurge + maxUnavailable + shift | ||
if len(list.Items) > expectedTotal { | ||
err = fmt.Errorf("new replicas should be less than target + maxSurge + maxUnavailable + shift. Replicas: %d, Expected: %d", len(list.Items), expectedTotal) | ||
} | ||
if err != nil { | ||
return false, err | ||
} | ||
gssList, err := framework.AgonesClient.AgonesV1().GameServerSets(framework.Namespace).List(ctx, | ||
metav1.ListOptions{LabelSelector: selector.String()}) | ||
if err != nil { | ||
return false, err | ||
// Ignore any GameServers that are shutting down (resulting from Allocation cycling). | ||
shuttingDown := 0 | ||
for _, gs := range list.Items { | ||
if gs.IsBeingDeleted() { | ||
shuttingDown++ | ||
} | ||
return len(gssList.Items) == 1, nil | ||
}) | ||
} | ||
Comment on lines
+363
to
+369
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added this, which ignores gameservers that are shutting down when checking if the total number of gameservers doesn't exceed the expected total. Needed when cycling allocations is enabled |
||
expectedTotal := targetScale + maxSurge + maxUnavailable + shift + shuttingDown | ||
if len(list.Items) > expectedTotal { | ||
err = fmt.Errorf("new replicas should be less than target + maxSurge + maxUnavailable + shift + shuttingDown. Replicas: %d, Expected: %d", len(list.Items), expectedTotal) | ||
} | ||
if err != nil { | ||
return false, err | ||
} | ||
gssList, err := framework.AgonesClient.AgonesV1().GameServerSets(framework.Namespace).List(ctx, | ||
metav1.ListOptions{LabelSelector: selector.String()}) | ||
if err != nil { | ||
return false, err | ||
} | ||
return len(gssList.Items) == 1, nil | ||
}) | ||
|
||
assert.NoError(t, err) | ||
assert.NoError(t, err) | ||
|
||
// scale down, with allocation | ||
const scaleDownTarget = 1 | ||
if usePatch { | ||
flt = scaleFleetPatch(ctx, t, flt, scaleDownTarget) | ||
} else { | ||
flt = scaleFleetSubresource(ctx, t, flt, scaleDownTarget) | ||
} | ||
// Stop cycling Allocations. | ||
// The AssertFleetConditions below will wait until the Allocation cycling has | ||
// fully stopped (when all Allocated GameServers are shut down). | ||
cancelCycle() | ||
|
||
// scale down, with allocation | ||
const scaleDownTarget = 1 | ||
if fixture.usePatch { | ||
flt = scaleFleetPatch(ctx, t, flt, scaleDownTarget) | ||
} else { | ||
flt = scaleFleetSubresource(ctx, t, flt, scaleDownTarget) | ||
} | ||
|
||
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(1)) | ||
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(1)) | ||
|
||
framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { | ||
return fleet.Status.AllocatedReplicas == 0 | ||
}) | ||
framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { | ||
return fleet.Status.AllocatedReplicas == 0 | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first 4 are the original fixtures, added a single 5th fixture that cycles allocations during the rolling update