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

Add status subresource for FleetAutoscaler #730

Merged
merged 2 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
20 changes: 20 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (f *Framework) WaitForGameServerState(gs *v1alpha1.GameServer, state v1alph
}

// WaitForFleetCondition waits for the Fleet to be in a specific condition or fails the test if the condition can't be met in 5 minutes.
// nolint: dupl
markmandel marked this conversation as resolved.
Show resolved Hide resolved
func (f *Framework) WaitForFleetCondition(t *testing.T, flt *v1alpha1.Fleet, condition func(fleet *v1alpha1.Fleet) bool) {
t.Helper()
logrus.WithField("fleet", flt.Name).Info("waiting for fleet condition")
Expand All @@ -141,6 +142,25 @@ 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.
// nolint: dupl
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