-
Notifications
You must be signed in to change notification settings - Fork 817
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
Creating a FleetAllocation allocated a GameServer from a Fleet #193
Creating a FleetAllocation allocated a GameServer from a Fleet #193
Conversation
@@ -169,7 +168,7 @@ func (c *Controller) syncFleet(key string) error { | |||
return errors.Wrapf(err, "error retrieving fleet %s from namespace %s", name, namespace) | |||
} | |||
|
|||
list, err := c.listGameServerSets(fleet) | |||
list, err := ListGameServerSetsByFleetOwner(c.gameServerSetLister, fleet) |
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 would love to get your opinion on this refactor (implementation here)
There were several places I needed a list type function like this, and wasn't quite sure the best way to do it.
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.
See my response below.
Build Succeeded 👏 Build Id: 44021edf-184a-4e67-9594-49089cee089c The following development artifacts have been built, and will exist for the next 30 days:
|
} | ||
|
||
// Validateupdate validates when an update occurs | ||
func (fa *FleetAllocation) Validateupdate(new *FleetAllocation) (bool, []metav1.StatusCause) { |
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.
Nitpick: ValidateUpdate
pkg/fleetallocation/controller.go
Outdated
ErrNoGameServerReady = errors.New("Could not find a Ready GameServer") | ||
) | ||
|
||
// Controller is a the GameServerSet controller |
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.
FleetAllocation controller
LGTM! |
// ListGameServerSetsByFleetOwner lists all the GameServerSets for a given | ||
// Fleet | ||
func ListGameServerSetsByFleetOwner(gameServerSetLister listerv1alpha1.GameServerSetLister, f *stablev1alpha1.Fleet) ([]*stablev1alpha1.GameServerSet, error) { | ||
list, err := gameServerSetLister.List(labels.SelectorFromSet(labels.Set{stablev1alpha1.FleetGameServerSetLabel: f.ObjectMeta.Name})) |
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.
Based on a cursory reading of the code, I think you could even replace the concrete type *stablev1alpha1.Fleet
with a metav1.Object
interface. This way, the ListGameServerSetsByFleetOwner
function might enjoy an even wider usage.
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 you use the metav1.Object
interface here, then the name lookup becomes f.GetName()
as with the lookup below.
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.
So I personally wasn't concerned with the type - since in this case, I really only want Fleet
s to be passed in. So using a Fleet
as the type signature makes sense, at least in my mind - it should be restrictive.
I guess my concern was more around passing in the Lister
to the function as an argument (rather than somehow creating another data structure with methods). This felt more lightweight, but was wondering if you saw any issues there?
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've seen that pattern in some object-oriented code, but I'm having a hard time remembering what the pattern might be called. It seems entirely reasonable to me.
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.
SGTM! Thanks for the sanity check.
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's basically a form of double dispatch.
This implements the FleetAllocation CRD, that when created looks at the requested Fleet, and marks one of the GameServers as Allocated (if available) and returns it's value in the FleetAllocation. This also includes a quickstart and spec for reference as well. Some refactoring was included in the PR (probably should have been a seperate PR for that).
7a4079a
to
762b537
Compare
Build Succeeded 👏 Build Id: f4ab7fcb-c6b8-46c2-982a-42ad32ea92b4 The following development artifacts have been built, and will exist for the next 30 days:
|
Build Failed 😱 Build Id: 1c628f59-78a4-42f7-b8d7-23c553eebd76 Build Logs
|
This implements the FleetAllocation CRD, that when created looks at the requested Fleet, and marks one of the GameServers as Allocated (if available) and returns it's value in the FleetAllocation.
This also includes a quickstart and spec for reference as well.
Some refactoring was included in the PR (probably should have been a seperate PR for that).