[api] Add NetworkStatus to allocation response (#17280)
Service discovery or mesh network systems consuming the Nomad event stream or API need to know the CNI assigned IP for the allocation. This data is returned by the underlying Nomad API but isn't mapped in the response struct.
This commit is contained in:
parent
4289de5986
commit
f44793d377
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
api: add missing field NetworkStatus for Allocation
|
||||||
|
```
|
|
@ -271,6 +271,7 @@ type Allocation struct {
|
||||||
PreviousAllocation string
|
PreviousAllocation string
|
||||||
NextAllocation string
|
NextAllocation string
|
||||||
RescheduleTracker *RescheduleTracker
|
RescheduleTracker *RescheduleTracker
|
||||||
|
NetworkStatus *AllocNetworkStatus
|
||||||
PreemptedAllocations []string
|
PreemptedAllocations []string
|
||||||
PreemptedByAllocation string
|
PreemptedByAllocation string
|
||||||
CreateIndex uint64
|
CreateIndex uint64
|
||||||
|
@ -402,6 +403,15 @@ type AllocDeploymentStatus struct {
|
||||||
ModifyIndex uint64
|
ModifyIndex uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllocNetworkStatus captures the status of an allocation's network during runtime.
|
||||||
|
// Depending on the network mode, an allocation's address may need to be known to other
|
||||||
|
// systems in Nomad such as service registration.
|
||||||
|
type AllocNetworkStatus struct {
|
||||||
|
InterfaceName string
|
||||||
|
Address string
|
||||||
|
DNS *DNSConfig
|
||||||
|
}
|
||||||
|
|
||||||
type AllocatedResources struct {
|
type AllocatedResources struct {
|
||||||
Tasks map[string]*AllocatedTaskResources
|
Tasks map[string]*AllocatedTaskResources
|
||||||
Shared AllocatedSharedResources
|
Shared AllocatedSharedResources
|
||||||
|
|
|
@ -161,6 +161,46 @@ func TestAllocations_CreateIndexSort(t *testing.T) {
|
||||||
must.Eq(t, allocs, expect)
|
must.Eq(t, allocs, expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAllocations_Info(t *testing.T) {
|
||||||
|
testutil.RequireRoot(t)
|
||||||
|
testutil.Parallel(t)
|
||||||
|
|
||||||
|
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) {
|
||||||
|
c.DevMode = true
|
||||||
|
})
|
||||||
|
defer s.Stop()
|
||||||
|
a := c.Allocations()
|
||||||
|
|
||||||
|
// wait for node
|
||||||
|
_ = oneNodeFromNodeList(t, c.Nodes())
|
||||||
|
|
||||||
|
// Create a job and attempt to register it
|
||||||
|
job := testJob()
|
||||||
|
resp, wm, err := c.Jobs().Register(job, nil)
|
||||||
|
must.NoError(t, err)
|
||||||
|
must.NotNil(t, resp)
|
||||||
|
must.UUIDv4(t, resp.EvalID)
|
||||||
|
assertWriteMeta(t, wm)
|
||||||
|
|
||||||
|
// List allocations.
|
||||||
|
qo := &QueryOptions{
|
||||||
|
WaitIndex: wm.LastIndex,
|
||||||
|
}
|
||||||
|
allocs, qm, err := a.List(qo)
|
||||||
|
must.NoError(t, err)
|
||||||
|
must.NonZero(t, qm.LastIndex)
|
||||||
|
|
||||||
|
// Check that we got one allocation.
|
||||||
|
must.Len(t, 1, allocs)
|
||||||
|
must.Eq(t, resp.EvalID, allocs[0].EvalID)
|
||||||
|
|
||||||
|
// Fetch alloc info.
|
||||||
|
qo.WaitIndex = qm.LastIndex
|
||||||
|
alloc, _, err := a.Info(allocs[0].ID, qo)
|
||||||
|
|
||||||
|
must.NotNil(t, alloc.NetworkStatus)
|
||||||
|
}
|
||||||
|
|
||||||
func TestAllocations_RescheduleInfo(t *testing.T) {
|
func TestAllocations_RescheduleInfo(t *testing.T) {
|
||||||
testutil.Parallel(t)
|
testutil.Parallel(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue