diff --git a/pkg/apis/stable/v1alpha1/fleet.go b/pkg/apis/stable/v1alpha1/fleet.go index ba3687feeb..eb21b4a42c 100644 --- a/pkg/apis/stable/v1alpha1/fleet.go +++ b/pkg/apis/stable/v1alpha1/fleet.go @@ -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" @@ -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 @@ -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, diff --git a/pkg/apis/stable/v1alpha1/gameserver.go b/pkg/apis/stable/v1alpha1/gameserver.go index 86b07719b0..e9509cc6f0 100644 --- a/pkg/apis/stable/v1alpha1/gameserver.go +++ b/pkg/apis/stable/v1alpha1/gameserver.go @@ -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" @@ -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" ) @@ -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 diff --git a/test/e2e/gameserver_test.go b/test/e2e/gameserver_test.go index 1dee9ab0e3..d1af48461d 100644 --- a/test/e2e/gameserver_test.go +++ b/test/e2e/gameserver_test.go @@ -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) {