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 Sep 16, 2020
1 parent f950643 commit cf3af87
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
}

// 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 @@ -1193,7 +1193,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 cf3af87

Please sign in to comment.