Skip to content

Commit 3757845

Browse files
committed
Cleanup on GameServer Controller
2 things: - Some controller methods weren't on the pointer. Changed them all to be consistent. - The `address` method was exported, when it didn't need to be
1 parent c4ac3a3 commit 3757845

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

pkg/gameservers/controller.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (c *Controller) creationHandler(review admv1beta1.AdmissionReview) (admv1be
217217

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

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

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

511-
c.recorder.Event(gs, corev1.EventTypeNormal, string(gs.Status.State), "Address and Port populated")
511+
c.recorder.Event(gs, corev1.EventTypeNormal, string(gs.Status.State), "address and Port populated")
512512
return gs, nil
513513
}
514514

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

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

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

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

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

610610
// waitForEstablishedCRD blocks until CRD comes to an Established state.
611611
// Has a deadline of 60 seconds for this to occur.
612-
func (c Controller) waitForEstablishedCRD() error {
612+
func (c *Controller) waitForEstablishedCRD() error {
613613
return wait.PollImmediate(500*time.Millisecond, 60*time.Second, func() (done bool, err error) {
614614
crd, err := c.crdGetter.Get("gameservers.stable.agones.dev", metav1.GetOptions{})
615615
if err != nil {

pkg/gameservers/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) {
637637
assert.Equal(t, gs.Spec.HostPort, gs.Status.Port)
638638
assert.Equal(t, ipFixture, gs.Status.Address)
639639
assert.Equal(t, node.ObjectMeta.Name, gs.Status.NodeName)
640-
assert.Contains(t, <-mocks.fakeRecorder.Events, "Address and Port populated")
640+
assert.Contains(t, <-mocks.fakeRecorder.Events, "address and Port populated")
641641
})
642642

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

741-
addr, err := c.Address(&pod)
741+
addr, err := c.address(&pod)
742742
assert.Nil(t, err)
743743
assert.Equal(t, fixture.expectedAddress, addr)
744744
})

0 commit comments

Comments
 (0)