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

Reproducible Node ID #2277

Merged
merged 8 commits into from
Feb 2, 2017
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
25 changes: 18 additions & 7 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/hashicorp/nomad/nomad/structs"
vaultapi "github.com/hashicorp/vault/api"
"github.com/mitchellh/hashstructure"
"github.com/shirou/gopsutil/host"
)

const (
Expand Down Expand Up @@ -629,12 +630,23 @@ func (c *Client) getAllocRunners() map[string]*AllocRunner {
return runners
}

// nodeIDs restores the nodes persistent unique ID and SecretID or generates new
// ones
func (c *Client) nodeID() (id string, secret string, err error) {
// nodeID restores, or generates if necessary, a unique node ID and SecretID.
// The node ID is, if available, a persistent unique ID. The secret ID is a
// high-entropy random UUID.
func (c *Client) nodeID() (id, secret string, err error) {
var hostID string
hostInfo, err := host.Info()
if err == nil && hostInfo.HostID != "" {
hostID = hostInfo.HostID
} else {
// Generate a random hostID if no constant ID is available on
// this platform.
hostID = structs.GenerateUUID()
}

// Do not persist in dev mode
if c.config.DevMode {
return structs.GenerateUUID(), structs.GenerateUUID(), nil
return hostID, structs.GenerateUUID(), nil
}

// Attempt to read existing ID
Expand All @@ -655,8 +667,7 @@ func (c *Client) nodeID() (id string, secret string, err error) {
if len(idBuf) != 0 {
id = string(idBuf)
} else {
// Generate new ID
id = structs.GenerateUUID()
id = hostID

// Persist the ID
if err := ioutil.WriteFile(idPath, []byte(id), 0700); err != nil {
Expand Down Expand Up @@ -686,7 +697,7 @@ func (c *Client) setupNode() error {
node = &structs.Node{}
c.config.Node = node
}
// Generate an iD for the node
// Generate an ID and secret for the node
id, secretID, err := c.nodeID()
if err != nil {
return fmt.Errorf("node ID setup failed: %v", err)
Expand Down
59 changes: 44 additions & 15 deletions vendor/github.com/StackExchange/wmi/wmi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions vendor/github.com/go-ole/go-ole/.travis.yml

This file was deleted.

49 changes: 0 additions & 49 deletions vendor/github.com/go-ole/go-ole/ChangeLog.md

This file was deleted.

46 changes: 0 additions & 46 deletions vendor/github.com/go-ole/go-ole/README.md

This file was deleted.

63 changes: 0 additions & 63 deletions vendor/github.com/go-ole/go-ole/appveyor.yml

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/github.com/go-ole/go-ole/build/compile-go.bat

This file was deleted.

8 changes: 0 additions & 8 deletions vendor/github.com/go-ole/go-ole/build/register-assembly.bat

This file was deleted.

Binary file not shown.
31 changes: 0 additions & 31 deletions vendor/github.com/go-ole/go-ole/example/excel/excel.go

This file was deleted.

Loading