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 to fleet and Gameserverset #575

Merged
merged 2 commits into from
Feb 23, 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
2 changes: 2 additions & 0 deletions install/helm/agones/templates/crds/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ spec:
template:
{{- include "gameserver.validation" . | indent 14 }}
subresources:
# status enables the status subresource.
status: {}
# scale enables the scale subresource.
scale:
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
Expand Down
2 changes: 2 additions & 0 deletions install/helm/agones/templates/crds/gameserverset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ spec:
template:
{{- include "gameserver.validation" . | indent 14 }}
subresources:
# status enables the status subresource.
status: {}
# scale enables the scale subresource.
scale:
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
Expand Down
6 changes: 6 additions & 0 deletions install/helm/agones/templates/serviceaccounts/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ 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"]
verbs: ["update"]
- apiGroups: ["stable.agones.dev"]
resources: ["gameserverallocations"]
verbs: ["list", "watch", "delete"]
Expand Down
10 changes: 10 additions & 0 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ 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"]
verbs: ["update"]
- apiGroups: ["stable.agones.dev"]
resources: ["gameserverallocations"]
verbs: ["list", "watch", "delete"]
Expand Down Expand Up @@ -328,6 +334,8 @@ spec:
minimum: 1
maximum: 2147483648
subresources:
# status enables the status subresource.
status: {}
# scale enables the scale subresource.
scale:
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
Expand Down Expand Up @@ -936,6 +944,8 @@ spec:
minimum: 1
maximum: 2147483648
subresources:
# status enables the status subresource.
status: {}
# scale enables the scale subresource.
scale:
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
Expand Down
17 changes: 15 additions & 2 deletions pkg/fleets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,24 @@ func (c *Controller) syncFleet(key string) error {
func (c *Controller) upsertGameServerSet(fleet *stablev1alpha1.Fleet, active *stablev1alpha1.GameServerSet, replicas int32) error {
if active.ObjectMeta.UID == "" {
active.Spec.Replicas = replicas
gsSet, err := c.gameServerSetGetter.GameServerSets(active.ObjectMeta.Namespace).Create(active)
gsSets := c.gameServerSetGetter.GameServerSets(active.ObjectMeta.Namespace)
gsSet, err := gsSets.Create(active)
if err != nil {
return errors.Wrapf(err, "error creating gameserverset for fleet %s", fleet.ObjectMeta.Name)
}

// extra step which is needed to set
// default values for GameServerSet Status Subresource
gsSetCopy := gsSet.DeepCopy()
gsSetCopy.Status.ReadyReplicas = 0
gsSetCopy.Status.Replicas = 0
gsSetCopy.Status.AllocatedReplicas = 0
_, err = gsSets.UpdateStatus(gsSetCopy)
Copy link
Collaborator Author

@aLekSer aLekSer Feb 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an extra step which set default values.

if err != nil {
return errors.Wrapf(err, "error updating status of gameserverset for fleet %s",
fleet.ObjectMeta.Name)
}

c.recorder.Eventf(fleet, corev1.EventTypeNormal, "CreatingGameServerSet",
"Created GameServerSet %s", gsSet.ObjectMeta.Name)
return nil
Expand Down Expand Up @@ -492,7 +505,7 @@ func (c *Controller) updateFleetStatus(fleet *stablev1alpha1.Fleet) error {
fCopy.Status.AllocatedReplicas += gsSet.Status.AllocatedReplicas
}

_, err = c.fleetGetter.Fleets(fCopy.Namespace).Update(fCopy)
_, err = c.fleetGetter.Fleets(fCopy.Namespace).UpdateStatus(fCopy)
return errors.Wrapf(err, "error updating status of fleet %s", fCopy.ObjectMeta.Name)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/fleets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func TestControllerSyncFleet(t *testing.T) {
m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) {
updated = true
ua := action.(k8stesting.UpdateAction)
// separate update of status subresource
if ua.GetSubresource() != "" {
assert.Equal(t, ua.GetSubresource(), "status")
return true, nil, nil
}
// update main resource
gsSet := ua.GetObject().(*v1alpha1.GameServerSet)
assert.Equal(t, int32(3), gsSet.Spec.Replicas)
assert.Equal(t, "gsSet1", gsSet.ObjectMeta.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/gameserversets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func (c *Controller) updateStatusIfChanged(gsSet *v1alpha1.GameServerSet, status
if gsSet.Status != status {
gsSetCopy := gsSet.DeepCopy()
gsSetCopy.Status = status
_, err := c.gameServerSetGetter.GameServerSets(gsSet.ObjectMeta.Namespace).Update(gsSetCopy)
_, err := c.gameServerSetGetter.GameServerSets(gsSet.ObjectMeta.Namespace).UpdateStatus(gsSetCopy)
if err != nil {
return errors.Wrapf(err, "error updating status on GameServerSet %s", gsSet.ObjectMeta.Name)
}
Expand Down