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 25, 2019
1 parent dfb2800 commit c551624
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/stable/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ package stable
const (
// GroupName is the Scheme Group Name for Agones Custom Resource Definitions
GroupName = "stable.agones.dev"
// VersionAnnotation is the key for version annotation
// associated with the CRD
VersionAnnotation = GroupName + "/sdk-version"
)
6 changes: 6 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 Down Expand Up @@ -124,6 +125,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[stable.VersionAnnotation] = pkg.Version
}

// UpperBoundReplicas returns whichever is smaller,
Expand Down
10 changes: 10 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 @@ -360,6 +361,15 @@ 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[stable.VersionAnnotation] = pkg.Version
if gs.ObjectMeta.Annotations == nil {
gs.ObjectMeta.Annotations = make(map[string]string, 1)
}
// VersionAnnotation is the annotation that stores
// the version of sdk which runs in a sidecar
gs.ObjectMeta.Annotations[stable.VersionAnnotation] = pkg.Version
}

// podScheduling applies the Fleet scheduling strategy to the passed in Pod
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"
"time"

"agones.dev/agones/pkg/apis/stable"
"agones.dev/agones/pkg/apis/stable/v1alpha1"
e2eframework "agones.dev/agones/test/e2e/framework"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -113,6 +114,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.VersionAnnotation])
}

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

0 comments on commit c551624

Please sign in to comment.