diff --git a/pkg/apis/stable/v1alpha1/gameserverset.go b/pkg/apis/stable/v1alpha1/gameserverset.go index adfa7155f2..e94aa424b1 100644 --- a/pkg/apis/stable/v1alpha1/gameserverset.go +++ b/pkg/apis/stable/v1alpha1/gameserverset.go @@ -74,6 +74,8 @@ type GameServerSetStatus struct { ReservedReplicas int32 `json:"reservedReplicas"` // AllocatedReplicas are the number of Allocated GameServer replicas AllocatedReplicas int32 `json:"allocatedReplicas"` + // ShutdownReplicas are the number of Shutdown GameServers replicas + ShutdownReplicas int32 `json:"shutdownReplicas"` } // ValidateUpdate validates when updates occur. The argument diff --git a/pkg/fleets/controller.go b/pkg/fleets/controller.go index 5807c315c9..bd58fdac52 100644 --- a/pkg/fleets/controller.go +++ b/pkg/fleets/controller.go @@ -16,6 +16,7 @@ package fleets import ( "encoding/json" + "fmt" "reflect" "agones.dev/agones/pkg/apis/stable" @@ -348,6 +349,7 @@ func (c *Controller) upsertGameServerSet(fleet *stablev1alpha1.Fleet, active *st func (c *Controller) applyDeploymentStrategy(fleet *stablev1alpha1.Fleet, active *stablev1alpha1.GameServerSet, rest []*stablev1alpha1.GameServerSet) (int32, error) { // if there is nothing `rest`, then it's either brand Fleet, or we can just jump to the fleet value, // since there is nothing else scaling down at this point + if len(rest) == 0 { return fleet.Spec.Replicas, nil } @@ -367,7 +369,7 @@ func (c *Controller) applyDeploymentStrategy(fleet *stablev1alpha1.Fleet, active func (c *Controller) deleteEmptyGameServerSets(fleet *stablev1alpha1.Fleet, list []*stablev1alpha1.GameServerSet) error { p := metav1.DeletePropagationBackground for _, gsSet := range list { - if gsSet.Status.Replicas == 0 { + if gsSet.Status.Replicas == 0 && gsSet.Status.ShutdownReplicas == 0 { err := c.gameServerSetGetter.GameServerSets(gsSet.ObjectMeta.Namespace).Delete(gsSet.ObjectMeta.Name, &metav1.DeleteOptions{PropagationPolicy: &p}) if err != nil { return errors.Wrapf(err, "error updating gameserverset %s", gsSet.ObjectMeta.Name) @@ -475,27 +477,30 @@ func (c *Controller) rollingUpdateRest(fleet *stablev1alpha1.Fleet, rest []*stab if gsSet.Status.Replicas <= 0 { continue } + // If the Spec.Replicas does not equal the Status.Replicas for this GameServerSet, this means // that the rolling down process is currently ongoing, and we should therefore exit so we can wait for it to finish if gsSet.Spec.Replicas != gsSet.Status.Replicas { break } - gsSetCopy := gsSet.DeepCopy() - gsSetCopy.Spec.Replicas = fleet.LowerBoundReplicas(gsSetCopy.Spec.Replicas - unavailable) + if gsSet.Status.ShutdownReplicas == 0 { + gsSetCopy.Spec.Replicas = fleet.LowerBoundReplicas(gsSetCopy.Spec.Replicas - unavailable) - c.loggerForFleet(fleet).WithField("gameserverset", gsSet.ObjectMeta.Name).WithField("replicas", gsSetCopy.Spec.Replicas). - Info("applying rolling update to inactive gameserverset") + c.loggerForFleet(fleet).Info(fmt.Sprintf("Shutdownreplicas %d", gsSet.Status.ShutdownReplicas)) + c.loggerForFleet(fleet).WithField("gameserverset", gsSet.ObjectMeta.Name).WithField("replicas", gsSetCopy.Spec.Replicas). + Info("applying rolling update to inactive gameserverset") - if _, err := c.gameServerSetGetter.GameServerSets(gsSetCopy.ObjectMeta.Namespace).Update(gsSetCopy); err != nil { - return errors.Wrapf(err, "error updating gameserverset %s", gsSetCopy.ObjectMeta.Name) - } - c.recorder.Eventf(fleet, corev1.EventTypeNormal, "ScalingGameServerSet", - "Scaling inactive GameServerSet %s from %d to %d", gsSetCopy.ObjectMeta.Name, gsSet.Spec.Replicas, gsSetCopy.Spec.Replicas) + if _, err := c.gameServerSetGetter.GameServerSets(gsSetCopy.ObjectMeta.Namespace).Update(gsSetCopy); err != nil { + return errors.Wrapf(err, "error updating gameserverset %s", gsSetCopy.ObjectMeta.Name) + } + c.recorder.Eventf(fleet, corev1.EventTypeNormal, "ScalingGameServerSet", + "Scaling inactive GameServerSet %s from %d to %d", gsSetCopy.ObjectMeta.Name, gsSet.Spec.Replicas, gsSetCopy.Spec.Replicas) - // let's update just one at a time, slightly slower, but a simpler solution that doesn't require us - // to make sure we don't overshoot the amount that is being shutdown at any given point and time - break + // let's update just one at a time, slightly slower, but a simpler solution that doesn't require us + // to make sure we don't overshoot the amount that is being shutdown at any given point and time + break + } } return nil } diff --git a/pkg/gameserversets/controller.go b/pkg/gameserversets/controller.go index e1a14700d3..787119678e 100644 --- a/pkg/gameserversets/controller.go +++ b/pkg/gameserversets/controller.go @@ -593,6 +593,7 @@ func computeStatus(list []*v1alpha1.GameServer) v1alpha1.GameServerSetStatus { for _, gs := range list { if gs.IsBeingDeleted() { // don't count GS that are being deleted + status.ShutdownReplicas++ continue } diff --git a/site/content/en/docs/Reference/agones_crd_api_reference.html b/site/content/en/docs/Reference/agones_crd_api_reference.html index 579ddaa6c7..f463e27f77 100644 --- a/site/content/en/docs/Reference/agones_crd_api_reference.html +++ b/site/content/en/docs/Reference/agones_crd_api_reference.html @@ -2232,7 +2232,7 @@

WebhookPolicy -{{% feature publishVersion="0.10.0" %}} +{{% feature expiryVersion="0.11.0" %}}

Packages: