mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Add version package
This PR adds a version package and consolidates version strings into a Version struct.
This commit is contained in:
@@ -102,7 +102,7 @@ func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Confi
|
||||
}
|
||||
conf.LogOutput = logOutput
|
||||
conf.DevMode = agentConfig.DevMode
|
||||
conf.Build = fmt.Sprintf("%s%s", agentConfig.Version, agentConfig.VersionPrerelease)
|
||||
conf.Build = agentConfig.Version.VersionNumber()
|
||||
if agentConfig.Region != "" {
|
||||
conf.Region = agentConfig.Region
|
||||
}
|
||||
@@ -308,8 +308,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) {
|
||||
r.IOPS = a.config.Client.Reserved.IOPS
|
||||
conf.GloballyReservedPorts = a.config.Client.Reserved.ParsedReservedPorts
|
||||
|
||||
conf.Version = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease)
|
||||
conf.Revision = a.config.Revision
|
||||
conf.Version = a.config.Version
|
||||
|
||||
if *a.config.Consul.AutoAdvertise && a.config.Consul.ClientServiceName == "" {
|
||||
return nil, fmt.Errorf("client_service_name must be set when auto_advertise is enabled")
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/hashicorp/nomad/helper"
|
||||
"github.com/hashicorp/nomad/nomad"
|
||||
"github.com/hashicorp/nomad/nomad/structs/config"
|
||||
"github.com/hashicorp/nomad/version"
|
||||
)
|
||||
|
||||
// Config is the configuration for the Nomad agent.
|
||||
@@ -114,9 +115,7 @@ type Config struct {
|
||||
DevMode bool `mapstructure:"-"`
|
||||
|
||||
// Version information is set at compilation time
|
||||
Revision string
|
||||
Version string
|
||||
VersionPrerelease string
|
||||
Version *version.VersionInfo
|
||||
|
||||
// List of config files that have been loaded (in order)
|
||||
Files []string `mapstructure:"-"`
|
||||
|
||||
Reference in New Issue
Block a user