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 Agones version into Gameserver Annotation #498

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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