Skip to content

Commit

Permalink
api: safely access legacy MBits field
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Nov 23, 2020
1 parent 7d1f294 commit d5a422e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions api/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ type NetworkResource struct {
MBits *int `hcl:"mbits,optional"`
}

// COMPAT(0.13)
// XXX Deprecated. Please do not use. The method will be removed in Nomad
// 0.13 and is only being kept to allow any references to be removed before
// then.
func (n *NetworkResource) Megabits() int {
if n == nil || n.MBits == nil {
return 0
}
return *n.MBits
}

func (n *NetworkResource) Canonicalize() {
// COMPAT(0.13)
// Noop to maintain backwards compatibility
Expand Down
2 changes: 1 addition & 1 deletion command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ func ApiNetworkResourceToStructs(in []*api.NetworkResource) []*structs.NetworkRe
Mode: nw.Mode,
CIDR: nw.CIDR,
IP: nw.IP,
MBits: *nw.MBits,
MBits: nw.Megabits(),
}

if nw.DNS != nil {
Expand Down
11 changes: 11 additions & 0 deletions vendor/github.com/hashicorp/nomad/api/resources.go

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

0 comments on commit d5a422e

Please sign in to comment.