Add version package

This PR adds a version package and consolidates version strings into a
Version struct.
This commit is contained in:
Alex Dadgar
2017-08-16 15:42:15 -07:00
parent b90980bd7d
commit c26ecb7092
18 changed files with 120 additions and 101 deletions

View File

@@ -25,6 +25,7 @@ import (
"github.com/hashicorp/nomad/helper/flag-helpers"
"github.com/hashicorp/nomad/helper/gated-writer"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/version"
"github.com/hashicorp/scada-client/scada"
"github.com/mitchellh/cli"
"github.com/posener/complete"
@@ -38,11 +39,9 @@ const gracefulTimeout = 5 * time.Second
// ShutdownCh. If two messages are sent on the ShutdownCh it will forcibly
// exit.
type Command struct {
Revision string
Version string
VersionPrerelease string
Ui cli.Ui
ShutdownCh <-chan struct{}
Version *version.VersionInfo
Ui cli.Ui
ShutdownCh <-chan struct{}
args []string
agent *Agent
@@ -199,9 +198,7 @@ func (c *Command) readConfig() *Config {
config = config.Merge(cmdConfig)
// Set the version info
config.Revision = c.Revision
config.Version = c.Version
config.VersionPrerelease = c.VersionPrerelease
// Normalize binds, ports, addresses, and advertise
if err := config.normalizeAddrs(); err != nil {
@@ -361,9 +358,9 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer) error {
// Setup update checking
if !config.DisableUpdateCheck {
version := config.Version
if config.VersionPrerelease != "" {
version += fmt.Sprintf("-%s", config.VersionPrerelease)
version := config.Version.Version
if config.Version.VersionPrerelease != "" {
version += fmt.Sprintf("-%s", config.Version.VersionPrerelease)
}
updateParams := &checkpoint.CheckParams{
Product: "nomad",
@@ -392,12 +389,7 @@ func (c *Command) checkpointResults(results *checkpoint.CheckResponse, err error
return
}
if results.Outdated {
versionStr := c.Version
if c.VersionPrerelease != "" {
versionStr += fmt.Sprintf("-%s", c.VersionPrerelease)
}
c.Ui.Error(fmt.Sprintf("Newer Nomad version available: %s (currently running: %s)", results.CurrentVersion, versionStr))
c.Ui.Error(fmt.Sprintf("Newer Nomad version available: %s (currently running: %s)", results.CurrentVersion, c.Version.VersionNumber()))
}
for _, alert := range results.Alerts {
switch alert.Level {
@@ -485,7 +477,7 @@ func (c *Command) Run(args []string) int {
// Compile agent information for output later
info := make(map[string]string)
info["version"] = fmt.Sprintf("%s%s", config.Version, config.VersionPrerelease)
info["version"] = config.Version.VersionNumber()
info["client"] = strconv.FormatBool(config.Client.Enabled)
info["log level"] = config.LogLevel
info["server"] = strconv.FormatBool(config.Server.Enabled)
@@ -746,7 +738,7 @@ func (c *Command) setupSCADA(config *Config) error {
scadaConfig := &scada.Config{
Service: "nomad",
Version: fmt.Sprintf("%s%s", config.Version, config.VersionPrerelease),
Version: config.Version.VersionNumber(),
ResourceType: "nomad-cluster",
Meta: map[string]string{
"auto-join": strconv.FormatBool(config.Atlas.Join),