From b4d29c3c7709cd97fc9026fbc42bdcd6736a39b5 Mon Sep 17 00:00:00 2001 From: Mark Mandel Date: Wed, 13 Dec 2017 15:14:13 -0500 Subject: [PATCH] Consolidate the Version constant This puts the Version in a single place, which is a setup for #21, and means there will always be constant version information across all the moving pieces. Closes #2 --- gameservers/controller/main.go | 7 +++---- gameservers/sidecar/main.go | 5 ++--- pkg/version.go | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 pkg/version.go diff --git a/gameservers/controller/main.go b/gameservers/controller/main.go index c713159123..0f001e1edf 100644 --- a/gameservers/controller/main.go +++ b/gameservers/controller/main.go @@ -30,11 +30,10 @@ import ( "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" + "github.com/agonio/agon/pkg" ) -// Version the release version of the gameserver controller const ( - Version = "0.1" sidecarFlag = "sidecar" pullSidecarFlag = "always-pull-sidecar" ) @@ -45,7 +44,7 @@ func init() { // main starts the operator for the gameserver CRD func main() { - viper.SetDefault(sidecarFlag, "gcr.io/agon-images/gameservers-sidecar:"+Version) + viper.SetDefault(sidecarFlag, "gcr.io/agon-images/gameservers-sidecar:"+pkg.Version) viper.SetDefault(pullSidecarFlag, false) pflag.String(sidecarFlag, viper.GetString(sidecarFlag), "Flag to overwrite the GameServer sidecar image that is used. Can also use SIDECAR env variable") @@ -62,7 +61,7 @@ func main() { logrus.WithField(sidecarFlag, sidecarImage). WithField("alwaysPullSidecarImage", alwaysPullSidecar). - WithField("Version", Version).Info("starting gameServer operator...") + WithField("Version", pkg.Version).Info("starting gameServer operator...") config, err := rest.InClusterConfig() if err != nil { diff --git a/gameservers/sidecar/main.go b/gameservers/sidecar/main.go index 1383f411ab..6a4c0d1c77 100644 --- a/gameservers/sidecar/main.go +++ b/gameservers/sidecar/main.go @@ -26,11 +26,10 @@ import ( "github.com/spf13/viper" "golang.org/x/net/context" "google.golang.org/grpc" + "github.com/agonio/agon/pkg" ) const ( - // Version the release version of the sidecar - Version = "0.1" port = 59357 // gameServerNameEnv is the environment variable for the Game Server name @@ -58,7 +57,7 @@ func main() { isLocal := viper.GetBool(localFlag) - logrus.WithField(localFlag, isLocal).WithField("version", Version).WithField("port", port).Info("Starting sdk sidecar") + logrus.WithField(localFlag, isLocal).WithField("version", pkg.Version).WithField("port", port).Info("Starting sdk sidecar") lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port)) if err != nil { diff --git a/pkg/version.go b/pkg/version.go new file mode 100644 index 0000000000..734135fe26 --- /dev/null +++ b/pkg/version.go @@ -0,0 +1,20 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pkg + +const ( + // Version is the global version for all binaries + Version = "0.1" +)