Skip to content

Commit

Permalink
Add Agones version into Gameserver Annotation
Browse files Browse the repository at this point in the history
Add sdk-version annotation into Gameserver and Pod spec.
  • Loading branch information
aLekSer committed Jan 23, 2019
1 parent 327ece5 commit 981b348
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/apis/stable/v1alpha1/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
"agones.dev/agones/pkg"
"agones.dev/agones/pkg/apis/stable"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -25,6 +26,9 @@ const (
// FleetNameLabel is the label that the name of the Fleet
// is set to on GameServerSet and GameServer the Fleet controls
FleetNameLabel = stable.GroupName + "/fleet"
// FleetSdkVersionAnnotation is the key for version annotation
// associated with the Fleet
FleetSdkVersionAnnotation = stable.GroupName + "/sdk-version"
)

// +genclient
Expand Down Expand Up @@ -124,6 +128,11 @@ func (f *Fleet) ApplyDefaults() {
f.Spec.Strategy.RollingUpdate.MaxUnavailable = &def
}
}
// Add Agones version into Fleet Annotations
if f.ObjectMeta.Annotations == nil {
f.ObjectMeta.Annotations = make(map[string]string, 1)
}
f.ObjectMeta.Annotations[FleetSdkVersionAnnotation] = pkg.Version
}

// UpperBoundReplicas returns whichever is smaller,
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/stable/v1alpha1/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/mattbaird/jsonpatch"

"agones.dev/agones/pkg"
"agones.dev/agones/pkg/apis/stable"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -73,6 +74,9 @@ const (
// GameServerContainerAnnotation is the annotation that stores
// which container is the container that runs the dedicated game server
GameServerContainerAnnotation = stable.GroupName + "/container"
// GameServerSdkVersionAnnotation is the annotation that stores
// the version of sdk which runs in a sidecar
GameServerSdkVersionAnnotation = stable.GroupName + "/sdk-version"
// SidecarServiceAccountName is the default service account for managing access to get/update GameServers
SidecarServiceAccountName = "agones-sdk"
)
Expand Down Expand Up @@ -360,6 +364,14 @@ func (gs *GameServer) podObjectMeta(pod *corev1.Pod) {
// (and evict the Pod in the process)
pod.ObjectMeta.Annotations["cluster-autoscaler.kubernetes.io/safe-to-evict"] = "false"
}

// Add Agones version into Pod Annotations
pod.ObjectMeta.Annotations[GameServerSdkVersionAnnotation] = pkg.Version
// Add Agones version into Gameserver Annotations
if gs.ObjectMeta.Annotations == nil {
gs.ObjectMeta.Annotations = make(map[string]string, 1)
}
gs.ObjectMeta.Annotations[GameServerSdkVersionAnnotation] = pkg.Version
}

// podScheduling applies the Fleet scheduling strategy to the passed in Pod
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func TestSDKSetAnnotation(t *testing.T) {

assert.Nil(t, err)
assert.NotEmpty(t, gs.ObjectMeta.Annotations["stable.agones.dev/sdk-timestamp"])

assert.NotEmpty(t, gs.ObjectMeta.Annotations["stable.agones.dev/sdk-version"])
}

func TestUnhealthyGameServersWithoutFreePorts(t *testing.T) {
Expand Down

0 comments on commit 981b348

Please sign in to comment.