From d5a422e3209b98b376cfca010736988e0c9b99eb Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 16 Sep 2020 12:35:51 -0500 Subject: [PATCH] api: safely access legacy MBits field --- api/resources.go | 11 +++++++++++ command/agent/job_endpoint.go | 2 +- vendor/github.com/hashicorp/nomad/api/resources.go | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api/resources.go b/api/resources.go index dab134cf9..5b5501a5c 100644 --- a/api/resources.go +++ b/api/resources.go @@ -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 diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 75cff06b6..3d956ca09 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -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 { diff --git a/vendor/github.com/hashicorp/nomad/api/resources.go b/vendor/github.com/hashicorp/nomad/api/resources.go index dab134cf9..5b5501a5c 100644 --- a/vendor/github.com/hashicorp/nomad/api/resources.go +++ b/vendor/github.com/hashicorp/nomad/api/resources.go @@ -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