Skip to content
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

Cleanup on GameServer Controller #114

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pkg/gameservers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (c *Controller) creationHandler(review admv1beta1.AdmissionReview) (admv1be

// Run the GameServer controller. Will block until stop is closed.
// Runs threadiness number workers to process the rate limited queue
func (c Controller) Run(threadiness int, stop <-chan struct{}) error {
func (c *Controller) Run(threadiness int, stop <-chan struct{}) error {
c.logger.Info("Starting health check...")
go func() {
if err := c.server.ListenAndServe(); err != nil {
Expand Down Expand Up @@ -490,9 +490,9 @@ func (c *Controller) syncGameServerRequestReadyState(gs *stablev1alpha1.GameServ
if err != nil {
return gs, errors.Wrapf(err, "error getting pod for GameServer %s", gs.ObjectMeta.Name)
}
addr, err := c.Address(pod)
addr, err := c.address(pod)
if err != nil {
return gs, errors.Wrapf(err, "error getting external Address for GameServer %s", gs.ObjectMeta.Name)
return gs, errors.Wrapf(err, "error getting external address for GameServer %s", gs.ObjectMeta.Name)
}

gsCopy := gs.DeepCopy()
Expand All @@ -505,10 +505,10 @@ func (c *Controller) syncGameServerRequestReadyState(gs *stablev1alpha1.GameServ

gs, err = c.gameServerGetter.GameServers(gs.ObjectMeta.Namespace).Update(gsCopy)
if err != nil {
return gs, errors.Wrapf(err, "error setting Ready, Port and Address on GameServer %s Status", gs.ObjectMeta.Name)
return gs, errors.Wrapf(err, "error setting Ready, Port and address on GameServer %s Status", gs.ObjectMeta.Name)
}

c.recorder.Event(gs, corev1.EventTypeNormal, string(gs.Status.State), "Address and Port populated")
c.recorder.Event(gs, corev1.EventTypeNormal, string(gs.Status.State), "address and Port populated")
return gs, nil
}

Expand All @@ -530,7 +530,7 @@ func (c *Controller) syncGameServerShutdownState(gs *stablev1alpha1.GameServer)
}

// moveToErrorState moves the GameServer to the error state
func (c Controller) moveToErrorState(gs *stablev1alpha1.GameServer, msg string) (*stablev1alpha1.GameServer, error) {
func (c *Controller) moveToErrorState(gs *stablev1alpha1.GameServer, msg string) (*stablev1alpha1.GameServer, error) {
copy := gs.DeepCopy()
copy.Status.State = stablev1alpha1.Error

Expand Down Expand Up @@ -580,11 +580,11 @@ func (c *Controller) listGameServerPods(gs *stablev1alpha1.GameServer) ([]*corev
return result, nil
}

// Address returns the IP that the given Pod is being run on
// address returns the IP that the given Pod is being run on
// This should be the externalIP, but if the externalIP is
// not set, it will fall back to the internalIP with a warning.
// (basically because minikube only has an internalIP)
func (c Controller) Address(pod *corev1.Pod) (string, error) {
func (c *Controller) address(pod *corev1.Pod) (string, error) {
node, err := c.nodeLister.Get(pod.Spec.NodeName)
if err != nil {
return "", errors.Wrapf(err, "error retrieving node %s for Pod %s", node.ObjectMeta.Name, pod.ObjectMeta.Name)
Expand All @@ -604,12 +604,12 @@ func (c Controller) Address(pod *corev1.Pod) (string, error) {
}
}

return "", errors.Errorf("Could not find an Address for Node: %s", node.ObjectMeta.Name)
return "", errors.Errorf("Could not find an address for Node: %s", node.ObjectMeta.Name)
}

// waitForEstablishedCRD blocks until CRD comes to an Established state.
// Has a deadline of 60 seconds for this to occur.
func (c Controller) waitForEstablishedCRD() error {
func (c *Controller) waitForEstablishedCRD() error {
return wait.PollImmediate(500*time.Millisecond, 60*time.Second, func() (done bool, err error) {
crd, err := c.crdGetter.Get("gameservers.stable.agones.dev", metav1.GetOptions{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gameservers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) {
assert.Equal(t, gs.Spec.HostPort, gs.Status.Port)
assert.Equal(t, ipFixture, gs.Status.Address)
assert.Equal(t, node.ObjectMeta.Name, gs.Status.NodeName)
assert.Contains(t, <-mocks.fakeRecorder.Events, "Address and Port populated")
assert.Contains(t, <-mocks.fakeRecorder.Events, "address and Port populated")
})

for _, s := range []v1alpha1.State{"Unknown", v1alpha1.Unhealthy} {
Expand Down Expand Up @@ -738,7 +738,7 @@ func TestControllerAddress(t *testing.T) {
_, cancel := startInformers(mocks, c.gameServerSynced)
defer cancel()

addr, err := c.Address(&pod)
addr, err := c.address(&pod)
assert.Nil(t, err)
assert.Equal(t, fixture.expectedAddress, addr)
})
Expand Down