Skip to content

Commit

Permalink
Add status subresource for Fleetautoscaler
Browse files Browse the repository at this point in the history
Updated serviceaccounts permissions accordingly. Added E2E test of
fleetautoscaler status update.
  • Loading branch information
aLekSer committed Apr 19, 2019
1 parent d69fe68 commit 3efc85b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
3 changes: 3 additions & 0 deletions install/helm/agones/templates/crds/fleetautoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ spec:
type: string
url:
type: string
subresources:
# status enables the status subresource.
status: {}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ rules:
- apiGroups: ["stable.agones.dev"]
resources: ["gameservers", "gameserversets"]
verbs: ["create", "delete", "get", "list", "update", "watch"]
- apiGroups: ["stable.agones.dev"]
resources: ["gameserversets/status"]
verbs: ["update"]
- apiGroups: ["stable.agones.dev"]
resources: ["gameservers"]
verbs: ["patch"]
- apiGroups: ["stable.agones.dev"]
resources: ["fleets", "fleetallocations", "fleetautoscalers"]
verbs: ["get", "list", "update", "watch"]
- apiGroups: ["stable.agones.dev"]
resources: ["fleets/status"]
resources: ["fleets/status", "fleetautoscalers/status", "gameserversets/status"]
verbs: ["update"]

---
Expand Down
8 changes: 4 additions & 4 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,14 @@ rules:
- apiGroups: ["stable.agones.dev"]
resources: ["gameservers", "gameserversets"]
verbs: ["create", "delete", "get", "list", "update", "watch"]
- apiGroups: ["stable.agones.dev"]
resources: ["gameserversets/status"]
verbs: ["update"]
- apiGroups: ["stable.agones.dev"]
resources: ["gameservers"]
verbs: ["patch"]
- apiGroups: ["stable.agones.dev"]
resources: ["fleets", "fleetallocations", "fleetautoscalers"]
verbs: ["get", "list", "update", "watch"]
- apiGroups: ["stable.agones.dev"]
resources: ["fleets/status"]
resources: ["fleets/status", "fleetautoscalers/status", "gameserversets/status"]
verbs: ["update"]

---
Expand Down Expand Up @@ -517,6 +514,9 @@ spec:
type: string
url:
type: string
subresources:
# status enables the status subresource.
status: {}

---
# Source: agones/templates/crds/gameserver.yaml
Expand Down
4 changes: 2 additions & 2 deletions pkg/fleetautoscalers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (c *Controller) updateStatus(fas *stablev1alpha1.FleetAutoscaler, currentRe
c.recorder.Eventf(fas, corev1.EventTypeWarning, "ScalingLimited", "Scaling fleet %s was limited to maximum size of %d", fas.Spec.FleetName, desiredReplicas)
}

_, err := c.fleetAutoscalerGetter.FleetAutoscalers(fas.ObjectMeta.Namespace).Update(fasCopy)
_, err := c.fleetAutoscalerGetter.FleetAutoscalers(fas.ObjectMeta.Namespace).UpdateStatus(fasCopy)
if err != nil {
return errors.Wrapf(err, "error updating status for fleetautoscaler %s", fas.ObjectMeta.Name)
}
Expand All @@ -276,7 +276,7 @@ func (c *Controller) updateStatusUnableToScale(fas *stablev1alpha1.FleetAutoscal
fasCopy.Status.DesiredReplicas = 0

if !apiequality.Semantic.DeepEqual(fas.Status, fasCopy.Status) {
_, err := c.fleetAutoscalerGetter.FleetAutoscalers(fas.ObjectMeta.Namespace).Update(fasCopy)
_, err := c.fleetAutoscalerGetter.FleetAutoscalers(fas.ObjectMeta.Namespace).UpdateStatus(fasCopy)
if err != nil {
return errors.Wrapf(err, "error updating status for fleetautoscaler %s", fas.ObjectMeta.Name)
}
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ func TestAutoscalerBasicFunctions(t *testing.T) {
//10% with only one allocated GS means only one ready server
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(1))

// get the Status of the fleetautoscaler
fas, err = framework.AgonesClient.StableV1alpha1().FleetAutoscalers(fas.ObjectMeta.Namespace).Get(fas.Name, metav1.GetOptions{})
assert.Nil(t, err, "could not get fleetautoscaler")
assert.True(t, fas.Status.AbleToScale, "Could not get AbleToScale status")

// check that we are able to scale
framework.WaitForFleetAutoScalerCondition(t, fas, func(fas *v1alpha1.FleetAutoscaler) bool {
return fas.Status.ScalingLimited == false
})

// patch autoscaler to a maxReplicas count equal to current replicas count
_, err = patchFleetAutoscaler(fas, intstr.FromInt(1), 1, 1)
assert.Nil(t, err, "could not patch fleetautoscaler")

// check that we are not able to scale
framework.WaitForFleetAutoScalerCondition(t, fas, func(fas *v1alpha1.FleetAutoscaler) bool {
return fas.Status.ScalingLimited == true
})

// delete the allocated GameServer and watch the fleet scale down
gp := int64(1)
err = alpha1.GameServers(defaultNs).Delete(fa.Status.GameServer.ObjectMeta.Name, &metav1.DeleteOptions{GracePeriodSeconds: &gp})
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ func (f *Framework) WaitForFleetCondition(t *testing.T, flt *v1alpha1.Fleet, con
}
}

// WaitForFleetAutoScalerCondition waits for the FleetAutoscaler to be in a specific condition or fails the test if the condition can't be met in 2 minutes.
func (f *Framework) WaitForFleetAutoScalerCondition(t *testing.T, fas *v1alpha1.FleetAutoscaler, condition func(fas *v1alpha1.FleetAutoscaler) bool) {
t.Helper()
logrus.WithField("fleetautoscaler", fas.Name).Info("waiting for fleetautoscaler condition")
err := wait.PollImmediate(2*time.Second, 2*time.Minute, func() (bool, error) {
fleetautoscaler, err := f.AgonesClient.StableV1alpha1().FleetAutoscalers(fas.ObjectMeta.Namespace).Get(fas.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
return true, err
}

return condition(fleetautoscaler), nil
})
if err != nil {
logrus.WithField("fleetautoscaler", fas.Name).WithError(err).Info("error waiting for fleetautoscaler condition")
t.Fatalf("error waiting for fleetautoscaler condition on fleetautoscaler %v", fas.Name)
}
}

// ListGameServersFromFleet lists GameServers from a particular fleet
func (f *Framework) ListGameServersFromFleet(flt *v1alpha1.Fleet) ([]v1alpha1.GameServer, error) {
var results []v1alpha1.GameServer
Expand Down

0 comments on commit 3efc85b

Please sign in to comment.