-
Notifications
You must be signed in to change notification settings - Fork 816
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
Rolling updates for Fleets #213
Rolling updates for Fleets #213
Conversation
// rollingUpdateDeployment will do the rolling update of the old GameServers | ||
// through to the new ones, based on the fleet.Spec.Strategy.RollingUpdate configuration | ||
// and return the replica count for the active GameServerSet | ||
func (c *Controller) rollingUpdateDeployment(fleet *stablev1alpha1.Fleet, active *stablev1alpha1.GameServerSet, rest []*stablev1alpha1.GameServerSet) (int32, error) { |
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.
@enocom particularly love your eyes on this function, and the functions it calls - it's a bit complicated, so if you can see anything that could improve the code / readability, would definitely be interested.
c87fd20
to
678d5ed
Compare
Build Succeeded 👏 Build Id: afe860aa-044d-48d9-91d6-26c692369fb1 The following development artifacts have been built, and will exist for the next 30 days:
|
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.
There's an opportunity to move error-case checking into if blocks, and happy path code outside of if blocks to have a more idiomatic control flow, i.e., error code is indented, happy path is left most. Otherwise, LGTM.
pkg/fleets/controller.go
Outdated
func (c *Controller) rollingUpdateActive(fleet *stablev1alpha1.Fleet, active *stablev1alpha1.GameServerSet, rest []*stablev1alpha1.GameServerSet) (int32, error) { | ||
replicas := active.Spec.Replicas | ||
|
||
if active.Spec.Replicas < fleet.Spec.Replicas && active.Spec.Replicas == active.Status.Replicas { |
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.
I would invert this boolean expression such that the body becomes return replicas, nil
as on line 381 below. That way the control flow of the function handles errors within if statements and happy paths outside. Does that make sense?
pkg/fleets/controller.go
Outdated
unavailable := int32(r) | ||
|
||
for _, gsSet := range rest { | ||
if gsSet.Status.Replicas > 0 && gsSet.Status.Replicas == gsSet.Spec.Replicas { |
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.
Same thing here as above. If you invert the boolean check, your if statement can become much smaller with a continue in the body, and the code outside the if statement can be moved below, which makes understanding the flow easier.
678d5ed
to
b2d8fd0
Compare
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.
Excellent suggestions as always. PTAL - I think this is much easier to parse (assuming I got your intentions right)
func (c *Controller) rollingUpdateActive(fleet *stablev1alpha1.Fleet, active *stablev1alpha1.GameServerSet, rest []*stablev1alpha1.GameServerSet) (int32, error) { | ||
replicas := active.Spec.Replicas | ||
|
||
// if the active spec replicas are greater than or equal the fleet spec replicas, then we don't |
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.
@enocom made the inversion here, and also put in some text to help explain the logic. WDYT?
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.
Very nice. It takes a bit of getting used to, but the resulting code has a better flow with errors handled to the right.
for _, gsSet := range rest { | ||
// if the status.Replicas are less than or equal to 0, then that means we are done | ||
// scaling this GameServerSet down, and can therefore exit/move to the next one. | ||
if gsSet.Status.Replicas <= 0 { |
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.
@enocom the inversion here breaks this out into two sections, with slightly different logic - which I think is much easier to read 👍 and parse. WDYT?
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.
I think it reads better for sure. And the comments are very helpful.
Build Succeeded 👏 Build Id: 53a0801a-9358-4780-9643-ae87a11ceb48 The following development artifacts have been built, and will exist for the next 30 days:
|
pkg/fleets/controller.go
Outdated
if gsSet.Status.Replicas <= 0 { | ||
continue | ||
} | ||
// If the Status.Replicas does not equal the Status.Replicas for this GameServerSet, this means |
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.
If the Spec.Replicas
does not equal ...
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.
Good catch. Done!
This implements a configurable rolling update strategy for Fleets that also ensures that Allocated GameServers are not interuppted. Also includes updates to documentation. Closes googleforgames#70
b2d8fd0
to
d409691
Compare
Build Failed 😱 Build Id: 37ec19e1-73e1-4aa5-b516-fe707fade650 Build Logs
|
Build Succeeded 👏 Build Id: a9267b94-3a73-4d49-9642-169ba958de16 The following development artifacts have been built, and will exist for the next 30 days:
|
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.
It took me some time but LGTM!
This implements a configurable rolling update strategy for Fleets that also ensures that Allocated GameServers are not interrupted.
Also includes updates to documentation.
Closes #70