-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fingerprint | ||
|
||
import ( | ||
"log" | ||
|
||
client "github.com/hashicorp/nomad/client/config" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
||
// NomadFingerprint is used to fingerprint the Nomad version | ||
type NomadFingerprint struct { | ||
StaticFingerprinter | ||
logger *log.Logger | ||
} | ||
|
||
// NewNomadFingerprint is used to create a Nomad fingerprint | ||
func NewNomadFingerprint(logger *log.Logger) Fingerprint { | ||
f := &NomadFingerprint{logger: logger} | ||
return f | ||
} | ||
|
||
func (f *NomadFingerprint) Fingerprint(config *client.Config, node *structs.Node) (bool, error) { | ||
node.Attributes["nomad.version"] = config.Version | ||
node.Attributes["nomad.revision"] = config.Revision | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fingerprint | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/client/config" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
||
func TestNomadFingerprint(t *testing.T) { | ||
f := NewNomadFingerprint(testLogger()) | ||
node := &structs.Node{ | ||
Attributes: make(map[string]string), | ||
} | ||
v := "foo" | ||
r := "123" | ||
c := &config.Config{ | ||
Version: v, | ||
Revision: r, | ||
} | ||
ok, err := f.Fingerprint(c, node) | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
if !ok { | ||
t.Fatalf("should apply") | ||
} | ||
if node.Attributes["nomad.version"] != v { | ||
t.Fatalf("incorrect version") | ||
} | ||
if node.Attributes["nomad.revision"] != r { | ||
t.Fatalf("incorrect revision") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters