Add 'nomad.advertise.address' to client meta via NomadFingerPrint
This change removes the addition of the advertise address to the exported task env vars and instead moves this work into the NomadFingerprint.Fingerprint which adds this value to the client attrs. This can then be used within a Nomad job like ${attr.nomad.advertise.address}.
This commit is contained in:
parent
367a8b5152
commit
b9009c419c
|
@ -59,10 +59,6 @@ const (
|
|||
// Region is the environment variable for passing the region in which the alloc is running.
|
||||
Region = "NOMAD_REGION"
|
||||
|
||||
// NomadAdvertiseAddr is the environment variable for passing the client HTTP
|
||||
// advertise address. GH-4381.
|
||||
NomadAdvertiseAddr = "NOMAD_ADVERTISE_ADDR"
|
||||
|
||||
// AddrPrefix is the prefix for passing both dynamic and static port
|
||||
// allocations to tasks.
|
||||
// E.g $NOMAD_ADDR_http=127.0.0.1:80
|
||||
|
@ -211,19 +207,18 @@ type Builder struct {
|
|||
// secretsDir from task's perspective; eg /secrets
|
||||
secretsDir string
|
||||
|
||||
cpuLimit int
|
||||
memLimit int
|
||||
taskName string
|
||||
allocIndex int
|
||||
datacenter string
|
||||
region string
|
||||
nomadAdvertiseAddr string
|
||||
allocId string
|
||||
allocName string
|
||||
groupName string
|
||||
vaultToken string
|
||||
injectVaultToken bool
|
||||
jobName string
|
||||
cpuLimit int
|
||||
memLimit int
|
||||
taskName string
|
||||
allocIndex int
|
||||
datacenter string
|
||||
region string
|
||||
allocId string
|
||||
allocName string
|
||||
groupName string
|
||||
vaultToken string
|
||||
injectVaultToken bool
|
||||
jobName string
|
||||
|
||||
// otherPorts for tasks in the same alloc
|
||||
otherPorts map[string]string
|
||||
|
@ -311,9 +306,6 @@ func (b *Builder) Build() *TaskEnv {
|
|||
// Copy region over to node attrs
|
||||
nodeAttrs[nodeRegionKey] = b.region
|
||||
}
|
||||
if b.nomadAdvertiseAddr != "" {
|
||||
envMap[NomadAdvertiseAddr] = b.nomadAdvertiseAddr
|
||||
}
|
||||
|
||||
// Build the network related env vars
|
||||
buildNetworkEnv(envMap, b.networks, b.driverNetwork)
|
||||
|
@ -453,7 +445,6 @@ func (b *Builder) setNode(n *structs.Node) *Builder {
|
|||
b.nodeAttrs[nodeClassKey] = n.NodeClass
|
||||
b.nodeAttrs[nodeDcKey] = n.Datacenter
|
||||
b.datacenter = n.Datacenter
|
||||
b.nomadAdvertiseAddr = n.HTTPAddr
|
||||
|
||||
// Set up the attributes.
|
||||
for k, v := range n.Attributes {
|
||||
|
|
|
@ -19,6 +19,7 @@ func NewNomadFingerprint(logger *log.Logger) Fingerprint {
|
|||
}
|
||||
|
||||
func (f *NomadFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cstructs.FingerprintResponse) error {
|
||||
resp.AddAttribute("nomad.advertise.address", req.Node.HTTPAddr)
|
||||
resp.AddAttribute("nomad.version", req.Config.Version.VersionNumber())
|
||||
resp.AddAttribute("nomad.revision", req.Config.Version.Revision)
|
||||
resp.Detected = true
|
||||
|
|
|
@ -11,17 +11,20 @@ import (
|
|||
|
||||
func TestNomadFingerprint(t *testing.T) {
|
||||
f := NewNomadFingerprint(testLogger())
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
v := "foo"
|
||||
r := "123"
|
||||
h := "8.8.8.8:4646"
|
||||
c := &config.Config{
|
||||
Version: &version.VersionInfo{
|
||||
Revision: r,
|
||||
Version: v,
|
||||
},
|
||||
}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
HTTPAddr: h,
|
||||
}
|
||||
|
||||
request := &cstructs.FingerprintRequest{Config: c, Node: node}
|
||||
var response cstructs.FingerprintResponse
|
||||
|
@ -45,4 +48,8 @@ func TestNomadFingerprint(t *testing.T) {
|
|||
if response.Attributes["nomad.revision"] != r {
|
||||
t.Fatalf("incorrect revision")
|
||||
}
|
||||
|
||||
if response.Attributes["nomad.advertise.address"] != h {
|
||||
t.Fatalf("incorrect advertise address")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue