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

[api] Add NetworkStatus to allocation response #17280

Merged
merged 2 commits into from
Jul 4, 2023
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
3 changes: 3 additions & 0 deletions .changelog/17280.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api: add missing field NetworkStatus for Allocation
```
10 changes: 10 additions & 0 deletions api/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ type Allocation struct {
PreviousAllocation string
NextAllocation string
RescheduleTracker *RescheduleTracker
NetworkStatus *AllocNetworkStatus
PreemptedAllocations []string
PreemptedByAllocation string
CreateIndex uint64
Expand Down Expand Up @@ -400,6 +401,15 @@ type AllocDeploymentStatus struct {
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 {
Tasks map[string]*AllocatedTaskResources
Shared AllocatedSharedResources
Expand Down
40 changes: 40 additions & 0 deletions api/allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,46 @@ func TestAllocations_CreateIndexSort(t *testing.T) {
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) {
testutil.Parallel(t)

Expand Down
Loading