diff --git a/install/helm/agones/templates/crds/fleetautoscaler.yaml b/install/helm/agones/templates/crds/fleetautoscaler.yaml index 8f8394089b..819233dc3d 100644 --- a/install/helm/agones/templates/crds/fleetautoscaler.yaml +++ b/install/helm/agones/templates/crds/fleetautoscaler.yaml @@ -78,4 +78,7 @@ spec: type: string url: type: string + subresources: + # status enables the status subresource. + status: {} {{- end }} diff --git a/install/helm/agones/templates/serviceaccounts/controller.yaml b/install/helm/agones/templates/serviceaccounts/controller.yaml index 4b85f03bf4..6e82c8e83c 100644 --- a/install/helm/agones/templates/serviceaccounts/controller.yaml +++ b/install/helm/agones/templates/serviceaccounts/controller.yaml @@ -52,9 +52,6 @@ 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"] @@ -62,7 +59,7 @@ rules: 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"] --- diff --git a/install/yaml/install.yaml b/install/yaml/install.yaml index c845e321ed..86c70dad79 100644 --- a/install/yaml/install.yaml +++ b/install/yaml/install.yaml @@ -50,9 +50,6 @@ 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"] @@ -60,7 +57,7 @@ rules: 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"] --- @@ -517,6 +514,9 @@ spec: type: string url: type: string + subresources: + # status enables the status subresource. + status: {} --- # Source: agones/templates/crds/gameserver.yaml diff --git a/pkg/fleetautoscalers/controller.go b/pkg/fleetautoscalers/controller.go index d781efb7cb..feb878d930 100644 --- a/pkg/fleetautoscalers/controller.go +++ b/pkg/fleetautoscalers/controller.go @@ -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) } @@ -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) } diff --git a/test/e2e/fleetautoscaler_test.go b/test/e2e/fleetautoscaler_test.go index b125177a84..32fd114224 100644 --- a/test/e2e/fleetautoscaler_test.go +++ b/test/e2e/fleetautoscaler_test.go @@ -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}) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 775a97ad85..919173f00c 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -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 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") @@ -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